LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to properly control two serial instruments using RS232

Solved!
Go to solution

Hello, I am pretty new to LabVIEW but I have been trying to use the examples etc. to create a program that can control a MKS 600 Pressure controller and a SAIREM Microwave Supply for the purpose of performing MPCVD. Currently I have a VI that works in the sense that I can turn on, turn off, increment/decrement values, etc. on both devices using event cases in while loops. I wanted to add a section to my front panel where I could have readouts of 3 different values displayed. Those being the pressure of the system, the forward power, and the reverse power of the MW supply; however, when I try to implement this using what I know from the LabVIEW examples, I receive a timeout error (VISA: (Hex 0xBFFF0015) Timeout expired before operation completed.which I believe is due to the FP/RP readout of the MW power supply . I've tried a couple of different remedies but I am kind of stuck on what to do. Also I would like some advice on how to better this code. I've been watching a lot of videos and noticing that the Serial LabVIEW examples are not too good. I've also looked at some Producer/Consumer architecture which seems like the more professional method to go down but I honestly a little confused on how that works. Lastly, another issue I am having is that the local variable stop for all of my parallel while loops doesn't work and the code keeps running. What can I do to stop this? Any help is apricated, thank you in advance.

 

 

0 Kudos
Message 1 of 10
(372 Views)

Good morning, smcal234.  Welcome to the LabVIEW Forum.

 

Thank you for attaching your VI for us to examine.  Unfortunately, as you are a "new" LabVIEW user, you are using LabVIEW 2024, and many (myself, included) "old-timers" haven't (yet) upgraded our licenses to at least this Version.

 

Older versions of LabVIEW, such as LabVIEW 2021 that I'm using, cannot open newer VIs.  The "fix" for this is for you to open your VI, go to the File menu, and choose "Save for Previous Version".  Specify LabVIEW 2021 or 2019, which seem to be popular choices.  If the result is a Folder, right-click the Folder, choose "Send to:" from the (Windows 10) Drop-down menu, and specify "Zipped (compressed) folder".  Attach that, and we'll be off and running.

 

Meanwhile, another thing you can do is to use MAX, the Measurement and Automation Explorer to let you "play" with your VISA ports.  Connect everything up (it's not clear how the two devices are configured, but here you are just going to test them one at a time).  The next tab may or might not be needed -- refer to the device Manual.    

 

Open MAX.  Expand "Devices and Interfaces", and look for the two serial ports you are using -- they may have a name like "COM3".  Select one and open a Test Panel.  You should see a set-up where you can set the Serial settings (Baud Rate, etc.) and Buffer Operations (read your manual and see if this is necessary).  For now, leave the other settings (unless your manual specifies things like Termination Characters).  

 

Now go to the Input/Output tab.  Here is where you try to Talk to and Listen to your device.  You'll see that it's set up to send the (quite commonly-used) "Identify Yourself" command, @IDN?\n.  The \n is a "newline" character, or Line Feed (hex 0x10).  Write that (to your device), which should respond with some Identifying characters, probably also ending in \n.  Push "Read" to read them into the buffer.

 

If this works, you have the beginnings of communication with this device!  Now you just need to do the same for the other device, then learn how to so all this with VISA commands in LabVIEW.  Fortunately, there's more help, including a great talk by Tim Robinson (I'll bet you could find it if you did a Web Search for "VISA Tim Robinson").

 

Bob Schor

0 Kudos
Message 2 of 10
(312 Views)

First go watch this video VIWeek 2020/Proper way to communicate over serial as it can solve most serial communication issues.

 

Don't initialize the com ports, retrieve data, and then close the com port every single iteration of the lop.

 

Then you need to learn a proper program architecture. This mess of disconnected loops communicating through local and global variables is going to end up being nothing but a bunch of race cases. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 10
(281 Views)

Hello, thank you for the reply. Sorry about the newer VI, I'll attach another version below. I've made successful communication with both devices using MAX and I have been going through the LabVIEW examples and such. This code probably seems like a mess and I am currently going through the process of redoing but let me know how I could improve this. My main goal is to continuously have control over the two devices over the range of say ~ 3 hours. In order to do this, I couldn't really think of another way I could achieve this beside implementing a bunch of parallel while loops, but I believe that led to some read errors that I was getting.

0 Kudos
Message 4 of 10
(264 Views)

Actually found this video the other day and I was playing in a separate VI trying to use his method for continuously reading but I am a little confused on how I can implement a read function before a write function; does the read VISA waiting for me to write something? Just as a learning thing, should I take the VISA close function outside of my event & while loop? Originally I had the VISA close outside my while loop for my readout.

 

Do you have any recommendations for program architecture for continuous control of 2 serial devices for the time span of ~3 hours?

 

 

0 Kudos
Message 5 of 10
(262 Views)
Solution
Accepted by topic author smcal234

HI Smcal234


Thank you for sharing your code. 

The error you are receiving is because the device didn't responded to the command you sent. 

In your code, you are consantly Serial Config, writing/reading and then closing the port. 

 

The opening could be executed only 1 time in the beginning of the program... and closing at the end. 

 

You could make use of Sub-vi -  is a vi that you use to reuse the code, instead of repeat the code over and over everytime it's needed. 

LVNinja_0-1751308902444.png

The commands you send / receave from serial could be implemented on the Subvi and associated to the command you are trying to execute. 

Finally, a program strucuter of producer/consumer (EVENTS) would make your code easier to mantain. 

This structure has 2 loops:

The Producer loop (top) - that constantly monitors the User interface for any change and in case of any interaction of buttons, numbers change, it will trigger a commnad to the Consumer loop. 

The consumer loop (bottom) would basically receive the commands fromt the producer loop   and send the command to serial. 

In your case, you could have 2 consumer loops one for each serial port MW_Supply and another for MKS-600. 

A draft version of the architecture is the diagram bellow. 

 

 

LVNinja_2-1751309662169.png

 

 

 

 

0 Kudos
Message 6 of 10
(244 Views)

Ah thank you! I had to recreate that first image from my code from what I remembered since I deleted that section, and accidentally overwritten the code so I mistakenly put the settings/VISA close inside of the loop. But thank you! I'll try to implement that Producer/Consumer Loop for my code!

0 Kudos
Message 7 of 10
(234 Views)

Quick question about this templete. Should I have two event cases for each intrsument in the producer loop if I want to keep the commands from the MW_Supply & MKS_600 seperate? I have tweak the string values differently.

0 Kudos
Message 8 of 10
(169 Views)

@smcal234 wrote:

Quick question about this templete. Should I have two event cases for each intrsument in the producer loop if I want to keep the commands from the MW_Supply & MKS_600 seperate? I have tweak the string values differently.


That depends on what you are trying to do. Do note that each instrument consumer should have its own queue. So a single event case could send a command to each of the instrument loops.


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 9 of 10
(143 Views)

Thank you crossrulz for clarifying. 

You need to create 2 queues, one for each serial port. 

Then on the producer loop, you associate the proper queue message to the right queue direcgted to the proper consumer queue. 

 

On the consume loop, you need to create one case for each "queue" message, meaning each user interface interaction will trigger a different message/command to the consumer loop. 

 

LVNinja_0-1751549953621.png

 

0 Kudos
Message 10 of 10
(106 Views)