LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading hex commands from text file and sending them on the serial port

Hi there,

I want to send hex commands( one command has three bytes e.g. 0x01,0x11,0x80) to a hardware over the serial port. I want to read all the commands from text file. But when I try to read the commands from the text file and write them to serial port it seems each character in the command is converted to hex equivalent of ASCII character on transmission so instead of three bytes I end up sending six bytes. Is there a good way to do this?

Thanks
Kanwar

0 Kudos
Message 1 of 7
(4,623 Views)

After reading your hex byte, use TypeCast to convert it into an ASCII character.  Send this character over the serial line.  The picture below shows that Type Cast will convert the byte into an actual ASCII character, versus just converting to a string.

Message Edited by tbob on 10-25-2005 12:02 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 7
(4,616 Views)
Thanks for your reply.

I guess I did not make my question clear, accept my apologies. Let me try one more time.I have a text file with one string in it  0110FF. This string is actual a hex command. Which means that data going on the serial port should be 0x01,0x10,0xFF.
When I read the text file I get the "string" 0110FF and when I try to send it on the port it goes out 
ASCII value of 0
ASCII value of 1
ASCII value of 1
ASCII value of 0
ASCII value of F
ASCII value of F
0 Kudos
Message 3 of 7
(4,607 Views)

That is exactly what you are asking.

The hex representation of the characters is sent out.

To send the real value you have to translate the hex string into 3 character before you send it to the serial port.

Do NOT typecast but a conversion is needed.

In the string/number conversion palette you find the "hexadecimal string to number" function.

That one should do it.

Eventual search for hexadecimal and that function should show up in the search view. 

greetings from the Netherlands
0 Kudos
Message 4 of 7
(4,604 Views)

You cannot wire a number (numeric type) into the VISA Serial Write function, it expects a string.  If you simply send the string "0110FF", each character will be sent as is, meaning six characters (or 6 bytes) will be sent.  If you want to send the value 0x01, 0x10, 0xFF, from a string "0110FF", you have to break the string into 3 2-character substrings, convert those to numbers, then type cast into a string to get the ASCII characters for those 3 numbers.  See attached vi:

 

Message Edited by tbob on 10-25-2005 02:22 PM

Message Edited by tbob on 10-25-2005 02:23 PM

- tbob

Inventor of the WORM Global
Message 5 of 7
(4,600 Views)
Now you get a number as output with  "hexadecimal string to number"  function . Without type casting how to convert it to string so that its value can be passed to VISA write? I tried to type cast it to convert to string. I got 0001 1080 for command 011080 as hex going to serial port.

011080 (string)--->" hexadecimal to string" function ---> 11080 ( a number) -----> type caste to hex-----> 0001 1080 ( hex string going on port, two extra 00 are appended on front)
0 Kudos
Message 6 of 7
(4,588 Views)
I did not see your second reply so ignore my previos reply. I think  the example should work.

Thanks a lot.

0 Kudos
Message 7 of 7
(4,586 Views)