LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with "Write to text file" VI

Solved!
Go to solution

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.

0 Kudos
Message 1 of 17
(1,515 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(1,509 Views)

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.

Message 3 of 17
(1,499 Views)
Solution
Accepted by topic author MaSta

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?

0 Kudos
Message 4 of 17
(1,435 Views)

@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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 17
(1,424 Views)

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.

0 Kudos
Message 6 of 17
(1,409 Views)

I need more coffee or some a tual code to figure out what you are seeing. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 17
(1,404 Views)

@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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 8 of 17
(1,394 Views)

@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.

0 Kudos
Message 9 of 17
(1,389 Views)

@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.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 10 of 17
(1,382 Views)