I've trimmed down the CAA Serial Codesys example to only listen on one port but, when stepping through the Case structure in debug mode, it jumps out of the structure during a specific point in every scan (I'll point it out below after describing the setup and listing the code).
I'm using a Pi 4 Model B, and I have an Arduino Nano Every plugged in via USB which is streaming the following serial message at 1 Hz:
Time since opening connection: 1 s
Time since opening connection: 2 s
...and so on.
The Pi shows the Nano at /dev/ttyACM0 so I edited CODESYSControl_User.cfg to read: Linux.Devicefile=/dev/ttyACM
The code in my PLC_PRG is (ignore some of the comments, I hadn't deleted them out from the original example):
I realize as I write this that the .udiPort should be 0 and not 1, but that shouldn't be causing the issue I'm seeing.
I'm forcing xStartTest:=TRUE every scan so that I can step into each line and observe what's happening. What I see is that the port parameters are set and the port is opened with no errors, but the code jumps out of the case structure to the last line every time it reaches (and I step into) the iState:=15 line (at the end of the iState:=0 block). So every scan cycle it goes through the block for iState=0 and jumps out at the same spot.
I'm a little new to PLC programming so I may be misunderstanding the flow, but shouldn't this case structure keep moving down in the same scan? If it only handles one case per scan, why doesn't the value of iState persist?
Thanks!
Update: I restarted the Codesys control today and I was then able to see an error for como1.eError of "WRONG_PARAMETER". I tried doing some digging and another post made me think I should add another line to CODESYSControl_User.cfg, so I now have:
So now when I set .udiPort to 1, I get "NO_ERROR" but I also don't read anything from the port (i.e. szRead = 0 always). If I try setting the port to 0 (which I'm confused about, because I added a COMPORT1 line but the device shows on the Pi as ACM0), I get the "WRONG_PARAMETER" error again.
Is there an easier way to troubleshoot the Pi and view what ports the Codesys runtime is actually able to see while the Pi is running?
Last edit: paulg 2024-06-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've trimmed down the CAA Serial Codesys example to only listen on one port but, when stepping through the Case structure in debug mode, it jumps out of the structure during a specific point in every scan (I'll point it out below after describing the setup and listing the code).
I'm using a Pi 4 Model B, and I have an Arduino Nano Every plugged in via USB which is streaming the following serial message at 1 Hz:
...and so on.
The Pi shows the Nano at /dev/ttyACM0 so I edited CODESYSControl_User.cfg to read:
Linux.Devicefile=/dev/ttyACM
The code in my PLC_PRG is (ignore some of the comments, I hadn't deleted them out from the original example):
I realize as I write this that the
.udiPort
should be 0 and not 1, but that shouldn't be causing the issue I'm seeing.I'm forcing
xStartTest:=TRUE
every scan so that I can step into each line and observe what's happening. What I see is that the port parameters are set and the port is opened with no errors, but the code jumps out of the case structure to the last line every time it reaches (and I step into) theiState:=15
line (at the end of theiState:=0
block). So every scan cycle it goes through the block foriState=0
and jumps out at the same spot.I'm a little new to PLC programming so I may be misunderstanding the flow, but shouldn't this case structure keep moving down in the same scan? If it only handles one case per scan, why doesn't the value of iState persist?
Thanks!
Update: I restarted the Codesys control today and I was then able to see an error for
como1.eError
of "WRONG_PARAMETER". I tried doing some digging and another post made me think I should add another line to CODESYSControl_User.cfg, so I now have:So now when I set
.udiPort
to 1, I get "NO_ERROR" but I also don't read anything from the port (i.e. szRead = 0 always). If I try setting the port to 0 (which I'm confused about, because I added aCOMPORT1
line but the device shows on the Pi as ACM0), I get the "WRONG_PARAMETER" error again.Is there an easier way to troubleshoot the Pi and view what ports the Codesys runtime is actually able to see while the Pi is running?
Last edit: paulg 2024-06-06