LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Newport YAG Laser power supply serial control

Hello,
I'm trying to connect a Newport power supply (Model PS51) to computer control via a RS-232 connection. I've had some trouble getting communication started, although I have made some progress. Here's what I have:

So far, through the MAX utility I sent the "*IDN?" query, and got a response that included the serial number and type of the power supply, in short, I know that I can communicate with the power supply. The response was something like 73 characters/bytes long.

Next I tried to write a LabVIEW VI that does the exact same thing. I've attached the VIs (YAGcom.vi, YAGcomS.vi is just a different connection opening (Serial vs. VISA), I don't know which is better, both don't work.), but it gets no response from the power supply. Technically it gets a timeout error (# -1073807339) from the read function. I tried reducing the bytes expected to 1 as they suggest, but that didn't help.

I also tried sending commands specific to the instrument, interpreted from this example program out of the manual (example1.pdf). This should turn the laser lamps on and off, however it doesn't. If I could get this to work, I would be most of the way there, I think.

If anyone has experience either with this type of power supply, or some hints on serial communication I would be very appreciative.

Thanks,
Karl
Download All
0 Kudos
Message 1 of 28
(5,291 Views)
Can't seem to open your VIs. LabVIEW says they're not resource files. Maybe something got corrupted during the file upload. The forums servers have been a little wonky the past couple of days.

Regardless, in terms of your question of serial vs. VISA. VISA is an API that allows you to communicate to instruments. It can be used to talk to instruments over a serial interface, a GPIB interface, or a TCP/IP interface.

The most likely reasons for your timeout:
  • Did not end termination character to the command string that you sent out. Sometimes you need to indicate the end of a command string with a character like a carriage return character or a linefeed.
  • Not waiting enough time after sending the command before attempting a read.
  • Not specifying what character to use to indicate to VISA Read when it should terminate the read. Again, this is usually used to indicate the end of a message from the device. Typically this is a linefeed.
If you open the Example Finder (Help -> Find Examples) and search for "serial", you will find the Basic Serial Write and Read example, which performs a serial write/read using VISA. Since you've already verified you can use HyperTerminal, I would start by using this example first to make sure you can talk to the device using LabVIEW
0 Kudos
Message 2 of 28
(5,273 Views)
Thanks for the fast response!  Sorry about the files.  Here they are again, from a different computer on my end.  I hope this works.

As for the example, my program is only a minor extension of the basic example that they gave, so I thought it would work.  Where does one specify the termination character?  I did that for the VI that uses the serial opener, and I specified it as /n, although the device seems to return /n/r.  Is there an important difference there?  It seems like it should work even if I don't put both in.

I'm also not sure about specifying the "read" part of it.  I also threw in some waits of 5 seconds or so that should give it plenty of time.

Thanks again,
Karl
Download All
0 Kudos
Message 3 of 28
(5,264 Views)
I'm not sure which example you're referring to, but it's definitely not the Basic Serial Write and Read one. Your VIs have no wait statements in your VIs. If the device ends a message with \n\r, then you need to specify \r as the termination character, since you can only specify a single character, and \r is the last character that it sends.

Thus:
  • In the YAGcomS1, change the constant of 10 to 13, which is the ASCII code for \r.
  • Set the Boolean constant to TRUE to indicate that VISA Read should use the termination character to indicate an end of read operation.
  • Insert a wait between the write and read, as is done in the Basic Serial Write and Read example
  • Change the constant of 2 that's fed to the VISA Read to some large number, like 100.
  • Enter the \n correctly for the string to write to the device. You've entered the \n using "normal" display mode. This means that the VISA Write is sending out *IDN, followed by the character "\", followed by the character "\", followed by the character "n". This is not the same as sending a linefeed character after *IDN?. Right-click on the string constant and select '\' Codes Display. You will see the string now show up as "*IDN?\\n". Remove one of the backslashes. Now it will send out *IDN?, followed by a linefeed character (\n).
0 Kudos
Message 4 of 28
(5,257 Views)
In both VI's, there is no wait statement between the Write VI and the Read VI.  Put a small wait statement in there such as 200 ms.  Also, set your byte count to be -1 so it reads all bytes.  Look in the example finder for Basic Serial Write Read.
0 Kudos
Message 5 of 28
(5,256 Views)
Try the attached vi.  You will need to know:
 
1) what baud rate to use
2) # of bits (probably 😎
3) Parity (probably none)
4) Command termination method (carriage-return, carriage-return\line-feed, line feed, etc., which I have it set for carriage-return\line-feed)
5) Response termination method (carriage-return, carriage-return\line-feed, line feed, etc., which I have it set for line-feed but will work fine for carriage-return\line-feed
 
I tried this vi out on a device (I changed the command to one that it supports) that requires carriage-return\line-feed for the command termination and also responds with carriage-return\line-feed in the response
0 Kudos
Message 6 of 28
(5,230 Views)
Hi again,
Thanks everyone for the help.  I can now get the identification string from the power supply, as I wanted to.  Now I know that I'm talking to the machine.

The next step is to send it real commands, and I've tried to copy their program (see my first post) as faithfully as I can with this VI here. The first part is just the program you gave me, rewritten in LV8.0.  (I don't know how to convert LV8.5->LV8.0)  The rest seems to do nothing.

Their command structure uses a lot of commas, could that change to something else when I type it into a string constant in labview?  Is there anything else that I'm forgetting? I changed all of the constants to code display, the last two commands should turn the laser on and off, but they don't do anything.  I've never tried interpreting code into LV before, so I might be missing something really basic (again).

Thanks again!

Karl
0 Kudos
Message 7 of 28
(5,207 Views)
Well, without a manual it's impossible to answer your question as to whether the commands are correct. In terms of your question regarding commas "changing to something else"... no, that's not going to happen.

One comment regarding your code: your delays are not tied to when you send the individual string of commands. Within a specific fram the wait can happen before or after the VISA Write, as there is no data dependency. This means that in one frame you can have the situation where the Wait occurs first, then the VISA Write, and in the very next frame the VISA Write executes first, and then the wait. My guess is that you were intending the wait to occur after the VISA Write. The position of a function on the block diagram does not dictate when it executes. Only data dependency dictates that. I would suggest using the Time Delay function. That has error in/error out clusters, allowing you to wire the whole sequence in order, and also allow you to eliminate the sequence frame.
0 Kudos
Message 8 of 28
(5,191 Views)
Sorry, I didn't realize you are using LV 8.0.
 
I modified your code a bit, but copied exactly the command order shown in example 1 of the .pdf file you have posed.  What I'm not sure about is a) does it really have 2 stop bits, 2) are commands supposed to be CRLF terminated, 3) are the commas supposed to be command terminations
 
Is the manual somewhere online?  If so, check it over and post a link.
 
 
0 Kudos
Message 9 of 28
(5,183 Views)
The one problem with your example, labviewman, is that you're using the EOL constant to append to the commands. This constant will vary from OS to OS. You should explicitly use a string constant of \r\n.
0 Kudos
Message 10 of 28
(5,181 Views)