Monday, May 27, 2013

More on LabVIEW, this time with RS232

My LabVIEW adventures continued today (yes, being close to graduation means you work on US national holidays). I began designing and implementing the pieces of my LabVIEW program for controlling the experimental setup that I discussed briefly in my last post.

After getting all the hardware pieces independently working with LabVIEW example VI's, I started working on some custom VI's that did exactly what I needed each piece of hardware to do. My idea is that I will use each custom subVI in a large control script. This control script should contain the commands to pass to each subVI and the order in which they'll be executed. All the data from the SR400 Photon Counter should be saved at each step, along with the current state of all the hardware pieces.

I started working on controlling the laser I have connected to a RS232 port. This should have been simple, but I my first bit of code simply didn't do anything. If I told the laser to turn off, it wouldn't. To mock me, the example "Basic Serial Write and" that's included with the LabVIEW base DID work.

After an hour or two of playing around, I discovered that the strings I was passing to the laser in my custom VI did not contain the line feed ASCII character "\n" that is required to mark the end of a command, even though I included it in the string. The strings were stored in a drop down menu of common commands I frequently use. The line feed character was also included in the string I entered into the example VI and this was actually sent to the laser, which is why it worked.

I ended up fixing the situation using the information on this NI community page. It's a bit strange that it requires this much work to place a line feed at the end of a string, but oh well, it works.

I also ran into some issues with having the commands from the laser echoed back to me when I read the data from its buffer with a VISA read VI. I didn't want the echoes, I wanted the information that each command should return. I fixed this by doing to VISA reads. Apparently, LabVIEW's VISA read only reads until the carriage return/line feed and leaves the rest of the information in the read buffer.

Though I ran into some bumps, I'm very grateful for the help I've been able to find on the NI support and community sites. Without them I probably would still be stuck.