LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Flush I/O Buffer doesn't work on my Serial Write and Read VI

Hello,

 

I've been working on a serial interface .vi that communicate with simple GPRS/3G modems via AT commands.
This VI is working very well except when its used repeatedly:

Even if I use "VISA Flush I/O  Buffer" or "VISA Clear" or clear the "Response" control string, the VISA Read keeps delivering the response concatenated after previous responses. Can you spot the bug in my VI? 

 

 

 

AT_serial.png

 

 

 I've had searched this forum for smiliar topics, but none of them were related. 

Thanks,

Antonio

Download All
0 Kudos
Message 1 of 6
(4,698 Views)

I can't spot the bug becasue the picture is too small and blurry to look at.

 

Can you attach the actual VI?

0 Kudos
Message 2 of 6
(4,693 Views)

Sorry! I thought I knew how to insert a Vi snippet Smiley Tongue

I added the serialcore.vi and the other two subVIs: one for pattern matching and other for Error handling.

0 Kudos
Message 3 of 6
(4,674 Views)

You are going to keep seeing previous messages because you are storing them in a string in the feedback node.  It doesn't matter what you do with the serial port or its buffer, you've created your own buffer with the feedback node.

 

Why are you using VISA events?  I don't find them very commonly used, and I don't see where you are using them anywhere else.

 

Why are you using Bytes at Port?  I don't see where you are controlling the speed of your loop, so you probably wind up reading the serial port a byte at a time or something like that.

 

Where are you sending your commands?

 

Why don't you use the termination character to determine when to stop reading on a VISA read so it will responde quickly, but guarnatee you get a complete message.

Message 4 of 6
(4,650 Views)

RavensFan escreveu:

You are going to keep seeing previous messages because you are storing them in a string in the feedback node.  It doesn't matter what you do with the serial port or its buffer, you've created your own buffer with the feedback node.

 


Well... and it's working fine! Thank you very much RavensFan!

I started develloping this code as my first steps into Labview, and it's based on previous and bad programmed serial.vi that my coworker had done.
Right now, I have less than 3 months of LV experience and, believe it or not, I'm the company's specialist. Smiley LOL

It's hard to solve all these little bugs! 


 

Why are you using VISA events?  I don't find them very commonly used, and I don't see where you are using them anywhere else.

 

Why are you using Bytes at Port?  I don't see where you are controlling the speed of your loop, so you probably wind up reading the serial port a byte at a time or something like that.

 

Where are you sending your commands?

 

Why don't you use the termination character to determine when to stop reading on a VISA read so it will responde quickly, but guarnatee you get a complete message.



I used VISA events because I wanted to get rid of the constant "wait for X ms" function between read and write. This way I read the answer at the time it arrived. I can't remember why I used Bytes at Port, probably because the program required it. I got to take a look on this later.

The commands are sent through the Command control.

And about using the termination character, It's not garanteed that the device will always respond with a termination character. But I will talk again with the hardware team about this.


Again, thank you!

0 Kudos
Message 5 of 6
(4,560 Views)
@antonioluppi wrote:

And about using the termination character, It's not garanteed that the device will always respond with a termination character. But I will talk again with the hardware team about this.
Again, thank you!


As stated by RavensFan YOUR code is concatenating the previous responses. Get rid of the feedback node and just read in the whole line up to the termination character.

 

The key here is Termination Character

 

Don't use Bytes at Port. There are tons of posts on this forums about NOT using Bytes at Port. I wish NI would get rid of the example serial code that uses it.

 

There are also tons of posts on this forums talking about how to use Termination Character. Set the timeout to something longer than you need and setting the bytes to read to something larger than what you expect. Then the VISA Read will just wait reading in all the stuff up to and including the termination character. ONE LINE AT A TIME.

 

But if you do not have any control over getting a Termination Character ("talk again with the hardware team about this") then you can adjust the timeout "on the fly" to detect when your modem is done.

 

 

Omar
0 Kudos
Message 6 of 6
(4,541 Views)