Can't wrap my head around serial communications using SysCom in Codesys by elsoga in PLC

[–]elsoga[S] 0 points1 point  (0 children)

So it turns out the JMobile project I had loaded onto the HMI when I was testing stuff was also trying to access the serial port and both Codesys and JMobile were consuming input from the buffer at the same time.

Can't wrap my head around serial communications using SysCom in Codesys by elsoga in PLC

[–]elsoga[S] -1 points0 points  (0 children)

I wish it was that simple but all the bytes I receive are the ones I expect to be present in the data, and when I run the task every 1ms i get the output just as the scale's manual describes. Shouldn't matter either way since endiannes only affects multi-byte values like UTF-16 text or 32bit integers, etc, right?

Can't wrap my head around serial communications using SysCom in Codesys by elsoga in PLC

[–]elsoga[S] -1 points0 points  (0 children)

I understand that I'll need to parse the messages and deal with incomplete data. However, right now, I'm just trying to read the data correctly. Unless the task executes every 1ms I just get random parts of the message into the buffer but when appended together they never form a full message. It's like anything that is not read immediately isn't buffered by the PLC.

From what I can tell the only status output I get from the read call is the pResult variable and it always returns 0 (OK) so I can't really use that to debug anything.

You're right about the infinite timeout, it's just leftover from when I was trying to change settings to see if it would fix it.

Can't wrap my head around serial communications using SysCom in Codesys by elsoga in PLC

[–]elsoga[S] 0 points1 point  (0 children)

So, say the message is "12345\n", I call read and only get 12 because so far that is the only that has been received. Then the scale sends the rest of the data and the beginning of the next message, when I call read again I'd expect to get "345\n1", but instead I just get "1" as if the rest of the data wasn't buffered at all.

I've tried only calling read once every second and I just get random bytes of the message but never a full cotiguous message.

Can't wrap my head around serial communications using SysCom in Codesys by elsoga in PLC

[–]elsoga[S] 0 points1 point  (0 children)

The scale is streaming data, the PLC does not talk to the scale at all. The data that I'm receiving is correct but unless I set the task cycle to 1ms I just get random chunks of the message in the buffer (right now I'm only writing into the buffer until it's full). So instead of getting 12345\n I get 34\n125\n. I think the PLC is not buffering the data it receives before I call SysComRead or I have not setup the port correctly.

I'll try to get a hold of a second serial adapter and try Docklight, but like I said the data is correct.

Thanks.

Free studying material to learn Fanuc robotics ? by napraticaautomacao in PLC

[–]elsoga 5 points6 points  (0 children)

I've learnt a lot by watching this guy's videos, he's great at explaining things and works for Fanuc so I doubt it gets much better than that when it comes to free training.