LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Select between different serial baud rates

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)?

 

Serial Baud Rate.png

 

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

 

 

0 Kudos
Message 1 of 11
(5,499 Views)

 

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":)

 

 

 

 

0 Kudos
Message 2 of 11
(5,486 Views)

 

 

SOrry I wasn't paying attention

 

Look at your loop conditional logic.

 

 

0 Kudos
Message 3 of 11
(5,482 Views)

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

 

 

0 Kudos
Message 4 of 11
(5,468 Views)

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.

0 Kudos
Message 5 of 11
(5,455 Views)

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

0 Kudos
Message 6 of 11
(5,444 Views)

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.

 

0 Kudos
Message 7 of 11
(5,439 Views)

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,

Luis A. Mata C.
Ing. Electrónico
Whatsapp: +58-414-1985579
BBM Pin: 2B83E99A
Thanks: Kudos
0 Kudos
Message 8 of 11
(5,427 Views)

 

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.

 

 

.

 

 

 

 

0 Kudos
Message 9 of 11
(5,378 Views)

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

0 Kudos
Message 10 of 11
(4,895 Views)