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.
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.
09-19-2011 11:07 AM
The termination character can be set via the configure port VI. There are optional inputs on it to enable the termination character and what the character is. The default is to have it enabled and the default termination character is a new line '0x0A'. I suspect that the data being returned from your device has a new line in it which is causing your read to terminate on that character, not the full 34 bytes requested. Try changing the termination character (wire a U8 constant with a value of 0x5A) and see if that resolves your problems.
09-20-2011 03:08 AM
Thanks again.
I have tried wiring the 0x5A constant to the VISA configure VI. The problem now seems to be, however, that anytime it encounters 0x5A, it stops reading, so the short read string happens more often. From this, I assume that the termination character input in the VISA Configure VI has preference over the byte count input in the VISA Read VI, right? Is there a way to reverse this, or the termination character, be it 0x5A or the default 'new line', has always preference?
Thanks a lot,
Gabriel
09-20-2011 04:55 AM
@gabrielcasano wrote:
Thanks.
So, just to make sure I undertand correctly, if I wire 'error out' from VISA Write to 'error in (no error)' from VISA Read, it means VISA Read always executes once VISA Write has executed correctly?
Exactly. Since Visa Read needs the output from Visa Write as input, it must wait.
Often you want a small wait in between, which is one of the few instances where you need a sequence or express vi. Since Wait doesn't have error in/out you'll need to put it in a sequence and run the error wire through it.
/Y
09-20-2011 06:15 AM
Thanks everyone.
OK, so I have been reading about this whole quite a lot, and thought I had figured it out, but no luck yet, so I hope you guys can help me. Below is a detail of the new VIs I have implemented. I have added the small time delay and also a property node. In the property node I added 'End mode for Read', changed it to write and set it to (0) None. According to Labview Help, (0) None means 'The read does not terminate until all of the requested data is received (or an error occurs)'. So my understanding of this is that it should always wait for the 34 bytes to come in. However, it keeps reading a short string sometimes. For instance, this is the last one I caught:
A52E CDEF 4140 C9EF 4119 01BF 41E8 0048 420A
This one is 18 bytes long, but they vary in length. One thing I also noticed is that the last byte is always 0x0A (regardless of the string length).
Any ideas of why this could be happening? Am I connecting something wrong?
Thanks very much
09-20-2011 06:16 AM
Sorry, forgot the attachment
09-20-2011 09:30 AM
I would have to say that you did not properly change the termination character for the VISA read. Try wiring it to the VISA Init that you use after you open the connection. If that still gives you problems I would disable th eread until termination character and always read 34 bytes. Validate the response by checking that the last character is 0x5A.
09-20-2011 11:15 AM
Thanks.
I am not sure I understand the explanation. I have tried wiring both 0x5A and nothing (so 0x0A, since it's the default) to the termination character input in the VISA Configure Serial Port VI. In both cases, no matter whether I set the End mode for Read property to (0)None or (2)Term. char, the string crops when it finds the respective termination character. So what I wonder is what the difference between (0None and (2)Term. char really is and what 'reading until all the requested data is received' means.
In terms of disabling the read until the termination character and always reading 34 bytes, I don't know how that would be done, but I would like to do it. In fact, what I would really like to do is to always read 34 bytes, or if not, get the first byte (0xA5), read 32 more, and then check if the 34th is 0x5A.
Sorry for the rumbling, and I appreciate the help.
09-20-2011 02:05 PM
Where is your serial configure VI?
That is where you should be disabling or enabling the termination character and defining what the character is. Then you won't need to add a VISA property node in the middle of execution to change the read mode.
09-20-2011 06:55 PM
If the short stringalways ends with 0A, that is because the termination character is enabled and set to its default value, 0A. You need to disable the termination character. Don't worry about changing it, just disable it. Do this by wiring a False constant to the "Enable Termination Character (T)" input to the VISA Serial Configuration VI. See the picture below.
09-20-2011 07:41 PM
Doesn't this sound familiar. I have done a lot of work with serial input and output. Setting the termination character enable to false never used to be enough, so I loaded my LabVIEW 2010 and looked at the context help for the Serial Settings property node: End Mode for Reads. here is what it says:
I learned back in LabVIEW 5.1 that setting the Termination Character Enable to False did not work as advertised. There is more work to be done. After setting this property node, reading 34 bytes from the serial port should work well.
You can also read the number of bytes at the serial port if you want to check how many bytes have come in.
Rob