The Ladner group (Joe Batts, Weiming Qi, and Matt McKinney) has been hard at work building a field-deployable membrane unit. One key step in this process was creating Labview programs to control our peristaltic pumps. This is a common enough endeavor (especially for Masterflex pumps that are often used) that we thought there would be great examples available online. But we didn’t find any that clearly explained what to do. So here is what we came up with. Hopefully it will be useful for others. We’ve done this on a few pumps, but the most recently purchased was Masterflex EW-07551-20. (Or just 07551-20; not sure if the EW is necessary).
Our approach was to write two Labview programs (what Labview calls “virtual instruments” [VIs]); one to initialize the pump and one to control it. These are meant to be embedded in an umbrella program that controls and reads signals from all the other components in the system (flow meters, pressure gauges, etc.).
And here is a YouTube video where I explain the nuts and bolts of the programs.
Update, August 2018
Someone who was trying to use this method sent some feedback and we had an email exchange. The programs weren’t working for him until he did several things:
- He hadn’t had NI-VISA installed, so he did that to be able to setup the COM1 (RS232) port.
- In the Masterflex initialize program there was a breakpoint defined, which he removed.
- He had an error of “Type Definition ‘Boolean’: Type definition not found or contains errors.” It seems that the in the Masterflex control program the (forward/reverse) direction toggle switch is not forward compatible with LabVIEW 2018. He right-clicked it and replaced it with a horizontal toggle switch from the menu. In other words, he replaced the “old” switch with a “new” one.
- His particular pump could not go 300 rpm, so it did not respond to his commands. Any value <= 100 worked with his pump.
After those fixes (and perhaps other little things he didn’t tell me about!) the programs worked for him on his system.
Then he had the problem of licensing: he only had a one-week trial of Labview! So he did some digging and figured out how to send commands to COM1 using the command line. Now he is sending them via system calls from the R programming language. No LabVIEW required. Pretty good work!
Here is the R script:
# set up the serial port system("mode COM1 baud=4800 parity=o data=7 stop=1", intern=T) # initialize the pump zzz <- system("cmd.exe", input="echo \x05 > COM1", intern=TRUE) # this command will cause the pump to be P00 for some reason zzz <- system("cmd.exe", input="echo \x02P01 > COM1", intern=TRUE) # for some reason need to run a command to initialize the pump to P01 zzz <- system("cmd.exe", input="echo P01S+20G0 > COM1", intern=TRUE) # send commands to the pump zzz <- system("cmd.exe", input="echo P01S+20G0 > COM1", intern=TRUE) zzz <- system("cmd.exe", input="echo P01S+80G0 > COM1", intern=TRUE) # halt the pump zzz <- system("cmd.exe", input="echo P01H > COM1", intern=TRUE)
Good job Dave!!!!
Hello! I’m trying to control a peristaltic pump through LabVIEW and I was trying to use your .VI. But I have an earlier version, could it be possible to get a version which can be run in LabVIEW 2013?
Thanks in advance!
Hi Louise. I don’t know if there is an option to save with a prior version. I can look into that. But in the meantime, I would think the logic would behave very similarly, and the program isn’t too complex, so perhaps it can be created in Labview 2013 using the video as an example.
Hi there,
I have “Shenchen Peristaltic Pump”. V-Series, you can find some information on http://www.good-pump.com. My question, is your software could work with it to control the amount of the medicine and control the inventory?
Thanks,
Sami
Hi Sami — I am fairly confident Labview could be used to control the pump if it has an RS232 or voltage control interface. You would also need the appropriate hardware; there needs to be a “box” (for lack of a better word) between the computer and the pump. That box is something that can talk to Labview, and send the appropriate signals to the pump.
What is the box you are talking about?
Hi Melissa; sorry for the slow reply. I overlooked your question until Yasmine asked the same question below.
It depends on what kind of signals the pump can accept. We use RS232 signals, so the “box” that we use is a USB – 232/4 box from National Instruments, catalog number 778473-04. The price was about $520 when we bought it. We also have a USB – 232/2 from National Instruments, catalog number 778473-02. That was $360.
We do other things with voltage signals, and we use a USB-6009 from National Instruments, catalog number 191039D-01L. We got that from Ebay for $220.
These details are from my student Weiming Qi’s thesis: https://tigerprints.clemson.edu/all_theses/2874/
can you give an example of a “box” brand you used
It depends on what kind of signals the pump can accept. We use RS232 signals, so the “box” that we use is a USB – 232/4 box from National Instruments, catalog number 778473-04. The price was about $520 when we bought it. We also have a USB – 232/2 from National Instruments, catalog number 778473-02. That was $360.
We do other things with voltage signals, and we use a USB-6009 from National Instruments, catalog number 191039D-01L. We got that from Ebay for $220.
These details are from my student Weiming Qi’s thesis: https://tigerprints.clemson.edu/all_theses/2874/
Hi,
I have been trying to communicate with AALBORG Instrument’s DPC mass flow controller which has an RS485 output. I’m using an RS485 to USB converter to communicate using the com port. I’m able to read the date from my Flow controller. Now i want to control the set point through RS485. I tried to find examples online which didn’t help me much. I would really appreciate if you tried to help me out.
Thanks in Advance!
Hi Karthik — There are lots of things to look into. I’d be happy to have a conversation with you to discuss, though to be honest, the equipment vendor is the first place to go, since they know their particular instruments. –david
Hi,
Thanks for sharing the labview code. I am using a 07552-20 peristaltic pump from masterflex in our lab and trying to use your code to control it. However, I can not make the PC communicate with the pump using the initialization program no matter which mode I choose in pump (local or remote). The labview version I am using is 2019 and operation system is windows 10. Could you provide any suggestions or comments? Anything will be helpful. Thank you!
BTW, I am also from Clemson University. Go Tigers!
Best,
Dongkai
Hi Dongkai — Great to hear that you’re trying this out. There are always a wide variety of things that could be going wrong, and a relatively smaller list of ways that it works correctly. So it’s tricky to troubleshoot from afar. But the first thoughts I have are:
1) Make sure the COM port is selected correctly. I think this was mentioned in the video, but I’ll re-emphasize it.
2) A restart of the pump and the computer is always worth trying!
3) Use NI-Max (measurement and automation explorer) to “play” with the connections and make sure the computer is seeing the pump.
4) Make sure you’re using the right kind of serial chord. Some of them are straight-through, some are … the other way; can’t remember the term now. But if it was a chord that was “just laying around” you’ll need to check it.
Hope you can figure it out!
–david
Hello David, thanks for your suggestions. I tried what you said here but the pump still not moving, I wonder which mode (e.g. local mode, remote->voltage input mode or remote->current input mode) you are setting the pump when using LabVIEW to control it. Also, I have two quick questions and I appreciate if you could answer them as well.
1. Which operation system you are using (windows 7/8/10)?
2. Did you installed any driver for the pump or serial cable in PC?
Thank you for your time and help!
Hi Dongkai — I apologize for overlooking your comment for so long. Surely you’ve moved beyond it now, but for completeness I’ll give a response.
Funny enough, I remember one time several years ago when “local mode” was what needed to be active to work. But that may have been with a SciLog pump, not Masterflex. We are not using voltage input, though a student did try it once and it did work. We most commonly use RS-232.
1. We have used all of the operating systems you mentioned: Windows 7, 8, 10, and even back in XP days.
2. We did not install separate drivers for the pump or serial cable. We installed the NI-Max software, which I believe has the drivers. There could have been other things we installed, but I am pretty sure they were all National Instruments drivers and not things from the serial cable vendor nor the pump vendor. (Perhaps those other drivers could work, but we did not use them.)
Hi Dongkai,
Were you able to get your pump running?
I am encountering the same issue as you. I tried to use the same vi but my pump is not running as well. If you were able to resolve it, could you please kindly help me out?
Thanks,
Anna
Hi Anna — This post is a few years old now, so our VI may have been rendered obsolete by LabVIEW upgrades or other changes. In the meantime, my student Weiming Qi decided to use voltage control for a new system he is building. He feels the voltage control will be more stable than RS-232. We may create a new post on that at some point. Best of luck in your endeavors. –david
Hello,
I am a graduate student working with the Masterflex 7550-30 pump and am trying to programmatically control the flowrate through time. I found the above published code works perfectly in R if the commands to set the speed and halt are prepended by the start of text character, as in:
system(“cmd.exe”, input=”echo P01S+20G0 > COM1″, intern=TRUE) corrected to
system(“cmd.exe”, input=”echo \x02P01S+20G0 > COM1″, intern=TRUE).
However, if I try to run the following line in the windows command prompt itself, I do not get the same response as I do in R
for example, “echo \x05 > COM1” does not initialize the pump in the cmd, but it does in R on the same computer. The COM port has the correct settings.
Any help to decipher why R might work, but not the cmd directly would be greatly appreciated, Thank You
Hi Keerthi. Unfortunately, I haven’t tried sending commands through the windows command interface. My only guess is that “echo” might not be something the windows command prompt understands, while R does. I have used “echo” in PHP coding, but not in windows shell commands. But, as a I said, this is just a first guess.
Thanks for your prompt reply, David. I am surprised that if R is availing of the ‘system’ function, which should operate on dos/shell, running the same code in the windows shell itself doesn’t work. There is very little documentation in how the system function in R is operating and even after trying many iterations, I haven’t made any progress.
My goal is to implement the R-code in Matlab and so far the only workaround I found was calling Rscript.exe to run the hard-coded R script from Matlab.
Keerthi, I have not tested it myself, but it could be that the “echo” command when run directly in the shell might be appending an extra space character after the ‘\x05’ sequence. See this short posting about that, and a simple workaround: https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/ .
Hi, Thank you for your code, I have a question how can flowrate be controlled by the LABVIEW instead of the speed of the pumps?
Hi Mahdi — We use LabVIEW to control the pump speed, which controls the flow rate. I can’t think of a good way to control the flow rate with LabVIEW if it isn’t changing the pump speed. If I had to try something, I would use a metering valve to direct some of the flow in one direction while recirculating the rest of the flow back to the feed tank. Perhaps that could be a good option if the pump has to be at a set speed. But then, of course, you need a controllable valve.
Hi there,
Thank you for sharing the codes. I have been using R codes as a reference to control the Masterflex pump and they work great. However, I want to control the pump using MSL codes and I am having trouble communicating with the pump through MSL codes. I would highly appreciate if someone can share some insight on this.
Thank you.
Hi Abdullah — sorry for the very slow reply. You’ve probably moved on by now. But anyway, we haven’t used MSL code. –david
Thank you for sharing your program. I am attempting to control a Masterflex Ismatec 78018-82 gear-driven pump via a db-25 connection (Connected directly to my laptop via db-25 to usb).
Each time I run the initialize program the pump runs for approximately 10 seconds at maximum RPMs, and then halts. It does the same when I run any variation of the actual control program as well.
I attempted using a Masterflex L/S 7528-30 and experienced the same result.
Any thoughts on how to work this out?
Thank you.
Hi Kevin — Sorry I didn’t respond earlier. Unfortunately, I don’t have a great guess as to what might be happening. My only thought is that the Masterflex RS-232 commands may be different; either upgraded, or different for that pump. But that’s a shot in the dark. –david
Hello David,
Thank you for sharing your VIs and tutorial video. I am trying to control a Masterflex 07522-30, but running into some issues. I am using a usb-RS232 cable to communicate with the pump. I mistakenly purchased a “null modem” type DB25 cable, so I added a crossover adapter. I am using your initialize.vi as received, except I had to remove the type def. from the serial settings constant. When I run the initialize.vi the pump does not change its display but starts running at high rpm. If I run the code again the pump stops briefly but then returns to high rpm. Pressing the physical play button stops the high rpm but then starts whatever is on the screen and won’t stop until I reset the power.
Have you encountered this type of problem? I would appreciate the time you take to give me your suggestions.
Thank you,
Zachary
Hi Zachary — I haven’t encountered that sort of thing, but some aspects of it sound similar to a comment Kevin C. had back in July 2022. I wonder if Masterflex has changed their RS-232 commands for some models. Not sure, but it’s my first guess. –david
Hi David,
I am trying the same what you did with the code. I was wondering what cable did you use?
Hi Jerin — We used a 9-pin straight-through serial cable.
Hello! I have Masreflex Peristaltic Pump ISM4408P and I want to control him from PLC Omron CP2E via RS232 communication protocol. Is that possible or I can do it only from LabView?
Best Regards
Hi Lurii. I don’t know details about the PLC Omron CP2E, but if it can do RS232, then yes, you should be able to control a Masterflex pump that way. (The pump does need RS232 capability, of course. I don’t know if all Masterflex Pumps come with that or not…) –david