Showing results for 
Search instead for 
Did you mean: 

serial comunication and hex

Go to solution



I am trying to get information from a device that only has one way communication, so I want to sent my device a commando that opens a relay, and then I can measure if the relay is open or not by using the CTS and check for voltage differers. The commando has to be five byte long and in Hex code, I want to read a 16 bit long number. The string constants are known commands and are written in Hex display.

The attached code doesn't work and I suspect that it is the type conversion to Hex that is causing the problem?

0 Kudos
Message 1 of 12
Accepted by ollef

Hi ollef,


please refer to this actual thread, which discusses "hex" vs. "decimal" in a quite long way.


And yes, the "to hex string" conversion is wrong here Smiley Wink

Best regards,

using LV2016/2019/2020 on Win8.1/10+cRIO
0 Kudos
Message 2 of 12
And posting an image is not the correct thing to do here. Attach an actual VI. No one can debug a picture and no one can check the string properties of an image.
0 Kudos
Message 3 of 12

In the middle of your concatenation, you aren't doing a typecast to "hex".  You are taking a number and formatting it to a hex formatted text string.  So if you had the number 16 going in, you are getting 10 out, but that is two characters, a "1" followed by a "0", not a single byte of 10hex.  Or as in your screen shot, the number 15 goes in, comes out as F,  but the character "F" (decimal 71, hex 47) as opposed to a byte of value decimal 15 (a non-printable control code).


Try byte array to string, or typecast a U8 input to a string.  See this message thread (same as Gerd's above) where the original poster was having a similar problem.

Message Edited by Ravens Fan on 06-23-2009 10:27 AM
0 Kudos
Message 4 of 12



Thanks for the replyes, I think that I've got the Hex code right now but my program is still not doing what I intend, but I think that it might be other problems like my wiring or broken parts that might be the problem.

0 Kudos
Message 5 of 12

Are you sure you are communicating using a valid serial port?  You have string control wired into your Serial Configure VI.  Delete that.  Right click on the terminal the wire goes into and pick Create Control.  Now you will have a VISA control that will list your valid serial ports.  (Likewise for baud rate.  Your control is a double representation being coerced to a U32 integer).


Do you have a manual for this relay device?  Perhaps the protocol for your command bytes is not correct.  Do you hear anything clicking when you run the code.

0 Kudos
Message 6 of 12
In your code up top, your last two bytes are 31 31 (hex).  That would be 49 49 in decimal.  But in your attached VI, your last two bytes are 4 and 4 in decimal.
0 Kudos
Message 7 of 12



sorry byt I do not have a manual, that is one of my bige problems. I've tryed the changes you proposed but it did not help, I'm not getting any signal from the device at all, and I do not hear any clicking. I now that it works since I have a old test jig that I can test it in and it works (clicking and all), but probably it is the comands that I'm sending in that is wrong!

0 Kudos
Message 8 of 12

How does the old test jig work?  It is communicating with it serially?


If so, try tapping into the transmit line from the communicating device (a PC?) to the relay device.  Feed that line into another PC serial port.  (You will need ground as well).  Open up the serial port on the extra PC and basically try to spy on the communication between the "test jig" and the relay device.


Actually, since the relay device doesn't communicate back, there must be no real way for the test jig to know what it is doing, so just use the appropriate cable to connect the test jig's serial port to another PC's serial port and see what is being sent.  No tap necessary.



0 Kudos
Message 9 of 12



I actualy started to read the code that operates the test jig, and found out that the five bytes that is sent always ends with 55(Hex) so I've aded that now, bot without any luck. Do you think that the CTS can read the responce from the device, and that I can use it to read the serial number as I intended?

0 Kudos
Message 10 of 12