LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert date/time to HEX command and write to a bin file


smercurio_fc wrote:
. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").

    Well, in my program every number of the string is intrepreted as HEX. So if it is 45, then the byte that I want is 0x45.

     

0 Kudos
Message 11 of 20
(1,898 Views)

Hi igurov,

 

the problem is: HEX is something different than BCD...

 

See attachment, it creates an array of BCD numbers from the date/time string...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 12 of 20
(1,889 Views)

Hi GerdW,

 

I have done this as well but in a little bit more complicated way. The question that I have is that how to write this command in a binary file so that when I send it the program knows that this is hex and nothing else.

 

Thanks a lot

 

Iliya 

0 Kudos
Message 13 of 20
(1,885 Views)

Hi igurov,

 

see attachment for saving to file. Rather simple and straightforward...

 

"the program knows that this is hex and nothing else"

Which program? If it's your vi then you have to ensure this. Smiley Wink Maybe using some headers? Making your own file format? Using config files?

Message Edited by GerdW on 08-19-2009 09:43 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 14 of 20
(1,881 Views)

GerdW,

 

You could simplify your conversion by doing a hex string to number instead of decimal, then the output is the number you need; no bit twiddling needed!

 

Or..... Inside the loop use scan from string with format %2x. The value output is the array element, the string output feeds back to the next iteration via a shift register. [Use either a for loop with N=6 or a while loop terminating on string output is zero length] Now you don't need a separate part of the loop to extract the required segment of the input string.

 

(Sorry can't post files!) 

 

 

Rod.

 

 

 

0 Kudos
Message 15 of 20
(1,861 Views)

igurov wrote:

I know exactly what the difference between decimal and hex is!? But I am not sure whether you understand what I really want.

I have a specific requirements and mainly that I have to write the string of date/time as hex value in a file and then send it via serial connection. Please, tell me, where in the whole story sth does not make sense to you.


The fact that, as has been pointed out, you are actually talking about BCD, not HEX. Treating a BCD number as HEX is simply not correct, as they are two different numbers. But then, you already knew that, right?

0 Kudos
Message 16 of 20
(1,856 Views)

Hi Rod,

 

thanks for advice!

 

The "hex string to number" would fit fine here. My calculation is the more general way (when just providing an array of numbers).

 

"Use either a for loop with N=6 or a while loop terminating on string output is zero length"

Well, at the moment I'm checking for "less than 2", which is more error-safe in case of odd-length strings Smiley Wink

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 17 of 20
(1,853 Views)

GerdW wrote:

 

 My calculation is the more general way (when just providing an array of numbers).

 

...... checking for "less than 2", which is more error-safe in case of odd-length strings


Of course, yes. My suggestion was very specific to this particular case. I was assuming correct input as there was no user-influence upon it. But we all (should) know how correct user input is. Smiley Wink

0 Kudos
Message 18 of 20
(1,836 Views)

@smercurio_fc wrote:
Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").

smercurio_fc, i have the same requirements as you mentioned in the above post... and the code you posted here, should suffice my requirements, but a question... why did you subtract 2000 from YEAR in your vi?

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 19 of 20
(1,344 Views)

@CrackJack wrote:

@smercurio_fc wrote:
Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").

smercurio_fc, i have the same requirements as you mentioned in the above post... and the code you posted here, should suffice my requirements, but a question... why did you subtract 2000 from YEAR in your vi?


To get a 2-digit year. That was part of the original format.

0 Kudos
Message 20 of 20
(1,319 Views)