Hello Folks, Been a long time.
I have a program I'd written awhile back that uses modbus RTU and now we need to add the Modbus Ascii to it so either can be used. Of course the protocol is determined at start up by a jumper. RTU is tried and tested, just have to squeeze in the ASCII portion.
The hit list:
On Power Up Check Jumper then Set Protocol Variable
Set Baud Rate, Parity and other Port Settings to proper values for Protocol
Modify HSerIn to decode accordingly
Modify HSerOut to Encode accordingly
Using HSerin2, which is the easiest way to convert ASCII to Decimal values.
I will be placing the values into an array of byte called BufRx.
The incoming Ascii is like this, with out the spaces.
:01 03 00 00 00 05 13 10
When Decoded, after skipping the Colon, and the CRLF I should have this:
BufRX[0] = 1
BufRX[1] = 3
BufRX[2] = 0
BufRX[3] = 0
BufRX[4] = 0
BufRX[5] = 5
Below, I Wait for the Colon, grab 2 char and convert to decimal and store in array until CR LF.
I know there has to be an easier way but I'm way rusty. Not even sure if this is correct.
HSerIn Timeout,Receive,[WAIT(":"),DEC2 BufRX[0], DEC2 BufRX[1], DEC2 BufRX[2], DEC2 BufRX[3], DEC2 BufRX[4], DEC2 BufRX[5],13,10 ]
Thanks,
Richard