I need to establish a serial communication (UART) with my own board that talks a proprietary protocol and i must configure PC side codesys application as a slave i.e. always listening for a command and send back an acknowledge message. The communication hasn't any flow control.
After readings and studying '' '' i've got stuck into the reception of unknown number of bytes from the peripheral due to the asynchronous way to transmit data with UART.
As my PRG it execute reading and writing routines at a fixed rate and i don't know how to set a callback to a byte reception interrupt (for example) or manage any kind of circular buffer (avoiding loss of data and) i'm asking to the community if someone faced the problem in the past and if there exist some example to be shared.
I'm even thinking of using python scripting but i preferred to ask you before.
I think that a solution could be found out because of Modbus RTU protocol support.
Can you help me?
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-03-24
Originally created by: ph0010421
Hello
There may be a better answer, but I execute the COM.Read FB like this:
Hello pp,
I don't believe your snippet is 100% reliable for the reason that your fb is executed at a known fixed rate and for one cycle it isn't in executing state at least. I'm could be wrong if function and fb behind COM.read continuously listen for a packet and isn't driven by argument parameter 'execute'.
In facts i would like to ask to everyone where i can find detailed documentation of 'Model behaviour library' and 'job executing library' that Com library it depends?
Thank you,
Enrico
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm interested in understanding if there exist some chance to write code for an event driven task. In this case the event would be byte received from com port.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-03-24
Originally created by: ph0010421
Hello Enrico
I'm interested to discuss things like this.
My understanding is the serial buffer is filled asynchronously, so the rate that the Read fb is executed doesn't matter.
As long as the szBuffer is larger than the maximum number of characters that can be received between executing then it's reliable.
The fb's reliability is based on an extended stress test.
The szSize is sometimes more than 1; ie multiple characters were received in 1 scan.
Best wishes
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-03-25
Originally created by: Viacheslav Mezentsev
ericci hat geschrieben:
and i don't know how to set a callback to a byte reception interrupt (for example)
It is impossible for the codesys application (IRQ handling). This is normal for microcontrollers, but not for the user application in the Codesys RTS.
Thank you for your support and i hope this will clarify the matter in the future.
I suppose your code is good enough to implement such a modbus slave protocol provided that your receiving routine is much faster than the sending one (Master side), and you accept that a slave could loss some packet (rarely).
Last assertion is due to the fact that a slave could start to read a packet when master is transmitting one and if slave receives his address and a valid modbus command into the master's packet payload only final crc it avoid a wrong command reception.
Hope to be clear.
Those examples are common problem related to an asynchronous packet exchange although tomorrow i will try your snippet in my code.
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-03-25
Originally created by: Viacheslav Mezentsev
Yes, this code must be improved by adding processing of some special cases. You are right, the function block must be executed in a sufficiently fast separate task.
You can try how it works. This code is part of the AgavaModbus library (see AgavaSDK package here - all docs in russian). See example: Примеры\AgavaModbus\ПЛК-40\ST\ModbusRTUSlave.project . You must install AgavaLibraries.3.5.10.3.package first (for Codesys >= 3.5.10.x).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all!
I need to establish a serial communication (UART) with my own board that talks a proprietary protocol and i must configure PC side codesys application as a slave i.e. always listening for a command and send back an acknowledge message. The communication hasn't any flow control.
After readings and studying '' '' i've got stuck into the reception of unknown number of bytes from the peripheral due to the asynchronous way to transmit data with UART.
As my PRG it execute reading and writing routines at a fixed rate and i don't know how to set a callback to a byte reception interrupt (for example) or manage any kind of circular buffer (avoiding loss of data and) i'm asking to the community if someone faced the problem in the past and if there exist some example to be shared.
I'm even thinking of using python scripting but i preferred to ask you before.
I think that a solution could be found out because of Modbus RTU protocol support.
Can you help me?
Regards
Originally created by: ph0010421
Hello
There may be a better answer, but I execute the COM.Read FB like this:
And concatenate the received string using ```
fbiComRead.szSize
```
I've written my own FB to build the final string (and look for a termination character) if you want it?
I've used this method with devices that send serial data (115K2) and it's reliable.
Pp
Hello pp,
I don't believe your snippet is 100% reliable for the reason that your fb is executed at a known fixed rate and for one cycle it isn't in executing state at least. I'm could be wrong if function and fb behind COM.read continuously listen for a packet and isn't driven by argument parameter 'execute'.
In facts i would like to ask to everyone where i can find detailed documentation of 'Model behaviour library' and 'job executing library' that Com library it depends?
Thank you,
Enrico
I'm interested in understanding if there exist some chance to write code for an event driven task. In this case the event would be byte received from com port.
Originally created by: ph0010421
Hello Enrico
I'm interested to discuss things like this.
My understanding is the serial buffer is filled asynchronously, so the rate that the Read fb is executed doesn't matter.
As long as the szBuffer is larger than the maximum number of characters that can be received between executing then it's reliable.
The fb's reliability is based on an extended stress test.
The szSize is sometimes more than 1; ie multiple characters were received in 1 scan.
Best wishes
Originally created by: Viacheslav Mezentsev
It is impossible for the codesys application (IRQ handling). This is normal for microcontrollers, but not for the user application in the Codesys RTS.
But I can suggest you the following algorithm.
And code example:
Hello Viacheslav,
Thank you for your support and i hope this will clarify the matter in the future.
I suppose your code is good enough to implement such a modbus slave protocol provided that your receiving routine is much faster than the sending one (Master side), and you accept that a slave could loss some packet (rarely).
Last assertion is due to the fact that a slave could start to read a packet when master is transmitting one and if slave receives his address and a valid modbus command into the master's packet payload only final crc it avoid a wrong command reception.
Hope to be clear.
Those examples are common problem related to an asynchronous packet exchange although tomorrow i will try your snippet in my code.
Regards
Originally created by: Viacheslav Mezentsev
Yes, this code must be improved by adding processing of some special cases. You are right, the function block must be executed in a sufficiently fast separate task.
You can try how it works. This code is part of the AgavaModbus library (see AgavaSDK package here - all docs in russian). See example: Примеры\AgavaModbus\ПЛК-40\ST\ModbusRTUSlave.project . You must install AgavaLibraries.3.5.10.3.package first (for Codesys >= 3.5.10.x).
Hi, Where I can download AgavaLibraries ?