08-15-2023 08:32 AM
Good day!
The said VI is supposed to write strings or arrays of string line by line into a file. In my case one string per loop iteration. The VI help doesn't make it clear whether it would add an EOL/CR character also to string, only mentions arrays. As it seems it doesn't and the result wouldn't then be one string per line. Anyway, this can be fixed.
What I can't seem to fix is a truncation that occurs when writing strings, not hex strings, which represent hexadecimal bytes. The string, a ModBus message, would be truncated after 0A which in the string of course isn't 0xA, but 0x30 0x41. Example from the file:
00 03 02 0B 5D 43 4D
00 03 02 0B 5D 43 4D
00 03 02 0B 5D 43 4D
00 03 02 0A
00 03 02 0A
00 03 02 09 9A 03 BF
00 03 02 09 9A 03 BF
I verified that the string with 0A in the middle is complete before passed to the VI. The VI doesn't offer switches and I can't seem to find an alternative for writing strings into a text file. Is this truncation a bug or intended? Any suggestions? TIA.
Solved! Go to Solution.
08-15-2023 08:44 AM - edited 08-15-2023 08:44 AM
Hi MaSta,
you forgot to attach an example VI…
@MaSta wrote:
What I can't seem to fix is a truncation that occurs when writing strings, not hex strings, which represent hexadecimal bytes. The string, a ModBus message, would be truncated after 0A which in the string of course isn't 0xA, but 0x30 0x41. Example from the file:
00 03 02 0B 5D 43 4D
00 03 02 0B 5D 43 4D
00 03 02 0B 5D 43 4D
00 03 02 0A
00 03 02 0A
00 03 02 09 9A 03 BF
00 03 02 09 9A 03 BF
For me it works as expected:
So what are you doing differently?
08-15-2023 08:54 AM
I think I fell for this again, because it's not the first time. Damn! You don't think of that first.
It's not the VI writing the text, it's the VISA Read VI that truncates the message after having received 0xA.
I didn't configure the VISA session accordingly.
08-16-2023 07:25 AM
Addition: found this https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019MOvSAM&l=en-US
This is, once again in my understanding, the weird logic of LabVIEW. Those are serial settings, but the termination would also occur when using Ethernet... How is anybody supposed to know that?
08-16-2023 08:04 AM - edited 08-16-2023 08:07 AM
@MaSta wrote:
Addition: found this https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019MOvSAM&l=en-US
This is, once again in my understanding, the weird logic of LabVIEW. Those are serial settings, but the termination would also occur when using Ethernet... How is anybody supposed to know that?
Look at the Warning out of the VISA Read function that tells you straight up that the termination character was found and more data may be available.
Stop swearing at yourself now.
08-16-2023 08:58 AM
I'm confused. I had added code to record the actual messages which, buy adding the serial property "ASRL End En" set to "None", would not be truncated anymore. However, if I remove "ASRL End En" for a test again and the message truncates, the return code of VISA Read would be zero with an empty source string. No warning.
08-16-2023 09:12 AM - edited 08-16-2023 09:15 AM
I need more coffee ☕ or some a tual code to figure out what you are seeing.
08-16-2023 09:23 AM
@MaSta wrote:
Addition: found this https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019MOvSAM&l=en-US
This is, once again in my understanding, the weird logic of LabVIEW. Those are serial settings, but the termination would also occur when using Ethernet... How is anybody supposed to know that?
VISA being intended for Instruments, I believe it would be the manufacturer's responsibility to ensure the termination character is not part of the data or use a term char that is not part of the data.
On the other hand, if it is regular old TCP/IP you could use those functions and not the VISA functions.
08-16-2023 09:42 AM
@santo_13 wrote:
VISA being intended for Instruments, I believe it would be the manufacturer's responsibility to ensure the termination character is not part of the data or use a term char that is not part of the data.
Binary data is sometimes transmitted over VISA, e.g., a data stream from an oscilloscope. Here you can have termination characters mixed in.
08-16-2023 10:08 AM
@mcduff wrote:
@santo_13 wrote:
VISA being intended for Instruments, I believe it would be the manufacturer's responsibility to ensure the termination character is not part of the data or use a term char that is not part of the data.Binary data is sometimes transmitted over VISA, e.g., a data stream from an oscilloscope. Here you can have termination characters mixed in.
In such scenarios, you tend to disable termination and read specific number of bytes given by the header.