‎08-27-2015 10:42 AM
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
‎08-27-2015 11:09 AM
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
‎08-27-2015 11:39 AM
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.
‎08-27-2015 11:45 AM
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.
‎08-27-2015 11:47 AM
@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.
‎08-27-2015 11:50 AM
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.
‎08-27-2015 11:52 AM
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
‎08-27-2015 12:12 PM
@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.
‎08-27-2015 12:30 PM
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.
‎08-27-2015 12:32 PM
@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