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?
Solved! Go to Solution.
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
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.
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.
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.
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!
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.
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?