09-14-2012 09:15 AM
I have an integer 32 value, for example 904 (0x388) that I need to write to a serial port with the actual byte value 0x0388. The VISA write expects a string, and when I convert the value using the vi 'number to hex string', the value written is not the same. Instead the asci value of 33 3838 is passed on.Is there a way to push the actual integer value 0x388 to the serial line so that device on the other end gets the true value?
09-14-2012 09:26 AM
09-14-2012 09:33 AM
The Flatten to String is the guy you want so you can set the endianness.
09-14-2012 09:53 AM
I'm inferring from the question that you want to send exactly 2 bytes to the serial port, the byte with value 0x03, followed by the byte with value 0x88
If that is so, a type cast to string is suitable. This preserves the bit pattern of the input. Bear in mind that if you do the type cast on a U32/I32, the string (being the same bit representation as the 32 bit / 4 byte value) will have 4 characters/bytes in it, in your example 0x00, 0x00, 0x03, 0x88
So you should either take a substring of the 3rd and 4th characters, or make sure that you pass a 16 bit quantity into the type cast, either by doing you sums in a U16 or by doing a "to U16" before the cast. Use whichever is most appropriate to the calulation that produces the 0x0388 result.
The 'number to hex string' converts the input number into a printable text string representation of the number; here the bit pattern is different. Therefore the 32 bit value of 0x00000388 (or 16 bit value of 0x0388) is converted into three ascii characters '3', '8', '8', having the hex values of 0x33, 0x38, 0x38
Rod.
09-14-2012 12:28 PM
So did you work it out?