Need help capturing a response.
Hello everyone! I have a question that is probably simple for you, but I don't know where to start.
I am sending commands to a controller and then getting a response. This is my code:
My question is... how would I capture the response and hold it so I can parse it out later as useful data?
Many thanks in advance.
I am sending commands to a controller and then getting a response. This is my code:
pub send_telegram
waitcnt(clkfreq/100+cnt)
debug.str(string("sending telegram",cr))
waitcnt(clkfreq*2+cnt) 'wait for at least 3.5 character intervals
plc.tx($01)
plc.tx($03)
plc.tx($40)
plc.tx($9B)
plc.tx($00)
plc.tx($02)
plc.tx($A0)
plc.tx($24)
waitcnt(clkfreq*2+cnt)'wait for at least 3.5 character intervals
GetResponse
Pub GetResponse
repeat
rx:=GetDataByte
PUB GetDataByte|Flag,Data,_Rx
Flag := 0
repeat while Flag == 0
Data := plc.rxcheck
if Data <> -1
_Rx := Data
Flag := 1
Result := _Rx
debug.tx(34) 'places a " between hex characters so I can tell them apart
debug.hex(_RX,2)
I am reading the response fine on the parallax serial terminal.My question is... how would I capture the response and hold it so I can parse it out later as useful data?
Many thanks in advance.

Comments
For instance RC time on a pot. I get the rc time decay and then compare it with a table to decipher where the pot is at.
With my current program I have figured out how to display the response from the controller on the serial terminal, but I dont know how to capture the response within the program to get info from it so the program can use that data for actions. Mostly because I'm a moron.
The resonse is actually similiar to the telegram.
For instance send: 01 03 40 9B 00 02 A0 24
recieve: 01 03 3f 00 01 C4 D4 F6
The response is not exact but that's the format.
Have a look at Extended FullDuplexSerial in the Object Exchange. It's an extension for FullDuplexSerial for receiving character strings terminated by a carriage return, but the same technique can be used for receiving other byte strings of information and processing the bytes to derive something useful.
The message would be: 01 03 3F 29 00 02 19 D7
The response would be: 01 03 04 00 00 00 C4 FB A0
Message:
01 -slave address
03 -read register
3F, 29 -parameter to be read
00, 02- 32 bit register
19 ,D7- CRC
01-slave adress
03-read register
04- byte count to follow
00,00,00,C4- result of the read
FB,A0- return CRC
PUB GetResponse : value | cmd, bcnt, crc repeat until plc.rx == $01 'wait for first byte (slave address) cmd := plc.rx 'get command bcnt := plc.rx 'get byte count value := 0 repeat bcnt 'get value value := value << 8 + plc.rx crc := plc.rx << 8 + plc.rx 'get crcBut depending of the number of possible responds and slaves, you might need a more complex parser, and also test if the command is right.
Andy
I Appriciate everyone's help!