07-14-2011 10:34 AM
I want to communicate & query the serial device. I know the resource name & all other serial communication settings except baudrate. I have to try between two baud rates and select the appropriate one.
Consider the device baudrate is 9600. In the below code, the first iteration executes with the baudrate 19200 and the communication fails. Next it executes second iteration with the baudrate 9600 and then also it returns timeout error after VISA read. Why does it return error for the correct baudrate(9600)?
If I pass the baudrate array as [9600,19200], then it executes the first iteration with baudrate 9600 and returns the IDN response string without any error.
I couldn't understand why the above code doesn't communicate successfully for the second iteration. For the second iteration, it should actually communicate successfully since the baudrate is correct(9600)
Thanks,
Raja
07-14-2011 11:44 AM
Looks like it should work on cursery examination.
I would try a 2 sec delay after closing the Port.
IF that does not do it NI should explain why cause I'd ike to know too":)
07-14-2011 11:46 AM
SOrry I wasn't paying attention
Look at your loop conditional logic.
07-14-2011 11:13 PM
I also tried with a delay of 10secs after port closing. But it doesn't work.
@AKA_TG wrote:
SOrry I wasn't paying attention
Look at your loop conditional logic.
The conditional logic is to stop the loop when I get a response from the device. The actual baudrate is 9600.
With baudrate array[9600,19200], I get a response in the first iteration(9600) and the conditional loop stops. This is fine and it works as expected.
With baudrate array[19200,9600], the first iteration(19200) results in timeout error after VISA read. Yes, it should return error since the baudrate is wrong. Then it proceed with the second iteration(9600) and then also it returns timeout error. Here is the problem. Why does it return error for the correct baudrate?
Also I tried clearing the buffer before port closing. Nothing works.
Thanks,
Raja
07-15-2011 02:54 AM - edited 07-15-2011 02:57 AM
A stupid question, but I can't try since I don't have a device here:
Does VISA Close really close the device if there's an error? I strongly hope so, but probably you could try clearing the error before closing the VISA session.
EDIT: I just read in the help that it closes the session "regardless of whether an error occurred in a preceding operation". So that should not be the issue.
07-15-2011 05:27 AM
Yes I tried that too. Passed no error to VISA Close. Still the problem exists.
I tried few other methods
Method 1:
First with wrong baudrate, opened the port, sent query and closed after Timeout read error. Then stopped the VI
Secondly with correct baudrate, opened the port & sent the query. Now I get a proper response without error.
Method 2:
Here I combined the above two operation and executed without stopping the VI inbetween. ie., as in my previous post,
First with wrong baudrate, opened the port, sent query and closed after Timeout read error.
Then without stopping the VI, again tested with correct baudrate, opened the port & sent the query. Now also I get timeout error after VISA Read. Why?
From the above two methods, I could come to a conclusion that VISA Close does not completely release the port. Stopping the execution of VI seems to be releasing the port completely. So in the method-2, I have to produce similar condition equivalent to stopping the VI after wrong baudrate. How?
Thanks,
Raja
07-15-2011 05:56 AM - edited 07-15-2011 05:57 AM
So based on this I could think of a possible workaround:
Dynamically call a SubVI (VI Server) that opens the port and tries to communicate. If it fails, close the port (within the SubVI), return the error. On the top level VI close the VI reference to make sure the SubVI leaves memory. Then (if it failed) call the SubVI again with the next baud rate.
When the SubVI succeeds in communicating to the device it can return the VISA reference.
07-15-2011 07:27 AM
Hi,
Can you try use "Flush Buffer.vi" after open port?. I think the buffer have someone invalid data after use the wrong baud rate.
Best Regards,
07-25-2011 01:04 PM
Sorry to be so vague. I have seen stuff like this before with LabVIEW. In the end its usually someting other than what I suspect.
so I'll not pass judgement.
.
I think closing the port should be followe by a delay of up to 2 secs may be needed after releasing the resource
before making an attempt to enable it again.
If that does not work I sure am stumped.
.
06-03-2014 11:19 AM
I know this is an old thread, but I am having a similar issue where once the baud rate is incorrectly set, nothing will fix the problem except closing, restarting LabVIEW and the device.
Any suggestions or solutions to this problem?
Thanks
mcduff