Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

convert ascii from serial port to decimal

Hi,
I am reading commands sent from a serial port.  I am able to tell the port what to do.  The problem I am having occurs with the converting of the ascii to recieved from the port.  Here is an example of the value read from the port; 0509 0D00 0000 9343 4C.  I know the correct decimal value for this string value, but I can't get LV to display the correct decimal value.  I use a vi to convert the text to hex, remove the spaces, then use a for loop to get the substr and run that substr through multiplt hi/lo.  I then take the hi/lo value and join the numbers back together, times by a constant and recieve an incorrect decimal value.  Is there a simple way to extract the decimal equivalent value?
 
Thanks,
Adam
0 Kudos
Message 1 of 12
(6,749 Views)

can you send the VI that makes the convertion.

what number this hex value should correspond to?

0 Kudos
Message 2 of 12
(6,742 Views)

Hi,

I believe this hex number should correspond to 20, but I am not sure, I don't have the actual codes with me right now.  Here is the vi I am using.  I get decimal values read into the array, but they are not close to what the real value should be.

0 Kudos
Message 3 of 12
(6,734 Views)
Standard disclaimer: HEX is a way to display binary, HEX has no value in itself.

Most of the time when manuals talk about HEX they mean binary, so it is much easier to look at the real values or the real string.
the example you gave is 0509 0D00 0000 9343 4C
so the decial values are: 5,9,13,0,0,0,147,67,76
no combination of these values delivers the decimal value 20
The last two values correspond to "CL" maybe you can find these characters in the manual and 147 (x93) is 19 with the highest bit removed, maybe a shot in the dark?

give us some more info and this riddle should be solved



greetings from the Netherlands
0 Kudos
Message 4 of 12
(6,724 Views)
Here is a real value read from the port.  The value 0509 0000 0000 C842 24 should correspond to a decimal value of 100.  The computer sends 0509 0D00 0000 C842 25 and the port respond with 0509 0D00 0000 C842 25.  I am able to send the commands to the port, but I can't decript the commands sent from the port to my computer.  I need to be able to have the port send the comand 0509 0000 0000 C842 24 and have my computer display the value 100.
0 Kudos
Message 5 of 12
(6,709 Views)
I must admit I don't see the solution yet.
Is it a standard instrument or something special.
If it is an instrument what brand and what type.
Is the number of bits 8 or less and if less what protocol exactly.

Or is it maybe (wild guess) a float of 8 bytes or less with a leader or end character?
greetings from the Netherlands
0 Kudos
Message 6 of 12
(6,697 Views)

Hi Shivels,

I played around with a number of conversions (e.g. string to number) and never got 100 out using your program. If you only want this one long code to output 100, you could just use a case structure. There are also a number of programs on this post that have conversions you could try:

http://forums.ni.com/ni/board/message?board.id=170&message.id=200382&requireLogin=False

If none of those work, please post about how that conversion should take place becuase it appears it is not a normal hex to decimal conversion.

Thanks,

Stephanie

0 Kudos
Message 7 of 12
(6,697 Views)
Hi,
I was able to get the vi to output the correct value in array postion 2, by only multiplying the by 1 and changing the 8's to 4's.  I will eventually take the multiply by 1 out, as it has no purpose.  The next problem has to due with the way the the values read in are arranged.  Reading 1 group at a time works fine, but when I try and read multiple groups, like 0509 0700 0000 C040 15 and 0509 3100 643B 5F41 7E, individually they work fine, but when I run them together, I get the following group: 0509 0700 0000 C040 1505 0931 0064 3B5F 417E.  Becuase of the 15 at the end of the first group, it tries to group the sting into groups of 4, messing up the hi/lo values for the following strings.  Is it possible to ignore/delete individual groups based on their size.  For example, keep C040 but ignore/delete 15 because it is only of size 2?
 
Adam  
0 Kudos
Message 8 of 12
(6,682 Views)

Hi,

I figured out how to do the ocnversions necessary, thanks for all your help.

Adam

0 Kudos
Message 9 of 12
(6,674 Views)
Hi
 
How did you do the ASCII to DEC conversion? I need this too, well I need to convert from DEC to ASCII, if you could help me out please.
 
Simon


Message Edited by SCMAJA on 11-14-2007 07:32 PM
LabVIEW 8.6 / 2009 / 2010
Vision Development Module 8.6 / 2009 / 2010
VBAI 3.6 / 2010
0 Kudos
Message 10 of 12
(6,253 Views)