This is the LCLS TwinCAT3 project lcls-twincat-general.
TODO
TODO
A PLC code toolkit for LCLS TwinCAT PLC projects
Home Page: https://pcdshub.github.io/lcls-twincat-general/
License: Other
This is the LCLS TwinCAT3 project lcls-twincat-general.
TODO
TODO
We should add a temperature offset to FB_TempSensor
. I should have done this before merging the PR. This is low priority because it's not clear if anyone is going to bother calibrating their sensors.
ERROR:pytmc.bin.pragmalint:Linter error:
POUs/Hardware/FB_ThermoCouple.TcPOU:line 17: {attribute 'pytmc' := '
pv: STC:CONN
io: input
field: ONAM Connected
field: ZNAM Disconnected
}
Looks like it's missing the final '
of {attribute ' '}
And potentially add some log messages when severity changes.
Originally posted by @klauer in #46 (comment)
Attempting to build these tags results in errors due to the issue described in pcdshub/tc-release#38
This does not stop us from saving/installing the library, nor does it cause any issues at runtime or when compiling our production beamline plc projects if we do so
We should be able to build the tagged packages for unit tests (in the works: do this in CI)
This has put a wrinkle into some CI/automatic build efforts
I'm going to resolve this for future tags by updating tc-release, but what can we consider doing here?
Some questions to answer:
If you call fbEPS.setBit()
or fbEPS.setDescription()
prior to calling fbEPS()
with some instance of DUT_EPS
, it results in a page fault. This is because setBit
and setDescription
refer to the eps
object that was passed in, and without passing one prior this is a null reference. Beckhoff sort of tries to warn us about this via a cryptic compiler warning, but this is otherwise not warned about in the documentation or in the docstrings.
We should have some combination of the following:
@NSLentz ran into this while testing out the EPS features.
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SER_RBV.NIST" to "COMERROR_INVALIDPROCESSDATASIZE" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SER_RBV.ELST" to "COMERROR_INVALIDCHANNELNUMBER" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SER_RBV.TTST" to "COMERROR_INVALIDNUMDATABITS" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SER_RBV.FTST" to "COMERROR_INVALIDNUMSTOPBITS" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SEND_RBV.NIST" to "COMERROR_INVALIDPROCESSDATASIZE" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SEND_RBV.ELST" to "COMERROR_INVALIDCHANNELNUMBER" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SEND_RBV.TTST" to "COMERROR_INVALIDNUMDATABITS" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:SEND_RBV.FTST" to "COMERROR_INVALIDNUMSTOPBITS" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:RECV_RBV.NIST" to "COMERROR_INVALIDPROCESSDATASIZE" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:RECV_RBV.ELST" to "COMERROR_INVALIDCHANNELNUMBER" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:RECV_RBV.TTST" to "COMERROR_INVALIDNUMDATABITS" Error (512,512)
ErrorCan't set "IM1L0:XTES:MFW:RAW:ERR:RECV_RBV.FTST" to "COMERROR_INVALIDNUMSTOPBITS" Error (512,512)
Brought up during the TcUnit presentation by @ghalym
What would this look like?
Once this is done, this page should be modified:
https://confluence.slac.stanford.edu/pages/viewpage.action?pageId=337066917
The current function block works, but is limited to floating point types.
Integers have the potential to work as-is with a cast from LREAL<->INT for at least a portion of all UINT32s.
There is no current way, however, to get a string value over this function block. I think it could be added to the library, but a bit of care will be required.
If the first "get IP address" check fails, logging will be disabled entirely because fbGetAdapterIP
never updates arrAdapters
again.
Fixed on plc-kfe-gatt
by manually toggling bExecute
.
The BOM is actually the byte order marker for UTF-8, and not the 3 bytes "BOM":
MSG = MSG-ANY / MSG-UTF8
MSG-ANY = *OCTET ; not starting with BOM
MSG-UTF8 = BOM UTF-8-STRING
BOM = %xEF.BB.BF
(from RFC5424 https://tools.ietf.org/html/rfc5424)
Not sure if we'll be sending UTF-8 from the PLC, more likely just ASCII...
While we can go with plaintext and worry about filtering down the line, it seems like it might be a good idea to tackle log message formatting from the start and include some structure.
Syslog itself has a few spots where we can insert information to better categorize messages, such as PID or message ID, which only need to be ASCII. Beyond that, maybe we could consider using JSON in the message with some versioned schema:
{
"schema": "plc-general-v1",
"msg": "message text",
"schema_metadata1": 123,
"schema_metadata2": 456,
...
}
Fields in logstash can contain JSON, which would be expanded either into the root event or nested somewhere.
Severity Code Description Project File Line Suppression State
Warning Implicit conversion from unsigned Type 'UINT' to signed Type 'INT' : possible change of sign [lcls general, 0.0.0 (slac)] FB_LogHandler 73
In syslog, this could fit in as either PID or message ID (either of which just need to be ASCII).
With 10 states in a big case statement, it's easy to get lost as to their meaning. I think this is a good case for making these named constants or an enum.
Alternatively, perhaps a named action saying "Go_to_X_state" or "Next_state" or something along those lines would be nice?
According to N.P. TC may allocate memory dynamically from the ADS router. We should add this block to monitor for memory leaks and to verify the overhead our IOC connections are putting on our systems.
from the WIP Jenkins CI:
2023-05-25 12:29:38 [INFO ] - Building solution...
2023-05-25 12:29:46 [ERROR] - Description: SA0027: Object name 'ST_PortAddr' already used in Library 'tc2_ethercat, 3.3.21.0 (beckhoff automation gmbh)'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Diagnostics\DUT\ST_PortAddr.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0027: Variable name 'Init' in 'AutoReset' already used for an object in Library 'tc3_eventlogger, 3.1.33.0 (beckhoff automation gmbh)'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\Tests\FB_CircuitBreaker_Test.TcPOU;FB_CircuitBreaker_Test.AutoReset
2023-05-25 12:29:46 [ERROR] - Description: SA0027: Variable name 'test' in 'FB_EtherCATDiag' already used for an object in Library 'tcunit, 1.2.1.0 (www.tcunit.org)'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Diagnostics\FB_EtherCATDiag.TcPOU
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'DisarmCountDefault'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\FB_LogHandler.TcPOU
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'ESC_MAX_PORTS'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\GVLs\Global_Variables_EtherCAT.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'fTimeStamp'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\GVLs\DefaultGlobals.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'iSLAVEADDR_ARR_SIZE'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\GVLs\Global_Variables_EtherCAT.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'I_EcatMaster1'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'LogToVisualStudio'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\FB_Listener.TcPOU;FB_Listener.LogToVisualStudio.Set
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'MAX_STATES'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\GVLs\GeneralConstants.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'nTotalEvents'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\FB_LogMessage.TcPOU
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'nTrickleThreshold'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\GVL_Logger.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'stEventInfo'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\FB_Listener.TcPOU
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'stSys'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\GVLs\DefaultGlobals.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'TCPADS_MAXUDP_BUFFSIZE'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\POUs\Logger\GVL_Logger.TcGVL
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'xAtVacuum'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'xFirstScan'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'xIOState'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'xOverrideMode'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Description: SA0033: Unused Variable 'xSwAlmRst'
2023-05-25 12:29:46 [ERROR] - ErrorLevel: vsBuildErrorLevelHigh
2023-05-25 12:29:46 [ERROR] - Filename: c:\Jenkins\workspace\lcls-twincat-general\LCLSGeneral\LCLSGeneral\Data types\Misc\ST_System.TcDUT
2023-05-25 12:29:46 [ERROR] - Build errors in project
We should be able to build the project and run the unit tests with no modifications
See https://github.com/pcdshub/lcls2-cc-lib/blob/master/lcls2-cc-lib/Library/POUs/FB_DataBuffer.TcPOU
These could be useful for fast data acquisition of twincat variables
Linking via EPICS and pytmc link
, monitor more structured things beyond just "let me link a floating point value".
Minimally, I'll need to add:
What else could be generically useful?
BPTS will need the motor record monitoring and some AreaDetector plugin PVs, but I don't expect those to be so reusable.
Note the download link:
https://github.com/pcdshub/lcls-twincat-general/releases/download/v2.6.1/L2SIVacuum-v2.6.1.library
Does this need a re-release?
The log handler should emit one message at startup to let everyone know it's online.
Currently a gate valve that is using the FB_LREALFromEPICS (on one side) to read pressure is closing every so often and we are trying to debug it. According to the archiver, the differential pressure is not ok and causes the valve to close. According to the archiver, both pressure are ok, but it could be a network issue instead. Having the logger point that out would be very helpful.
Log messages may be duplicated when using TcUnit (or otherwise?)
Currently set to @(IOC)
, which pytmc will replace with $(IOC)
when creating a database, the logger function block PV prefix needs to be decided upon and fixed.
Looks like single quotes were used in a DESC inside a single quote pragma
Checking ./LCLSGeneral/LCLSGeneral/DUTs/DUT_EPS.TcDUT
ERROR:pytmc.bin.pragmalint:Linter error: Unhandled exception: Found invalid pragma line(s):
./LCLSGeneral/LCLSGeneral/DUTs/DUT_EPS.TcDUT (TcPlcObject)
----------------------------------------------------------
- DUT_EPS: Declaration - 3 pragmas
| pv: sFlagDesc
| io: i
| field: DESC of nFlag variable, using '
--> | ' seperated list.
--> |
./LCLSGeneral/LCLSGeneral/DUTs/DUT_EPS.TcDUT:line 12: {attribute 'pytmc' := '
pv: sFlagDesc
io: i
field: DESC of nFlag variable, using ';' seperated list.
'}
ERROR:pytmc.bin.pragmalint:Unhandled exception (may be a pytmc bug)
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pytmc/bin/pragmalint.py", line 253, in lint_source
lint_pragma(pragma)
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pytmc/bin/pragmalint.py", line 131, in lint_pragma
pragmas.split_pytmc_pragma(pragma_setting)
File "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pytmc/pragmas.py", line 95, in split_pytmc_pragma
raise ValueError(f"Found invalid pragma line(s):\n{invalid_lines}")
ValueError: Found invalid pragma line(s):
| pv: sFlagDesc
| io: i
| field: DESC of nFlag variable, using '
--> | ' seperated list.
--> |
INFO:pytmc.bin.pragmalint:Total pragmas found: 3 Total linter errors: 1
Pragma lint failed. Setting error code.
See #80 (comment)
There are some files in this repo where the function block xml name tag and the filename do not match
The linked issue manually fixes the compiler link which is relevant when parsing the project on linux
There is an additional cleanup task here of making the two names actually match
It may be useful to have some PLC PVs sourced from the general library that can be used to reboot the PLC, restart TwinCAT, etc:
To reboot the whole OS: https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibutilities/html/tcplclibutilities_nt_reboot.htm
To restart just the TwinCAT process: https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibutilities/html/tcplclibutilities_tc_restart.htm
There are also blocks like https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibutilities/html/tcplclibutilities_plc_reset.htm but these should probably be called from a separate PLC instance if they are to be useful... since once you reset the PLC it can't start itself again, since it isn't running any code.
I started investigating this for some ads-ioc debugging over here: https://github.com/ZLLentz/lcls-twincat-motion/blob/d7353562c81fb4f06a7b252a95992099d83a38b8/lcls-twincat-motion/Example/POUs/Main.TcPOU#L37
In lcls-plc-rixs-optics, @ZLLentz found that UDP packets were not always sent in a single cycle. (ref pcdshub/lcls-plc-rixs-optics#75) It can reportedly be around 15 cycles.
I incorrectly had assumed this would be the case as well for logging via JSON-formatted UDP packets to logstash.
We should consider looking back into this - especially if we notice missing log messages following successful ones.
While attempting to use these function blocks for an experiment setup in RIX I found that these function blocks don't appear to work properly for negative values. I had to make some quick hacks (as these needed to be functional in ~30 minutes at the time), resulting in pcdshub/lcls-plc-crixs-motion#7. For example, the analog output terminal I was using needed to operate from -10 to 10 Volts. The analog output conversion does the following:
fScale := (EXPT(2, iTermBits) - 1) / (fTermMax - fTermMin);
iRaw := LREAL_TO_INT((fReal - fTermMin) * fScale);
However, if fReal is negative, and fTermMin is negative (as it would be for a bipolar output card) then a requested value of e.g. -9.0 V would result in:
(-9.0V - (-10 V)) * (2^16 - 1) / (10 V - (-10 V)) = 3277 (a 1 V positive output)
For the analog input, setting the iTermBits to 16, fTermMax to 10 and fTermMin to -10, an input value of e.g. -30000 ADC, or about -9V, would result in the following:
fReal = (-30000) / [(2^16 - 1)/(10 V - (-10 V))] + (-10 V) = -19.1 V
Any others?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.