Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial comunication, hex to ascii

I am writting data to my PIC chip via the serial port. The commands I have to write are all in hex, like 0x85. How would I convert that to an 8 bit , not 7, data packet for the serial communication.
0 Kudos
Message 1 of 5
(3,530 Views)
If you're communicating using 7 data bits, then you will throw-away the MSB. This means that in the case of your hex commands, you will have only 128 possible commands. Also 0x80 will be the same as 0x00, 0x81 = 0x01, etc.

The "throwing-away" of the higher data bit(s) happens at the UART level, so there should be no need to reformat your data before writting out of the serial port. However, you need to be aware that the MSB will be lost in the process.
0 Kudos
Message 2 of 5
(3,528 Views)
Build up your commands by building an array of U8's.
Then use the byte array to string.vi and write to the comport. If that is your problem, it's easily fixed.
Message 3 of 5
(3,528 Views)
I am trying to send the same thing to a pic chip with the MSB and LSB but once i try the basic serial vi. it sends only a string which i cant change it to be hex !!! i might be confused but when i send something from one side it will be sent as string and it will be received as string which means Pic chip will not recognize the input coming through unless its in Hex format ?? how can i fix this ??
0 Kudos
Message 4 of 5
(3,466 Views)
VISA transmits data in HEX format, so for each kind of data you send (ASCII, BInary, HEX, etc), VISA will converted it to its HEX value and send over through VISA. What you can do is right click on the String Control where your command is written and choose "HEX Display" so the HEX values of your ASCII commands will be displayed in HEX--this does not change how the values are sent over VISA.

For example, if you use the HEX display, and send FF, the serial port will transmit the value of 11111111(binary). If you are using Normal Display and send FF,it will have a HEX value of 4646 and being transmitted as a totally different binary number. You can check the following KnowledgeBase for more info:

http://digital.ni.com/public.nsf/websearch/77C8F61D36F5A23086256634005ACB38?OpenDocument
0 Kudos
Message 5 of 5
(3,440 Views)