LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

want to use visa read only when bits are at the port

Solved!
Go to solution

Thanks for the feeback Crossrulz,

 

So even with a termination character you lose data in the situation youre describing?  This similar to the situation im in as well, im not quite sure when the data will come through and there is a chance that i will lose data. 

 

Using a visa read with termination character, if say half your ASCII data came through, would it; A) discard the data that was read before the timeout, B) Truncate the data to data read before and data read after the timeout, C) simply not read in the data and grab all the data until the termination character on the next read?

 

Thanks,

Matt



-Matt
0 Kudos
Message 21 of 34
(1,505 Views)

I believe the answer is B. When you do another read that data will come out.

 

You can do something similar to the GeneralSerialIO vi I posted. Check bytes at port, keep checking until two consecutive bytes at port queries give you the same answer. (Of course you need a delay in there, I use 50 ms). At this point I've found it safe to assume that all of the response is there.

 

Cheers,

mcduff

 

 

0 Kudos
Message 22 of 34
(1,498 Views)

matt198717 wrote:

Using a visa read with termination character, if say half your ASCII data came through, would it; A) discard the data that was read before the timeout, B) Truncate the data to data read before and data read after the timeout, C) simply not read in the data and grab all the data until the termination character on the next read?


A mix of B and C.  In the timeout situation, you would get the data that has come in so far and then the next read you will get the rest of the message (ending at the termination character).  And, yes, I actually had this happen to me.  It is a once in a million thing.  But that is too often for the application I was in.

 

So to reiterate: you want to use the Bytes At Port to see if ANY of your message has come in (more than 0 bytes at the port).  If part of your message is there, then the rest will come in soon enough that the VISA Read will not timeout and will return your entire message, ending with the termination character.


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 23 of 34
(1,491 Views)
Solution
Accepted by topic author Wolleee

By the way, here is an example I put together for another thread.

Note: I have a 10ms wait in the "0" case so that the loop does not become greedy.


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 24 of 34
(1,486 Views)

@crossrulz wrote:

matt198717 wrote:

Using a visa read with termination character, if say half your ASCII data came through, would it; A) discard the data that was read before the timeout, B) Truncate the data to data read before and data read after the timeout, C) simply not read in the data and grab all the data until the termination character on the next read?


A mix of B and C.  In the timeout situation, you would get the data that has come in so far and then the next read you will get the rest of the message (ending at the termination character).  And, yes, I actually had this happen to me.  It is a once in a million thing.  But that is too often for the application I was in.

 

So to reiterate: you want to use the Bytes At Port to see if ANY of your message has come in (more than 0 bytes at the port).  If part of your message is there, then the rest will come in soon enough that the VISA Read will not timeout and will return your entire message, ending with the termination character.


That makes complete sense actually.  In example the first byte is is noticed by the bytes at port, then give the visa read a timeout that in worst case scenario would give enough time for all the bytes from the beginning byte to the termination character to be transmitted. 

 

I think thats what i was looking for.

 

THank you.



-Matt
0 Kudos
Message 25 of 34
(1,484 Views)

I feel like this should be an example they ship with labview or something that is documented.  Like a best practises for serial communication in labview.



-Matt
Message 26 of 34
(1,478 Views)

While that may not be the best example, partly becase it is a relatively rare scenario, I agree that they need to better document the examples to explain when Bytes at Port is appropriate and when it is not.

 

Lynn

0 Kudos
Message 27 of 34
(1,471 Views)

@matt198717 wrote:

I feel like this should be an example they ship with labview or something that is documented.  Like a best practises for serial communication in labview.


Don't get me started on the examples NI has for serial communications.  The problem with the example is that there is only one and they do a horrible job of explaining all of the options that need to be to get your setup right.  They really should have several examples, each of a special circumstance: ASCII Data Stream, ASCII Command and Response, Binary Data Stream, Spurious ASCII Data Message.


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 28 of 34
(1,455 Views)

I completelely agree.  I would say labview is hugely used for serial communication as well.  Getting back to the mention of the producer consumer loop? You brought that up because the example i posted had a section for analyzing the data, and you think i should just be using a general producer consumer? I think ill implemant that as well.



-Matt
0 Kudos
Message 29 of 34
(1,447 Views)

@johnsold wrote:

While that may not be the best example, partly becase it is a relatively rare scenario, I agree that they need to better document the examples to explain when Bytes at Port is appropriate and when it is not.

 

Lynn


Lynn,

 

 even if it is a rare scenario i think that you should always be using best practises or at least be made aware of them.  Serial communication is so widely used

 

Matt



-Matt
0 Kudos
Message 30 of 34
(1,444 Views)