LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert BCD to Hex, but keep the same value

Ok, so here is my issue.

 

I am pulling parameters from our SQL database, and the values are read in as U16 Decimal Integers.

 

I then have to put the parameters into a packet of data and send out over the serial port as Hex.

 

This work fine, except for two of the commands, where the programmers decided to have the "paypload" of the packet as BCD instead of the hex value.

 

So if I put the number straight into my packet creator like all the other commands I get the wrong command.

 

For example, I am setting a date, and want it set to 31.  So I read 31 (integer, u16) from the database.  I then put it into my packet creator (adds header, checksum, etc) and it changes the 31 to 1F (hex).

 

But the command wants me to send the 31 itself.

 

So how to I change a number (31) from decimal/integer to Hex, but keep the same number?  It should be 31 from the database, but also 31 needs to be hex value I send into the packet creator.

Kenny

0 Kudos
Message 1 of 7
(3,749 Views)
Can't you just do a test for the specific commands and skip the converter?
0 Kudos
Message 2 of 7
(3,743 Views)

I use the Build Packet "converter" to add in the Header, and checksum.  So if I skip that, it wont add in the checksum/header, causing the device not to accept it.

 

The output is sent as a HEX string.

 

Kenny

0 Kudos
Message 3 of 7
(3,730 Views)

Here is a screen shot of the code, maybe that helps.

 

The command packet indicator is set to display as Hexidecimal.

 

The payload is standard decimal.  So somehow before I enter the 31 into the payload, I want to somehow "trick" labview to thinking it is a hex value, or I have to change it to 49, so it gets output as 31.

 

build packet.png

Kenny

0 Kudos
Message 4 of 7
(3,725 Views)
So put the case statement inside your converter? It all depends on the command byte, correct?
0 Kudos
Message 5 of 7
(3,719 Views)

Dennis, thank you for your replies so far, I apologize for the delay in getting back to you.

 

Engineering has made another change.  

 

So the payload has some values that need to be converted to hex, and come values that do not.

 

Parameter A = input is an int (12345678),output needed for the command in Hex (12345678)

Parameter B = input is a string (varchar) (ABCD), output needed for the command in Hex 

Parameter C = input is an int (13), output needed for the command in Hex (0D)

Parameter D = input is an int (29), output needed for the command in Hex (29)

 

So the payload may have portions of it that need converting and others that should be passed through, but just as hex instead of int, but of the same value.

 

I apologize if I am not making it clear.

Kenny

0 Kudos
Message 6 of 7
(3,613 Views)

Hi Kenny_K,

 

I'm not sure of what u're trying to do. But, if u know the parameter's data type and how it should be may be u can use simple case structure and convert the data accordingly.

I did a raw brute force method to suit ur requirements ( i'm not sure if this is what u need 😞 )

Thanks
uday
0 Kudos
Message 7 of 7
(3,603 Views)