alolkema

TCP/IP messaging

3 posts in this topic

Hello, i am new here,  and i tried finding this topic, but without success (maybe my impatience…).

I am writing a PLC (CJ2M) with a CJ1W-EIP21 Ethernet module, to have a 2-way explicit message communication with a server on a customer's network.
Done it before, but now i have ran into the problem that i need to split the "chained" messages;

So, i can receive a message, and as long as it contains only 1 message, all goes well. But sometimes, due to the machine's process, i get 2 or 3 messages in 1 string:

1 message:      <STX>ID|002|1|1|DescriptionText|<ETX>
3 messages:   <STX>ID|002|1|1|DescriptionText|<ETX><STX>HBT<ETX><STX>FX|003|1|44|ShutDownMotor4<ETX>
I also need to control any messages i need to send, to wait for the receiving actions.
 

I already started writing, but debugging it takes a long time.

Anyone has a -off-the-shelf- solution for this?

Thanks in advance,
Arnold

Share this post


Link to post
Share on other sites

For receiving the most simple solution is to stick to a fixed message length. You can see how many bytes are in the receive buffer. E.g. when your message length is 50 and the number of bytes received is 100, just treat it as 2 separate messages. So take all data from the receive buffer and split it into the number af messages calculated.

For sending the easiest would be just using 2 ports. One for receiving and one for sending. If you can only use one port: also here stick to a fixed message length. Put all messages in a buffer. If the port is ready for sending, send the first message in the buffer.

Share this post


Link to post
Share on other sites

Thank you, ahbest. I have used the STX and ETX as marker, to determine if there are more than 1 messages in the receive buffer. When i find the 1st message, i cut it from the string, and do another pass for the next, and repeat it until all messages are dealt with.
During this procedure, i set a Wait bit to hold any messages for sending.

I have tested this routine extensively, and it works very good.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now