Showing results for 
Search instead for 
Did you mean: 

How Does Serial Port Works

Hi everyone,

I have been working for some months with LabVIEW in order to develop an application to control a SCORBOT ER-IX.

For those who don't know, this SCORBOT has a controller-B and is programmed trough serial port with ACL. It also has a software called ATS (Advanced Terminal Server) to send programs to the controller and others useful functions.

A part of my work consist in communicate a LabVIEW script with the SCORBOT. I have already ended this part, and then I am going to work in the machine vision part to analyze images from a camera and send the SCORBOT the positions and orders to make determinated orders.

The reason for this message is that some months ago I used the VISA library to manipulate serial port. It's very easy to do because of the simple operations, but the behaviour of the data sending and reception wasn't appropiate.

In these days, I obtained a solution that allowed me sending commands to the robot and receive it's response. The SCORBOT worked fine, it executed the instructions properly, but the response was always quite strange because the echo and the response were mixed.

I couldn't understand why that was happening. Hyperterminal works fine, but my LabVIEW code doesn't and is a very simple thing.

At last I put a serial port reader that looked for data in every iteration of a for loop.

The problem of that was the imposibility of knowing when the controller and/or robot have finished an instruction and were ready to receive more. I only get an script to send orders, but sending lists of them, waiting for the previous before sending the next, wasn't possible.

After some tests with serial port sniffer, hyperterminal, LabVIEW, ... I discovered that SCORBOT need instructions to be send byte to byte and when he receives the '\r' char executes the command. SCORBOT needs also some time to process each byte, so I have to wait (for the moment, 10ms).

I tried to write byte to byte in the serial port with VISA functions, but that doesn't work. I guess there maybe some internal buffers, so the data is send when they are full...

At last, I solve the problem using an Active X, mscomm.ocx and invoking the functions on it, but I wonder if is possible to do that with the VISA library, and if not, I think is a thing to look at for new versions.

I think VISA could be an easier way to do those things, but for the moment is not accurate or I don't know how to do that.

Thanks to everyone.

PS: I have my working code, so if anyone need to take a look on it, tell me.
Message 1 of 15
I'm trying to understand what you are asking for. Are you saying that you tried sending the \r and it didn't work with VISA? If that's the case, did you send the characters '\' and 'r' or the actual control code. In order to include the control code in a LabVIEW string control or constant, you have to right click and select '\' Codes Display. If you don't do that, then you won't be sending it correctly. The other way to do it is to use the concantanate to string function and use the Carriage Return constant on the string pallete.
0 Kudos
Message 2 of 15

No, that's not what I'm asking for.

See, If I want to send, for example, the string:"open", I append the "\r" and get:"open\r" (I use the \r constant, so no problem with that). The problem is that the bytes are needed to be send one by one to the controller, and when I try to do that with the VISA function "write on serial port" it don't works as I need: The controller's response is mixed with the command echo and the result of it's execution and some times the end of response ("\n\r>") is lost too, wich provokes infinite loops if I wait until that string indicating end of response arrives.

What I need is send a command and wait until is finished to send the next, so the controller won't be overflowed. For the same reason I need to send the commands byte to byte.

When trying to do that with VISA it seems as if there were a buffer and it's content is not send until it's full, so I can't send bytes one by one waiting for the controller to read actual byte before sending the next.

I solved this with an ActiveX using the same kind of functions as in VISA and works, but I think it maybe solved with VISA too, and in an esaier way.

I have already solve the problem with that solution, but I have curiosity about that and the reason wich the VISA solution doesn't works.

If you think it maybe useful I can post the VI with the ActiveX, or an image of this, so you can see how it works.


Mensaje editado por Juanjo Vega

0 Kudos
Message 3 of 15
Hello Juanjo,
to make sure all data is sent you can set in the context menu of the VISA write function the synchronous I/O mode to synchronous. This lets the VISA writefinish only after sending all data. If set to asynchronous (default) the function returns immediately after writing the data to the transmit buffer, leaving the rest to the VISA driver. Maybe this could be the solution to your problem.
But when set to asynchronous it should work too by reading the serial interface continuously until the expected answer is received. See the attached BD picture.
Greets, Dave

Message Edited by daveTW on 02-03-2007 03:41 PM

Greets, Dave
0 Kudos
Message 4 of 15

Here's another thring to try. With something like this, you can send a string with a delay between each character.

Message Edited by Dennis Knutson on 02-03-2007 09:02 AM

0 Kudos
Message 5 of 15
Hi again, thanks to all of you. That's looks more like I'm looking for.

It's saturday nigth in Spain, so I can't test your ideas until monday, so I'm going to develop them and I'll test them on monday. When I'll do and I'll post here the results.

I'm not sure if is essential to write bytes one to one, the problem maybe the synchronous/asynchronous mode.

I thought something like that, but wasn't able to solve even after looking at MAX. I tought the default configuration or MAX one maybe interfering and gessed that I could configure at MAX, but didn't find any solution for this. I'll take a look again to that.

By the way, that's my Active X solution. The first for loop is to write chars one by one in the port. The second loop, while, is to read chars from port until "\n\r>" arrives (that's the way as controller-B notifies the end of response arriving, with a ">" in a new line).

As you can see, is very simple, but I'd like to know if that behaviour can be imited with VISA.

Mensaje editado por Juanjo Vega

Mensaje editado por Juanjo Vega

Mensaje editado por Juanjo Vega

Mensaje editado por Juanjo Vega

Mensaje editado por Juanjo Vega

0 Kudos
Message 6 of 15
Hi everyone, I have found the problem with serial port Smiley Very Happy

The reason why port dind't work properly is the synchronous/asynchronous mode. Just right-click over the Write and/or Read block, select "Do synchronous I/O" and all working fine.

The LabVIEW code is exactly as I posted above.

Thanks to everyone!!, Mission Accomplised!! Smiley Wink
0 Kudos
Message 7 of 15
Interesting story, thank you for sharing!
0 Kudos
Message 8 of 15
Sorry, the final code is not exactly the above one.

Here it is.

Hope to be useful.

Best Regards!!

Mensaje editado por Juanjo Vega

0 Kudos
Message 9 of 15
It looks very reasonable Smiley Very Happy
Greets, dave

Message Edited by daveTW on 02-05-2007 09:35 PM

Greets, Dave
0 Kudos
Message 10 of 15