LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Another serial port related question

Hi
I am fairly new to Labview. I have been trying to communicate with a Roboteq controller to control the speed of a marine thruster. The serial settings of the controller are 9600 bauds, 7 data bits, even parity and a \r as the termination character.
 
The controller recognizes some specific commands and replies back with an answer. One of the command I am using is ?z\r. The controller should respond to it by sending an echo of the command followed by two other lines to successive read operations. It should look something like this
 
First read reply             ?z\r
Second read reply        00\r
Third read reply            00\r
 
I have done this with Matlab without having any trouble. I have even tried to use the measurement and automation explorer which seems to work fine i.e. when I click execute the first time, it replies with a ?z\r, second time with a 00\r and third time also with a 00\r.
 
The problem I am having is that the controller is responding with an echo i.e. ?z\r after the first read operation, however, when I read it again, it doesnt show any data. I have tried to automate the process by running the while loop 3 times but to no avail.
 
I have attached the program.
 
Any help/suggestions will be greatly appreciated.
 
Thanks
Message 1 of 10
(3,408 Views)

There is no attachment, try again.

If you are getting the first expected reply, it sounds like the link is good.  It could be the way you process the incoming data.  00\r may not show up as a printable character.  Try type casting to a U8 or U16 to see what arrives.

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 10
(3,397 Views)
I assume that you are using a \ codes display to look at the feedback (otherwise \r is just a carriage return). Can you look at the number of characters that were returned? Is it just 4 (?z\r) or is it returning more characters? Enough to cover all of the characters?

Basically, what I'm thinking is that you have set \r as a termination character, but the instrument is returning all of the characters in a stream and the LabVIEW serial driver is getting all the characters and truncating everything after the termination character (the \r).

Try turning off the termination character and see if you get all of the lines that you expect.

    Rob
Message 3 of 10
(3,387 Views)
Thanks for your replies.
 
This is exactly what I was thinking because when i send the ?z character from Matlab, it return 9 bytes which cover all of the strings i have mentioned. Ofcourse I need to execute the read operation 3 times.
 
In case of Labview I am only receiving 4 bytes of information.
 
I assume that when you configure the serial port to set the termination character, it is only for read operation. For write operation, you need to send the terminating character as part of the string! (Please correct me if I am wrong).
 
Surprisingly, when I used the measurement and automation explorer to send ?z\r, I receive all 3 strings through 3 successive read operations.
 
I will try to attach the vi again in my next message.
0 Kudos
Message 4 of 10
(3,364 Views)
The vi is attached. (hopefully)
0 Kudos
Message 5 of 10
(3,344 Views)
Well, you didn't seem to get the VI attached.

But one thing about setting serial ports - when using a property node, there are 2 settings that often get missed. Under Serial Settings:End Mode for Reads and End Mode for Writes. Not only can you enable the termination character, you should select what you want to do with it from these 2 settings.

Are you using the Bytes at Port property node to check how many bytes to read? If so, how many bytes does it think you have to read? If you KNOW how many bytes are in the reply then you can try reading only that many bytes and then reading again to see what you get.

Is it reading all bytes and putting them in one string output? Then when displayed it is a text box with multiple lines? Try changing the text box mode to "\" codes display and see if it says the same thing.

     Rob
0 Kudos
Message 6 of 10
(3,330 Views)
Thanks Rob
 
Yes I am using the bytes at port property to read the values. I have originally tried to fix the number of bytes to be read from the serial port but the problem remains.
 
I will check that \codes thing and will let you know the outcome.
 
I am having some trouble attaching the file. I selected the file twice and hit the submit post button but it didnt seem to attach the file. Not sure if I am doing anything wrong.
 
I dont think its reading all the bytes. The number of bytes available after the write operation are only 4 which are ?z\r.
 
Wasif
0 Kudos
Message 7 of 10
(3,324 Views)
Got it attached this time although I didnt do anything different. Smiley Happy
 
Just for info, I am using Labview 6.1
 
Wasif
 
0 Kudos
Message 8 of 10
(3,319 Views)
The first thing I noticed is that the string to write control is not set for '\' Codes Display so if you type in a \r, you are not sending the control code. You are send the characters '"\" and "r".
0 Kudos
Message 9 of 10
(3,316 Views)
Thats it. problem sorted. Thanks everyone.
 
Wasif
0 Kudos
Message 10 of 10
(3,303 Views)