LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert an array of hexadecimal numbers to decimal numbers and write to spreadsheet

i'm trying to acquire data from a micro-turbine and there are a set of commands which i use to communicate with it. For example, the SPVDAT command gives an output in this format : SPVDAT,<turbno>=0,6,<ARG0>,<ARG1>,<ARG2>,<ARG3>,<ARG4>,<ARG5>

 

Sample output: SPVDAT,0=0,6,0,0,0,20,0,0

 

ARG 0-5 are the values i need and these are in hexadecimal format; the rest of the stuff is not important. I need these values converted to decimal numbers and written to a spreadsheet.

 

I've attached the original VI and a modified VI where we attempted to convert HEX to decimal. Unfortunately, my output is a bunch of zeros which led me to believe something was wrong.

 

This is just one command. Different commands have different number of arguments ranging from 1 to 20 ARG's! One other command (ALLDAT) has close to 15 sub-commands within it, each with varying ARG's, all in hexadecimal format.

 

Would appreciate any help...thanks!

0 Kudos
Message 1 of 12
(7,204 Views)

Hi,

 

I don't have labview 2011, so I can't open you program. if you save it for previous versions (I have 2010), I could take a closer look.

 

It appears you're getting this arguments from VISA, so you're reading them as strings. Once you've parsed the string you received (I'd like to take a look in the software to comment on this) you can use function block "hexadecimal string to number" in order to convert it. The value displayed will be converted to decimal if your indicator is configured to show values in decimal base.

 

Regards,

Mariana.

0 Kudos
Message 2 of 12
(7,182 Views)

I've attached files saved in previous version.

0 Kudos
Message 3 of 12
(7,179 Views)

You have a classic race condition.  You are reading data from the serial port and writing it to a local variable.  You then expect the other loop to read at the same rate to save to disk.  Local variables are NOT a good way to do this.  You can miss data, have stale data, and it just isn't a good idea.  You should look into using a queue to send the data between the loops or putting all of the code into a single loop.

 

The other thing I see is that your Write to Spreadsheet.vi should have %d for its format.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 12
(7,160 Views)

I was afraid of that, thank you crossrulz. Would that solve my conversion problem (HEX to decimal)? I could use any help in setting up the VI !!

 

Thanks again

 

 

0 Kudos
Message 5 of 12
(7,146 Views)

I'm sure this is a bit of a rube goldberg (especially how I get the string subset). You can probably use a regular expression to more cleanly get the string between the equals sign and the "new line", but I'm regex illiterate. Anyways, Does this do what you need it to?

 

0 Kudos
Message 6 of 12
(7,144 Views)

A slightly more elegant regex to perform the task.

 

Regex to pick data between equal and eol.png

 

If you had multiple lines you could place this in a loop and put the offest past match into a shift register and then process all of the lines. Other regular expressions could be created which would be specific other commands if required.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 7 of 12
(7,128 Views)

@Mark_Yedinak wrote:

A slightly more elegant regex to perform the task.

 

Regex to pick data between equal and eol.png


HA, i knew it was possible! Time to get a regex book...

0 Kudos
Message 8 of 12
(7,126 Views)

Hello again,

 

I tried out the regex solution you suggested. The "Match Regular Expression" is taking in the input string and Regex, but there is no output from it at all, once we tested it with the turbine. Could use your help with this. We tried another way of splitting the string at the regex and i've attached that VI. This is for just one input command.

 

We have another command, "ALLDAT" with 21 sub-commands. The output would look something like the following, in HEX code like the earlier problem :

 

ENGDT1,0=0,8,7d4,1,17,c,f,32,0,0
ENGDT1,0=8,9,28f,293,291,25c,0,1388,1f9,e228,0
ENGDT2,0=0,4,0,71b,f0,0
ENGDT2,0=4,7,4a,5,14,156,9,7,0
CTRLDT,0=0,6,3001,0,0,0,2c40,0
CTRLDT,0=5,8,1b01,249,11558,183,0,1,1,00cc
RFCDAT,0=0,8,0,81,0,0,7717,0,0,0
SPVDAT,0=0,6,0,0,0,20,0,0
BCDAT1,0=0,10,12,0,1b,19,3b9,3e7,3e7,0,0,0
BCDAT1,0=10,10,0,0,1733,3336,0,0,1,0,0,0
BCDAT1,0=20,2,1adc,1
INVDT1,0=0,5,0,0,0,0,0
INVDT1,0=5,5,0,0,0,0,0
INVDT2,0=0,5,0,3b40,3b8b,3b4d,ffff
INVDT2,0=5,5,0,0,0,1b,1ff
GENDT1,0=0,6,0,fffffffe,1,0,0,a55
GENDT2,0=0,5,0,244,1b,0,0
GENDT2,0=5,4,0,0,28d,a22
BATDAT,0=0,9,0,7d4,115,0,0,0,0,1,a
LFCDAT,0=0,5,0,0,0,0,0
MLOCKD,0=0,1,00000007
CHPDAT,0=0,8,0,0,c8,44,43,4e,13,0
CHPDAT,0=9,2,00000041,0

 

This is one block of data and i need to just separate the necessary values. For eg: the 1st sub-command, ENGDT1 has 8 ARGS (7d4,1,17,c,f,32,0,0) and the last, CHPDAT has 2 ARGS (00000041,0). I just need the ARG's from each sub-command. I was thinking of putting it in a loop, but since this is one single block of output, i'm not sure how well that would work.

 

Thanks again for the help!

0 Kudos
Message 9 of 12
(7,088 Views)

this may help you out

 

Array hex to decimal.png

0 Kudos
Message 10 of 12
(7,071 Views)