LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview program working in highlight mode and not working in normal mode

Solved!
Go to solution

Hi all,

 

With all your suggestions I have made many modifications my code is working with use of proper delays...

 

Thankyou

0 Kudos
Message 11 of 22
(1,920 Views)

@rolfk wrote:

@Deepthi23 wrote:

Thankyou somuch @Daikataro

 

I have tried out the code you have posted. It is working fine in the Highlight mode as before but showing a wrong resourcename as out put and not reading 's' in the normal

 

 

And again my pet topic about VISA communication: DO NOT USE "Bytes at Serial Port" EVER. It is in 99.9% of the cases not only not necessary but even outright wrong! If you believe it is necessary think again, chances are almost 100% that you are wrong especially if you haven't already written a few 100 instrument drivers in LabVIEW or even just using VISA.


This post sparked my curiousity becuase I have used that property more than once.

 

For those very old-school widgets that would drive a dot-matrix printer and used a CR LF termination I was able to pick-up in the middle of the device being connected to a serial port (first packet is generally corrupted or malformed) search until I find teh CR LF and then syncronize with the incoming data stream.

 

Many on those old devices did not accept commands but would just start spewing serial message to print on the printer.

 

I am curious why you have such a strong opinion about checking the number of bytes waiting at the serail port and reading as many as are indicated.

 

Just curious,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 22
(1,893 Views)

I think there are times that it can be used, and the case you point out is one of them. Although you talk about looking for the line feed character, I think you'd be better off using the termination character, asking for a ridiculously large number of bytes and let it end when you receive it.

 

When you go and get everything that is there, are careful about parsing your data and storing previously gathered bytes in a shift register until you use them or discard them, and don't have a termination character to help you frame the messages.  Bytes at Port is fine.

 

The problem is that the Serial Port examples that NI provides, and is the first thing everyone goes to, uses it, and that becomes the framework everyone's VI starts with.  But the example shouldn't use it because the examples are on a command/response setup.  Not a "let me get everything that the device spews unprompted."

 

The command/response example is a good one to start with as most modern serial applications work that way.  And if they are using a termination character (which the NI examples configure the serial port for) then there is no need to ever use the bytes at port method.

 

My issues with bytes are port are that you rarely need it, the NI examples use it, and those examples are for a weird hybrid of commands that are never quite right for any specific real world situation.

 

In the end, you wind up with messages like this one start out where newbies who don't understand serial communication use the examples, then can't figure out why their code isn't working.

0 Kudos
Message 13 of 22
(1,887 Views)

@Ben wrote:

I am curious why you have such a strong opinion about checking the number of bytes waiting at the serail port and reading as many as are indicated.


Because you will miss parts of messages unless you wait a LONG time.  Most instruments use the CR as the marker that the message has ended.  So just save yourself a lot of headache and just let VISA handle searching for it for you.  You will now know that you got the entire message and you can process it.

 

Yes, for instruments that just stream data in this format, the first message will likely be trancated.  But you can handle that at the point of connection (do a read and do nothing with the data).  From there, just let the termination character determine when a message has ended and take care of it.

 

But where I do like to use the Bytes At Port is just for checking if a message has even started, like I showed earlier.  But the Bytes At Port is not used to tell the VISA Read how many bytes to read, otherwise we would be back to the original issue.  If there is a termination character, use it!

 

This is valid for ASCII messaging (you can read the raw serial data in a text file).  For binary messaging, then you need to be smarter (like read 1 byte at a time until you find the message start byte, then read the message type byte, then read then number of samples needed for the rest of the message, perform CRC/checksum validation where applicable).

 

I have plans for a series of nuggets for serial port communications.  I need to work on those again for reasons just like this...


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
Message 14 of 22
(1,884 Views)

@Ben wrote:

For those very old-school widgets that would drive a dot-matrix printer and used a CR LF termination I was able to pick-up in the middle of the device being connected to a serial port (first packet is generally corrupted or malformed) search until I find teh CR LF and then syncronize with the incoming data stream.

Many on those old devices did not accept commands but would just start spewing serial message to print on the printer.

I am curious why you have such a strong opinion about checking the number of bytes waiting at the serail port and reading as many as are indicated.

Just curious,

Ben


As others have pointed out, if you have a termination character you really shouldn't need Bytes At Serial Port (BASP) at all. You simply start of reading data and the first packet you may have to verify to be a full packet and after that you can sit back and let VISA do all the work!

 

I can see some usefullness in using BASP to check if there is any data available and if not go to do other things rather than letting VISA Read block the thread, although it is in most cases not really a problem to have a thread blocked by VISA Read as LabVIEW has more threads available and doing other things in the same code module often is rather violating the isolation of code responsibility.

 

For full binary protocols with no common termination character BASP is an option although it makes the protocol handling not really easier, it just exchanges some of the complexity for other complexity.

 

The only case where BASP is really undispensable is when you want to implement a terminal like UI. There you don't care about partial data blocks as all you do is dump it on a screen and let the user do the decoding Smiley Very Happy .

 

Humans are pretty good at that sort of task to recognize patterns easily and that is what people struggle to understand when trying to implement a reliable device driver. What seems intuitively trivial to do as we simply do it without much effort proofs to be pretty hard to do when you need to put it into formalized programming instructions Smiley Tongue

Rolf Kalbermatter
My Blog
Message 15 of 22
(1,868 Views)

@rolfk wrote:

I can see some usefullness in using BASP to check if there is any data available and if not go to do other things rather than letting VISA Read block the thread, although it is in most cases not really a problem to have a thread blocked by VISA Read as LabVIEW has more threads available and doing other things in the same code module often is rather violating the isolation of code responsibility.


Just to play Devil's Advocate...

I had an instrument that only sent data over the serial port when something changed.  I initially just let the timeout do its job of waiting for data and let it do the waiting.  But I actually ran into the race condition where I only got part of my message since the message was sent right when the timeout was expiring.

 

Yes, this is a rare situation.  But it does happen.  So for any type of slow streaming (like 200+ ms/sample) or randomly sending data instruments, I always first check to see if there is anything in the port first.  If there is, I read my entire message.  If there is no data at the port, I throw in a wait (usually).


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 16 of 22
(1,852 Views)

@crossrulz wrote:

@rolfk wrote:

I can see some usefullness in using BASP to check if there is any data available and if not go to do other things rather than letting VISA Read block the thread, although it is in most cases not really a problem to have a thread blocked by VISA Read as LabVIEW has more threads available and doing other things in the same code module often is rather violating the isolation of code responsibility.


Just to play Devil's Advocate...

I had an instrument that only sent data over the serial port when something changed.  I initially just let the timeout do its job of waiting for data and let it do the waiting.  But I actually ran into the race condition where I only got part of my message since the message was sent right when the timeout was expiring.

 

Yes, this is a rare situation.  But it does happen.  So for any type of slow streaming (like 200+ ms/sample) or randomly sending data instruments, I always first check to see if there is anything in the port first.  If there is, I read my entire message.  If there is no data at the port, I throw in a wait (usually).


Well, what you describe is a very rare situation. I have come across devices which just squirt data without ever being commanded to do so (GPS devices being one class of them), but not in random intervals. And I would guess that about 95% of the devices I have interfaced so far are fully command-response based.

 

These rare beasts do IMHO not warrant to use the BASP function for simple basic examples that only confuse new users into thinking they need to use this function for every communication they will run into. I will maintain my stance that BASP is the wrong solution in just about every possible case a new LabVIEW and/or VISA user is ever likely to encounter.

Rolf Kalbermatter
My Blog
Message 17 of 22
(1,812 Views)

rolfk wrote:  And I would guess that about 95% of the devices I have interfaced so far are fully command-response based.

I would say about 90% of the devices I have interfaced with are also command-response, SCPI/ASCII based (I recently ran into several custom instruments that stream data).  And I fully agree that the BASP should NOT be used for those.  And NI really needs to do some cleaning up of the serial port examples.  And by cleaning up, I actually mean to make more.  There should be an example for a standard SCPI/ASCII command-response interface and another for a streaming ASCII data interface (constantly read with the occasionally write).  I could argue similar for binary interfaces, but that could get complicated since you really need to know the protocol.


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
Message 18 of 22
(1,795 Views)

@rolfk wrote:

...
. I will maintain my stance that BASP is the wrong solution in just about every possible case a new LabVIEW and/or VISA user is ever likely to encounter.

Agreed.

 

Thank you for the clarification.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 19 of 22
(1,785 Views)

good day

 

I have a question...related

 

When i have a vi executing in labview it allow me to created new files (csv) recording a comm lecture, but as an executable it does not work properly.

 

Do you know why ???

0 Kudos
Message 20 of 22
(1,766 Views)