LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Failed serial communication

Hi, I´m new in LABVIEW, so this error may seem stupid, but I'm trying to communicate with a laser via serial communication and it doesn´t work.

The communication consists in sending a command to the laser about a parameter and obtaining its value. According to de guide, the command must be written like ":H1↵" , being H1 a temperature of the laser. Once it is send, the laser should response with ":H1,xx", being xx the value of the temperature or ":H1!" if the command is not recognized by the laser of if it is not written correctly.

In the attached VI I try to establish the communication, which is based on the basic serial/write example in labview, adding some element as the conditions to stop the vi from running, which stops automatically when there is no bytes left to read at the port and it has already read a byte. The other addition are the arrays, which I inlcuded because I thought that the laser may be sending the bytes in different packages of bytes, so with the arrays I can see all of them, and the part outside the loop is to obtain the array in a clean format without the initial and final offset.

All of this explained, the error consists in that it not only does not receive the ":H1,xx" or ":H1!" as it should, but also every time I run the programm, I receive a different answer. Some examples are: "ec e7 e7" , "ec f7 e7 f7" , "ec f7 e7 e7" , " ec f7 f7 e7". 

Any ideas of what could be going wrong? (The laser is from the continuum dls laser series, if it helps)

0 Kudos
Message 1 of 3
(2,112 Views)

If you browsed this Forum, you might have found numerous beginners confused about how to handle serial communication.  When I saw "when there are no bytes left to read", I knew you are making the "most common Serial Communication error" that shows up in this Forum.

 

When you configured VISA, you should wire a Boolean "True" constant to "Use Termination Character" (don't make it an option, force it to be set).  You can probably leave the Termination Character at its default value, 0xA (or <Line Feed>), but you should check the communication settings on your Serial Device to be sure that is how it is communicating (most Serial Instruments I've used send text, terminated by <LF>, when communicating).

 

Now you send a String (ending with <CR><LF>) to your Device to get it to send data back to you.  You do a VISA Read, specifying "more bytes than you will ever need" (I use 1024, as I like powers-of-2).  The VISA Read will patiently wait until the device responds (or 10 seconds, or whatever has been set as the Timeout, occurs, generating an Error), and will return the String.  You (almost never) need/use Bytes at Port.

 

See if this helps.  If not, provide us a link to the manual to your device (so we can look at its protocol) so we can figure out what went wrong.

 

Bob Schor

 

P.S. -- I should have asked -- did you try to communicate with your device using MAX?  This can provide a way for you to type a Command and ask MAX to read the response.  You can adjust the Serial settings (Baud, mostly -- the others, like Parity, # bits, etc., are almost always N-8-1, no flow control), and can be sure that you are using a Termination Character and that it is <LF> (0xA).

0 Kudos
Message 2 of 3
(2,073 Views)

Do you have a manual for the laser?  There are a lot of finer details that don't quite make sense that I would rather verify through the manual myself.

 


@juanto97 wrote:

but also every time I run the programm, I receive a different answer. Some examples are: "ec e7 e7" , "ec f7 e7 f7" , "ec f7 e7 e7" , " ec f7 f7 e7".


Typically when I see that, the Baud Rate is wrong.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 3
(2,054 Views)