Darryl

As I showed in the previous post, you build your own protocol. If you are doing ASCII commands, then you need a sync character to know the start of packet.

Code:
STX DST SRC CMD DATA.......DATA CS ETX
This can be the format for a typical packet. STX (02H) is the start character you seek to know there is a command / response packet. DST is the slave id which you want to talk to. SRC is the id of the master and can be omitted if there is a single master as in the case of a PC based logger. CMD tells the slave which function is being invoked and DATA passes parameters to the function if they are needed. Finally CS is a checksum to verify that the data packet has arrived without corruption. CS could be as simple as a LRC longitudinal redundancy check or as severe as a CRC16 cyclic redundancy check.

ETX (03H) generally is not needed but can be used to frame the command / response packet.

The slave responds with a message within the alloted time window (fixed by your program). If not, the master times out and understands that the slave is disconnected or not working. I have built many systems using this type of
protocol and it works really well.

You could look at the MODBUS specification if you want to learn more. MODBUS however offers an ASCII mode and a binary RTU mode. PLCs generally use the RTU mode to garner speed. In ASCII mode, you have to send every byte converted to 2 bytes of ASCII. So, a character like 02H will be sent as 30H, 32H. This is also applicable to the protocol I described above.

Jerson