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: 

Visa Serial interface problem

I am trying to read an array of string using the code as attached. I have an error with "scan from string" block every time I run the program. you can find sample of my data to be sent by my hardware to Labview as below

 

D10112.31D10212.31D10312.31D10412.31D10512.31D10612.31D10712.31\r\nCapture.PNG

 

0 Kudos
Message 1 of 14
(3,608 Views)

@Zahran88 wrote:

I am trying to read an array of string using the code as attached. I have an error with "scan from string" block every time I run the program. you can find sample of my data to be sent by my hardware to Labview as below

 

D10112.31D10212.31D10312.31D10412.31D10512.31D10612.31D10712.31\r\nCapture.PNG

 


Your code depends on the whole message being read at once, which I can guarantee you isn't happening the way you set up the serial read.  I wish NI would deprecate the example that uses Bytes at Port, because you are their latest victim.  You have termination characters, so make use of them by specifying that in your serial port setup!  And then get rid of the Bytes at Port.  Since you can only specify a single character to be the termination character, I would use the linefeed as the termination character so you read the entire message and then use Trim Whitespace to get rid of the carriage return.  Make sure that bytes to read is bigger than the biggest message you'll ever see.  LabVIEW is smart enough to only allocate what it needs.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 14
(3,568 Views)

Just get rid of the Bytes At Port and replace it was a constant.  After counting you bytes, I would use 100.  The idea is that the VISA Read will stop reading when the number of bytes you specify are read or a termination character is read, whichever comes first.  So you tell the VISA Read to read more than a full message and let the termination character end the read.  This way you always get the full message.  The default settings from the Configure Serial already match what you want.


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 3 of 14
(3,523 Views)

I think this one will not working with me (I tried before) as the number of data changing from time to time so I need something smart to do it without error massages ! 

0 Kudos
Message 4 of 14
(3,496 Views)

@Zahran88 wrote:

I think this one will not working with me (I tried before) as the number of data changing from time to time so I need something smart to do it without error massages ! 


I have no idea what you just said.  What didn't work for you?  Apparently what you tried before isn't the same or it would have worked.  The way I and cross had explained it, it *is* smart enough to do without errors.  As we both said, just set Bytes to Read to something bigger than the biggest message you'll ever see.

 

Other than that, I can't help any further until you show us that other thing that didn't work.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 14
(3,488 Views)

Thanks a lot for your assistance but your answer is not clear for me! could you please show me how can I solve the problem without changing data format ?

0 Kudos
Message 6 of 14
(3,487 Views)

Hi Zahran,

 

could you please show me how can I solve the problem without changing data format ?

As long as you don't attach cour VI we cannot edit and show the code…

 

Two steps:

- delete the BytesAtPort property node

- wire a "100" constant to the "bytes to read" input of VISARead…

 

One more suggestion:

Right click your thermometer/gauge indicators and show their numerical display. Then delete those additional indicators you use for the very same purpose…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 14
(3,485 Views)

As long as you don't attach cour VI we cannot edit and show the code…

 

I attached it. kindly refer to my first post attachment 

0 Kudos
Message 8 of 14
(3,480 Views)

Hi Zahran,

 

you only attached an image of your code.

You were asked to attach your VI before…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 14
(3,477 Views)

Smiley Happy I attached it really beleive me Smiley Embarassed  any way I attached it again hereCapture2.PNG

0 Kudos
Message 10 of 14
(3,474 Views)