03-06-2020 07:12 AM
Hi,
I have a vi written by my supervisor which requires the 'VISA resource name' (which is the USB port, in my case COM4) and has a box called 'write buffer' in which you can type commands to control a Harvard apparatus syringe pump.
So far I've got code to open the vi and can write the '00run' command into the write buffer but it will not allow me to put anything into the 'VISA resource name box', maybe because it's a dropdown box of detected devices? Anyway I need to set this to COM4 in order to comminucate with my pumps but I have been hitting my head against a wall for hours and can't find any solutions online.
My error is as follows:
In MATLAB:
Undefined function or variable 'COM4'.
Error in VI_Call (line 6)
vi.SetControlValue('VISA resource name',COM4);
When it opens the vi but can't fill the VISA box:
I will attach my MATLAB script and vi and hopefully someone can let me know how to get around this 🙂
Solved! Go to Solution.
03-06-2020 04:15 PM
You can save COM4 as the default value for the control. Just open the VI in LabVIEW, type in or select COM4 from the drop down. Then right click on the control, select "Data Operations", scroll down to "Make Current Value Default". Then re-save the VI. Now when you run it the COM port should be specified.
But it seems like you want the VI to be interactive (by that I mean to stay open and allow you to write a command, read a response, wait for more commands, etc..). The way the VI is coded right now simply executes with no command when called from Matlab directly. It won't wait for a command to be entered (unless you can type it in <100ms!), it just opens a VISA session with the instrument (current error), then send the command string (currently empty) the reads response and exits. I think you want to have your supervisor re-code it to allow you better interact with the instrument. If they aren't clear on how to accomplish this we can help.
Craig
03-06-2020 04:33 PM
Actually what you've said there sounds perfect, at the moment it puts in my test command (00run) when it runs the VI but just has an error with the COM port. Ideally what I want to happen is it opens the VI, inputs a command to change the pump flow rate then after that I'm quite happy for it to close since the pump only needs the initial command and if I want to change the flow rate, I can just call the VI again with a different command.
I was looking for a default option but didn't know what it would come under!
Unfortunately I don't have access to the PC for a couple of days but I think you've solved my issue, but I will wait to confirm when I can test it properly.
Thank you so much!
Callum
03-07-2020 08:54 AM
I have to admit, I haven't tried automating and sending commands to a LabVIEW VI from Matlab. (Anything Matlab can do, LabVIEW can do IMHO but to each their own.)
You could make the inputs that don't need changing in the LabVIEW code Constants rather than Controls. Your VISA resource and command string. Now if you wanted to pass values to the LabVIEW VI it appears you have a method, but you could use an INI file if that would be easier. Matlab write the value to the INI and then when you call the LabVIEW code it reads the INI file and then updates the parameters and executes the commands.
Let us know how it works.
Craig
03-09-2020 08:34 AM
So I just got back into the lab to try it out and setting the COM4 to be the default value (since for my uses it will always be plugged into the same USB port) worked absolutely perfectly!
Thank you so much for your help Craig!
If I was to do it again, I'd use only LabVIEW but I had already written most of the project in MATLAB and I'm getting towards the deadlines so that's why I've ended up having to use this method to control the pumps. As for as the analysis goes, I knew MATLAB better so decided to do it in that rather than also having to learn a new way of scripting things.
Thanks again,
Callum