Reading/Displaying HEX bytes?
I'm trying to write code to read PELCO-D code from a PTZ camera interface.
PELCO-D is sent as a string of 7 bytes. The first is always $FF. In my set-up, the second byte is the camera ID of $02. I want to display the 7 bytes in HEX on a line then CR to the next line.
I have communication established between the BS2 and the interface. For testing I am sending the CAMERA STOP command (FF, 02, 00, 00, 00, 00, 02) to the BS2
My code as it is:
The result on the DEBUG Terminal for the CAMERA STOP command is: ?
PELCO-D is sent as a string of 7 bytes. The first is always $FF. In my set-up, the second byte is the camera ID of $02. I want to display the 7 bytes in HEX on a line then CR to the next line.
I have communication established between the BS2 and the interface. For testing I am sending the CAMERA STOP command (FF, 02, 00, 00, 00, 00, 02) to the BS2
My code as it is:
' {$STAMP BS2}
' {$PBASIC 2.5}
serStr VAR Byte(7) ' make 10-byte array
Main:
LOW 1 ' Enable Receive
SERIN 0, 16780, [STR serStr\7] ' get nine bytes ' Receive 7 bytes of HEX bytes
DEBUG STR serStr\7, CR ' Display
HIGH 1 ' Disable Receive
GOTO main
The result on the DEBUG Terminal for the CAMERA STOP command is: ?
Comments
FOR i = 0 to 6 DEBUG HEX2 serStr(i) IF i < 6 THEN DEBUG " " NEXT i DEBUG CR
That sure did make a difference. I've been looking at those two sections but I must have glazed over the parts that would have helped me. I was also using the inverted Baud Rate code so that didn't help.
With the following code, I'm getting results much more in line with what I should:
' {$STAMP BS2} ' {$PBASIC 2.5} serStr VAR Byte(7) ' make 7-byte array Index VAR Byte Main: LOW 1 SERIN 0, 396, [STR serStr\7] ' get nine bytes FOR index = 0 TO 6 DEBUG HEX2 serstr(index) IF index < 6 THEN DEBUG " " NEXT DEBUG CR HIGH 1 GOTO main
Where I should get "FF 02 00 00 00 00 02" though, I get "00 FF 02 00 00 00 00". I'm not sure where that first 00 byte is coming from. The 7th byte is a check sum that includes the 5 bytes after the FF. In my example it should be 02 but I think this it's getting truncated.
Doesn't it look like I should be receiving 7 bytes? I think I may need to use a WAIT modifier to begin the 7 byte string at the $FF byte.
falcon