PDA

View Full Version : How do I Send & Receive HEX values via Serial?



DavidM
04-30-2008, 01:15 PM
Hi

Now that I have my AERCOM AC4490-200M-02 Module working ( sort of??)

all the documentation for the commands are in HEX, so..

Q1) How to I send ( and receive ) HEX values via the EXTENDED_FDSerial Object??

for example I want to send

$CC C1 80 06 to my Aerocomm module

I know that some hex values can be converted to ascii , but some don't have keyboard equivalents ie. $CC is some kind of A with a line above it??

Q2) This command will also return HEX values as well, So How to I view the result as HEX on my LCD? ( I am using a string pointer variable)

Q3) Ideally I want to create CONSTANTS for my HEX Commands , Is this done with a DAT declaration?

eg..

EnterATCmdMode := $41, $54, $2B, $2B, $2B, $0D
ExitATCmdMode := $CC, $41, $54, $4F, $0D


Thanks

Dave M

Peter Jakacki
04-30-2008, 08:09 PM
Dave,

Remember that hex is just a way of representing the bytes that are transmitted for us humans to read, it's all 1's and 0's at the end of the day. If I said that the Aerocomm had to receive 01000001 you might scratch your head. If I said it had to receive A you might still scratch your head. If now I say that you have to send $41 in this manner ---> Serial.tx($41) then you would type that in exactly like that and it would work. So would Serial.tx(%01000001) and so would Serial.tx("A") as they all do the same thing. I've included a short demo code snippet and the "hex" output, notice the two "HELLO" strings as well as the two "AT+++" strings that were compiled.

*Peter*



obj
serial: "Extended_FDSerial"

pub demo
serial.tx($41) 'sends out the character "A"
serial.tx("A")

serial.str(string("HELLO")) 'sends out "HELLO"
serial.str(string($48,$45,$4C,$4C,$4F)) ' same

serial.str(string($41, $54, $2B, $2B, $2B, $0D)) 'forces modem to enter command mode
serial.str(string("AT+++",$0D))

serial.str(string($CC, $41, $54, $4F, $0D)) ' exit command mode
serial.str(string($CC, "ATO", $0D)) ' exit command mode



00000000 00 1B B7 00 00 8E 10 00 AC 06 0C 07 1C 00 10 07 ииииииииииииииии
00000010 6C 00 02 01 0C 00 00 00 6C 00 00 00 01 38 41 06 lиииииииlииии8Aи
00000020 02 05 01 38 41 06 02 05 01 87 80 43 06 02 08 01 иии8AииииииCииии
00000030 87 80 49 06 02 08 01 87 80 4F 06 02 08 01 87 80 ииIииииииOииииии
00000040 56 06 02 08 01 87 80 5D 06 02 08 01 87 80 63 06 Vииииии]ииииииcи
00000050 02 08 32 48 45 4C 4C 4F 00 48 45 4C 4C 4F 00 41 ии2HELLOиHELLOиA
00000060 54 2B 2B 2B 0D 00 41 54 2B 2B 2B 0D 00 CC 41 54 T+++ииAT+++иииAT
00000070 4F 0D 00 CC 41 54 4F 0D 00 00 00 00 8C 03 12 01 OиииATOиииииииии
00000080 4C 00 00 00 55 00 00 00 5A 00 00 00 60 00 00 00 LиииUиииZиии`иии
00000090 65 00 00 00 6B 00 00 00 71 00 00 00 78 00 00 00 eиииkиииqиииxиии
000000A0 7E 00 00 00 84 00 00 00 8B 00 00 00 92 00 0C 00 ~иииииииииииииии
000000B0 1B 01 10 00 BB 01 10 00 60 02 10 00 07 03 04 00 ииииииии`иииииии
000000C0 3D 03 08 00 8C 03 10 00 01 64 68 6C 70 06 12 01 =ииииииииdhlpиии

DavidM
05-01-2008, 05:57 AM
Hi Pete,

Thanks for the clear explanation

I guess all I needed to know was the SYNTAX for the multiple hex values, I did not know that the string function handles it this way,

i.e

STRING( $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF )

and also combining different data types

e.g.

Hex, Alpha and numeric..

STRING( $FF, "HELLO", 13 )


This is not mentioned in the manual for the string function. (PAGE 310 )

Thanks

Dave M