From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

ASCII Formatting Issue with Read text File and Sending to Visa Write function for RS232 comms

Solved!
Go to solution

Hello, 

 

I did some troubleshooting to check that my serial comm port was working correctly using a write buffer constant \040000\02AA>0\03\r using '\' Codes Display to send a command to the VISA write function block. As expected after running the simulation I received a hex response of 06 (ACK). This verified that Tx and Rx were operating as expected on the RS232 port.

 

Now that the sequence has been verified, I wish to perform the same operation using a text file (.txt) to send the exact same command. 

 

The issue I am having now is that I when I'm trying to send the exact same command \040000\02AA>0\03\r from a text file it is actually being sent as 0430\s3030\s3002\s4141\s3E30\s030D\s 

 

Therefore the sequence of the command will not enable for a response of 06 (ACK) to be received.

 

So the question is, how can the text file (.txt) be formatted in the same way as write buffer constant so that VISA Write will send the command in the correct format?

 

Many Thanks

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

I would just have the text file be the hex values.  Then your code does a Hex String To Number and then Byte Array To String to convert the data into the right format for sending the data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 17
(4,555 Views)

Hi Crossrulz, 

 

I attempted to follow your advice by implementing Hex String To Number and then Byte Array To String

 

When trying to implement Byte Array to String I seemed to have compatibility issues implementing it into the block diagram. 

 

I've actually included two separate VI's below to try to specify the problem exactly. 

 

The first VI reveals that the constant has no formatting issues and is read as it is supposed to be at the RS-232 port and provides the correct response. 

 

When trying to send the exact same command from a text file the formatting issue begins. I've tried searching in depth on how to resolve this.

 

All I want to achieve is for the text file to have the same formatting that is provided via the write buffer constant. 

 

Many Thanks

0 Kudos
Message 3 of 17
(4,516 Views)

Hi neunited,

 

make the display style indicator of your string constant visible. (This should ALWAYS be done!)

Then compare the display style of your string constant with the style of your "text" indicator…

 

When you want the exactly same result you should use the very same display style!

 

Best regards,
GerdW


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

Hi GerdW, 

 

I completely agree with you, I set the write buffer constant to '\' Codes Display which identifies the code correctly in the text box in the front panel. 

 

But how can the display style indicator be achieved with a text file? Sorry I might be missing your point here. 

 

Many Thanks

0 Kudos
Message 5 of 17
(4,505 Views)

Hi neunited,

 

the point is: you are comparing apples with oranges when you don't use the same display style in those different places…

 

Either edit your "text" file to have the same content as your string constant - or you need to convert as has been suggested before! (Keep in mind: a "text" file is just a collection of bytes in a file with a filename suffix of "txt"…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 17
(4,502 Views)

If you want the text into the file to have the \ Codes Display or Hex Display formatting, you can load its content into a string control or indicator featuring the very same display format. The control/indicator value will be the desired string.

 

string_example.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 7 of 17
(4,498 Views)

Hi Paolo, 

 

What is the name of the function you used in String 1 (between the controls) please? 

 

Many Thanks, 

Neunited

0 Kudos
Message 8 of 17
(4,480 Views)

It's a property node…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 17
(4,476 Views)
Solution
Accepted by topic author neunited

Every LV "object" (controls and indicators, but also the Application and the Vi themselves, and others too) feature its own set of Properties (attributes) and Methods (functions). You can use a Property e.g. right-clicking on a control on the FP or its terminal on the BD, then selecting Create -> Property node -> ... You can find more information in the LabVIEW help.

Property nodes (and Invoke nodes for calling Methods) are very useful and practically unavoidable to write a good LabVIEW program in most applications (with some caution if you need very high performance).

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 10 of 17
(4,472 Views)