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: 

VISA serial communication shows zero bytes at port

Solved!
Go to solution

I have a development board that communicates over serial port. The following shows the basic properties of the serial port.

Development board Serial port propertiesDevelopment board Serial port properties

The board uses binary message format (35 bytes of ASCII encoded data is converted into binary) to communicate with a Bluetooth device which is always ON and broadcasting. In return for a successful connect , it sends back a handshake message exactly as  the sent message but with a different identifier (however the total number of bytes remains the same).

 

For instance:

Byte array for Connect: 33, 10, 0, 0, 0, 53, 50, 82, 68, 88, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 165, 1

The first byte is the ASCII exclamation mark (red)

The last 2 bytes is the sum of the middle 32 bytes (green)

Example expected result: 33, 10, 0, 0, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 1

 

As you can see below, I am converting the array of 35 bytes to binary for VISA Write and I expect 35 bytes to be read back as well. Alas, I am not sure why I am not able to read anything back, and Bytes at Port always shows 0. The port settings are as per the properties figure shown above (the figure below doesn't show VISA open/close, but the attached VI should serve as a MWE).

 

Any advise is appreciated. Thanks.

 

LV2019LV2019

 

 

NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 1 of 14
(3,453 Views)

Of course it is 0, you didn't provide anywhere near enough time between the VISA Write and the Bytes at Port to give the device time to respond!

 

This is yet another example of where "Bytes at Port" is the wrong thing to use.  Get rid of it.

 

Since you know the response string is the same length as the Write string, just get the length of the string you wrote then wire that into the VISA Read.

 

Also, the VISA configure should be before the loop, not inside.

0 Kudos
Message 2 of 14
(3,426 Views)
Okay, I will do the changes. One clarification- it says Byte count at VISA Read, but since my input is Binary (35 bytes = 280 bits). Should I wire Byte Count i.e. 35 or length of binary write string = 280 ?
NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 3 of 14
(3,416 Views)

It says Byte Count.  Not Bit Count.  Why would you think you'd wire 280?

0 Kudos
Message 4 of 14
(3,412 Views)

Did all three changes as per your advice. Played around with time factor ranging from 10s to 60s. Didn't make a difference yet.

 

iaBb2Zi

advanced properties of the serial port board.

XP9kTfr

NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 5 of 14
(3,403 Views)

I'm confused.  And I guess I missed that part the first time you posted the VI image.  Why are you converting your 35 byte string into a string of 0's and 1's?

 

You had said you were sending 35 bytes and gave examples of that.  I didn't see your For Loop where you converted each byte into an 8 character string of 0's and 1's.  Does your device really want that?

0 Kudos
Message 6 of 14
(3,394 Views)
Yes the device takes in message in Binary only. Therefore 35 bytes of data array is converted into its corresponding Binary format.
NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 7 of 14
(3,389 Views)
Also the return count at VISA Write shows 280, whereas in the HELP it shows "return count contains the actual number of bytes written. "...

Doesn't make any sense why would it show 280. It should have shown 35 (bytes).
NI System Configuration:
- NI PXIe-1071, 4-Slot 3U PXI Express Chassis , 1 GB/Slot throughput, Part Number: 781368-01
- NI PXIe-PCIe8381,x8 Gen2 MXI-Express for PXI Express Interface,3m, Part Number: 782522-01
- PXIe-5160 PXI Oscilloscope, 500 MHz, 10 bits, 2.5 GS/s, 2 Channels, 64 MB, Part Number: 782621-01
- Astronics PXIe-1209 2-Channel, 100 MHz PXI Pulse Generator, Part Number: 785033-01
0 Kudos
Message 8 of 14
(3,385 Views)
Solution
Accepted by topic author asukumari

NO NO NO.

 

Your string manipulation turned 35 bytes into 280 bytes when you converted each byte of data into 8 bytes such as "01010101" with that inner For Loop.  When you sent a "0", you sent a byte of value 48 decimal.  And when you sent a "1", you sent a byte of value 49 decimal.

 

I really doubt your device wants 8 characters of "1" and "0".  I suggest you reread the manual for your device.

Message 9 of 14
(3,381 Views)

Hi asukumari,

 

Yes the device takes in message in Binary only.

What happens when you get rid of that conversion to 01-strings?

What kind of device are you talking to? Can you attach a manual of that device?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 14
(3,379 Views)