Giter Club home page Giter Club logo

lcls-twincat-general's Introduction

lcls-twincat-general

This is the LCLS TwinCAT3 project lcls-twincat-general.

Documentation

Purpose

TODO

Usage

TODO

lcls-twincat-general's People

Contributors

ghalym avatar jozamudi avatar klauer avatar n-wbrown avatar nrwslac avatar robertoroos avatar sagatowski avatar slacawallace avatar zllentz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lcls-twincat-general's Issues

CI linter error, invalid pragma

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.

Temperature Offset

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.

Fix FB_AnalogOutput and FB_AnalogInput for negative numbers

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

All tags of lcls-twincat-general do not build in TwinCAT as-is for unit testing

Current Behavior

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

Expected Behavior

We should be able to build the tagged packages for unit tests (in the works: do this in CI)

Context / environment

This has put a wrinkle into some CI/automatic build efforts

Steps to Reproduce (for bugs)

  1. check out a tag
  2. build

Suggested Solution

I'm going to resolve this for future tags by updating tc-release, but what can we consider doing here?

Some questions to answer:

  • Is it worth modifying old tags, or should I let these exist as-is and use a different library to test the automatic library build tools? Perhaps modifying old tags is a step too far.
  • Do the static analysis checks help here? I think they probably do, for what it's worth.

Fields with invalid pragmas

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)

Logger: consider buffering UDP packet sending

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.

Filename inconsistencies

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

Log message format

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.

PLC Restart and Related Utils

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

Add function blocks for monitoring structured EPICS things

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:

  • motor record (readback value, motion status, homing status and other MSTA things)

What else could be generically useful?

  • TwinCAT motor information (while extremely - and perhaps bizarrely - indirect, it could be useful in some situations)

BPTS will need the motor record monitoring and some AreaDetector plugin PVs, but I don't expect those to be so reusable.

Add Enum for EcatDiag state machine

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?

Originally posted by @klauer in #35

Page Fault with Improper Use of FB_EPS

Current Behavior

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.

Expected Behavior

We should have some combination of the following:

  • Errors instead of page faults
  • A warning in the docstrings
  • A warning in the documentation

Context / environment

@NSLentz ran into this while testing out the EPS features.

FB_ThermoCouple pragma typo

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 ' '}

Add ADS Router Info

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.

Get Router Info

Fix logger prefix

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.

Adding Logger to FB_LREALFromEPICS

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.

Work through the static analysis errors that prevent running the test suite

Current Behavior

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

Expected Behavior

We should be able to build the project and run the unit tests with no modifications

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.