From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending ASCII character codes to serial port

Hello,

I have a remote controlled relay that takes commands via a serial port. It takes commands in ASCII character codes, 1 meaning turn on relay for instance. My problem is that when you send a 1 to the serial port, it gets interpreted as the ascii character 1, ans sends the code for 1 instead (49).

Does anyone have a good solution for this?

Thanks,
Mathias
0 Kudos
Message 1 of 6
(7,400 Views)
Hi Mathias,
right click on the string constant you are sending to the serial port, check "Hex display", then input any numerical value you want (in hex form, of course)
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 6
(7,389 Views)
I'm not sure if this will solve your problem but you could try to use the Byte Array To String and the String to Byte Array functions. In LV8.2.1, there are located in the String >> String/Array/Path Conversion group of the functions palette.



See the context help for more details.

Message Edité par JB le 05-10-2007 10:37 AM

0 Kudos
Message 3 of 6
(7,387 Views)
Thanks for your quick replies,

I looked at the 'byte to string' earlier but did not quite understand how it worked. Is it so that the string then will contain the ascii characters that in the end will be transformed to the correct ascii character code?

0 Kudos
Message 4 of 6
(7,379 Views)
Exactly. JB's suggestion may be very useful especially when the command contains variable parameters and must be dynamically built.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 6
(7,370 Views)
Ok, I got it to work. Thanks guys!
0 Kudos
Message 6 of 6
(7,365 Views)