Hexadecimal Reading with the Serin command
Manuel Henriques
Posts: 4
I need the following help...
I have a display that send and receive the command in hex , and I'm having trouble to read with serin command (BS2)...
Example
Reading date and time sending the command (SEROUT) A5 5A 03 81 20 07
The response of the display (SERIN) A5 5A 0A 81 20 07 01 04 14 05 21 24 12
01 04 14 - DATE (D-M-Y)
05 - DAY WEEK (W)
21 24 12 - TIME ( H-M-S)
I need your help to learn how to send and receive the data used Serin and Serout Command and put one of the fields (D) (M) (Y) - (H) (M) (S) - (W) individually in the following variables (DAY) (MOTH) (YEAR) - (HOUR) (MIN) (SEC) - (WEEK).
If someone can post an example I am very grateful,
Best Regards,
Manuel Henriques
I have a display that send and receive the command in hex , and I'm having trouble to read with serin command (BS2)...
Example
Reading date and time sending the command (SEROUT) A5 5A 03 81 20 07
The response of the display (SERIN) A5 5A 0A 81 20 07 01 04 14 05 21 24 12
01 04 14 - DATE (D-M-Y)
05 - DAY WEEK (W)
21 24 12 - TIME ( H-M-S)
I need your help to learn how to send and receive the data used Serin and Serout Command and put one of the fields (D) (M) (Y) - (H) (M) (S) - (W) individually in the following variables (DAY) (MOTH) (YEAR) - (HOUR) (MIN) (SEC) - (WEEK).
If someone can post an example I am very grateful,
Best Regards,
Manuel Henriques
Comments
The HEX2 modifier makes sure the data is 2-digit hex before placing it into the variables. The assumes the data stream is as you showed in color. What are the bold values? If the seven variables of the date are encoded in the six bold hex bytes, then you will have to translate it according to how it is encoded. In that case, you would have to read the six hex bytes into an array and manipulating it later. SERIN can't parse data down to the bit level.
where string is a six element array of bytes.
I'll echo the questions for more information from Hal and Sapphire. Here is another possibility.
If those are binary coded decimal values (which are closely related to hex, and commonly used by real time clocks) then here is some alternative code:
The data ends up as BCD values in the successive memory locations named from "day" to "second". The variables have to be defined in the order shown and they make what is called an "implicit array".
Because of the time difference, morning will be posting more information about the display and control to guide me in the best way ...
In the office tomorrow I will test some of this information...
A5 5A 0A 81 20 07 01 04 14 05 21 24 12 This is the information I get from the display, only care the last 7 bytes. With this command SERIN 1,baudmode,[ STR day\7], information received in bold is ignored?
Thank you very much,
Best regards
which will ignore (skip) the first 6 bytes, and then read in the next seven into the variables shown.
Thanks for your explanations. I tried both options and both work.
Command to receive the date and time:
SEROUT Tx,br,[$A5, $5A, $03, $81, $20, $07]
Return with date and time
SERIN Rx,br,[skip 6, Year]
In this example only did the reading year
My doubt is the following, the information in this variable year is 20, which corresponds to the year 14 ... I need to compare the year 14 ... as if I'm inside my variable 20... How can I make this check.
Exemple:
If Year = 14 Then Start
Thank you very much,
Best regards
as it appears the data is DECimal, not HEX. Then year = 14. The "2" in DEC2 means two digits. You must include this otherwise the DEC command doesn't know when the digits end if they are not separated by a space.
I did the command, but the variable year is "0" .... SERIN Rx,br,[skip 6, DEC2 year]
There are some test for me to do,
Best regards
This should give you the correct decimal value.
The BCD values are stored in the named Stamp variables starting at "day". Use the formula suggested by Sapphire if you need to convert them from BCD to straight binary. You might want to do that for purposes of elapsed time computation.