03-15-2022 11:45 AM
Hi
Sorry for what it seems a basic question (I am an amateur in bytes and stuff).
I read some info from an instrument through a TCP Visa connection. Data is read either as Ascii or Bin as follows
To distinguish between ASCII command and binary data from the instrument each data block is transmitted in the following format:
0 1 2 3 4…Len+4
TypeHi TypeLo LenHi LenLo Data
LenHi, LenLo contain length of the Data part of the message, TypeHi, TypeLo determine the type:
• TypeHi = 55h, TypeLo = AAh – ASCII command, Data part of the message contains the ASCII string
(transferred string is not terminated by CR!).
• TypeHi = 66h, TypeLo = BBh – binary command, Data part of the message contains the binary
stream data.
I have difficulties in reading these. an exemple of what I tryin (without success) is attached here (not of much use but it gives an exemple of what the instrumet sends back).
Thanks for help
Solved! Go to Solution.
03-15-2022 11:54 AM
Looks like the numbers are formatted as comma delimited decimal integers in the string, not flat binary. What values do you expect for your example string?
03-15-2022 11:59 AM
The string received should be something like PRESNC:-412,-412 but includes a header marker like "55AA" for a ASCII and two bytes stating the length of the string submitted.
03-15-2022 12:07 PM
In the doc I have this, but as I am noob, I don't know how to handle it :
03-15-2022 12:13 PM - edited 03-15-2022 12:14 PM
What you should do is read 4 bytes. You can use the Unflatten From String to get the data type and the data length from those 4 bytes. You then read the number of bytes stated in the data length. You can then parse the data based on the data type.
03-15-2022 12:17 PM
Start with something like this (you can easily add more cases, one for each header type):
03-15-2022 12:18 PM
Hi
Thanks, can you post it as LV 2020 or below ? (sirry, I am not up to date !)
regards
03-15-2022 12:29 PM - edited 03-15-2022 12:33 PM
Here's my version of Tim's above. I definitely would not make 55AA the default case, of course.
As I mentioned:
03-15-2022 12:40 PM
Hi
thanks, it works. I just wonder how to read the other possibility with the 66BB in which the number of values is variable (I can not make a "variable" cluster...). anyway, thanks, I will try to figure it out.
Another problem I have : how to mark 2 solutions in this forum ?
regards
03-15-2022 12:43 PM - edited 03-15-2022 12:54 PM