working with HEX
docwisdom
Posts: 28
I am trying to do a few things with HEX and am having no luck so far.
I am doing a SEROUT command for our dispenser (who requires hex)
so I need to calculate some HEX values to generate a checksum.
I also am sending a status request to the unit and am using SERIN to get the status, but I am not getting the information I need.
___________________________________________
the checksum
B3 01 0E 7F 01 01 01 01 01 01 01 01 ___ 0D
the blank is the checksum location and is an addition of the previous bytes then %FF (47 in this example)
my attempt
fk_chksm = $B3+$01+$0E+$7F+fk_hopr(0)+fk_hopr(1)+fk_hopr(2)+fk_hopr(3)+fk_hopr(4)+fk_hopr(5)
but the fk_hopr variables are decimal :P
___________________________________________
the status check
SEROUT 4, 16416, [noparse][[/noparse]$B3, $01, $06, $80, $3A, $0D] 'send request for status
the unit then sends
88 01 07 80 00 10 0D
I need to grab the 00 byte
My attempt was
SERIN 3, 16416,[noparse][[/noparse]HEX J(0), HEX J(1), HEX J(2), HEX J(3), HEX VSTATUS]
with no luck. I also tried using a WAIT(128) to look for HEX 80 but that didnt work either.
Post Edited (docwisdom) : 10/8/2009 9:44:00 PM GMT
I am doing a SEROUT command for our dispenser (who requires hex)
so I need to calculate some HEX values to generate a checksum.
I also am sending a status request to the unit and am using SERIN to get the status, but I am not getting the information I need.
___________________________________________
the checksum
B3 01 0E 7F 01 01 01 01 01 01 01 01 ___ 0D
the blank is the checksum location and is an addition of the previous bytes then %FF (47 in this example)
my attempt
fk_chksm = $B3+$01+$0E+$7F+fk_hopr(0)+fk_hopr(1)+fk_hopr(2)+fk_hopr(3)+fk_hopr(4)+fk_hopr(5)
but the fk_hopr variables are decimal :P
___________________________________________
the status check
SEROUT 4, 16416, [noparse][[/noparse]$B3, $01, $06, $80, $3A, $0D] 'send request for status
the unit then sends
88 01 07 80 00 10 0D
I need to grab the 00 byte
My attempt was
SERIN 3, 16416,[noparse][[/noparse]HEX J(0), HEX J(1), HEX J(2), HEX J(3), HEX VSTATUS]
with no luck. I also tried using a WAIT(128) to look for HEX 80 but that didnt work either.
Post Edited (docwisdom) : 10/8/2009 9:44:00 PM GMT
Comments
Try leaving out the HEX. That way J(0) will be $88, J(1) will be 1, J(2) will be 7, J(3) will be $80, and VSTATUS will be 0
fk_chksm_init = $B3+$01+$0E+$7F
fk_chksm_hopr = fk_hopr(0)+fk_hopr(1)+fk_hopr(2)+fk_hopr(3)+fk_hopr(4)+fk_hopr(5)
fk_chksm = fk_chksm_init + fk_chcksm_hopr
interestingly it provided only the last two digits of the addition, 45 instead of 145 which is what I expected. I was planning on having to apply FF to it to get 45. Is this a characteristic of addition in PBASIC?
Im a little confused on formatting and how PBASIC displays the various formats. How is it that I will get a HEX output without telling the code to operate in HEX? Isnt everything binary in the core anyway?
Post Edited (docwisdom) : 10/9/2009 4:42:43 AM GMT
I cant figure out why this variable is showing up with the wrong value.
New question:
I am successfully sending my serial data to the vending unit. It then sends back an acknowledgment string.
ie
send: B3 01 06 80 3A 0D
should receive: 88 01 07 80 00 10 0D
actually receive 2C 07 00 D4
so im not getting enough bytes and they are not what I am expecting. I am running at 19200, N8 as noted in the vending manual. The only thing I am not sure on is the 1 stop bit it says to use.
SEROUT 4, 16416, [noparse][[/noparse]$B3, $01, $06, $80, $3A, $0D]
SERIN 3, 16416,[noparse][[/noparse]SRC, DST, JNK1, JNK2]
Don't forget that you have to declare fk_hopr as a byte array of the correct size for your code.