02-09-2024 03:34 AM
Hello,
I've encountered an issue with my LabVIEW code. I'm attempting to communicate with an external device that requires serial communication. To achieve this, I've been utilizing the write/read functions. The frame I need to send is as follows:
00x16 00x16 00x16 00x16 00x10 00xFF 00x22 00x00 00x00 00xA7 00x5F 00xF5
It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:
1616161610FF220000A75FF5
Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.
I'm unsure how to resolve this issue. Has anyone encountered a similar problem?
Thank you for your help.
Solved! Go to Solution.
02-09-2024 09:12 AM
Please define all acronyms, for example what is "STR" in your context?
02-09-2024 09:17 AM
Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial
02-09-2024 10:21 AM
@MinHolly ha scritto:
...
It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:
1616161610FF220000A75FF5Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.
You are probably sending the sequence "1616161610FF220000A75FF5" as a 24-characters ASCII string (that is, 24 bytes).
One way to prepare the frame is to build it as a U8 (unsigned byte) array, then typecast it to a string.
Please post your code so that we can help you more.
02-09-2024 12:17 PM
@MinHolly wrote:
Hello,
I've encountered an issue with my LabVIEW code. I'm attempting to communicate with an external device that requires serial communication. To achieve this, I've been utilizing the write/read functions. The frame I need to send is as follows:
00x16 00x16 00x16 00x16 00x10 00xFF 00x22 00x00 00x00 00xA7 00x5F 00xF5It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:
1616161610FF220000A75FF5Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.
I'm unsure how to resolve this issue. Has anyone encountered a similar problem?
Thank you for your help.
This is a common cause for confusion with the serial functions.
It sounds like you need to send a sequence of bytes. You can do that using this function: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/byte-array-to-string.html.
What you are probably doing is sending a ASCII encoded hex string rather than the actual hex values.
See attached.
02-10-2024 10:22 PM