02-17-2025 04:52 AM
Hi guys,
I'm reworking an existing LabVIEW VI. It's used to measure Dew-Point Temperature, External Temperature etc. In the lab, we have it connected to a MBW373. I'm working from home and can't access the MBW, so I'm trying to simulate the data stream so I can test the VI as if it were connected to the MBW. When running the VI, we input the appropriate COM Port to communicate with the MBW.
I'm using com0com and created a virtual COM Port pair (COM3, COM4). I've tested them with a Python script and they successfully send each other data. Now, I want to create a Python script that would simulate the behavior of the MBW with that COM Port pair.
Let's take the Dew-Point Temperature instance, that's implemented in the working VI. The VI opens the port with the VISA Open function and configures it with the VISA Configure Serial Port. Then it sends the port the command DP? with the Carriage Return Constant appended. After the COM port receives the command it returns a value, that is read inside the VI.
How should I go about writing my virtual MBW? I'm thinking of creating a Python script that takes in the commands from the VI and answers with the appropriate measurement data, using the appropriate MBW syntax. But I'm not exactly sure what to do with my COM Ports. If anyone can help with this, I would greatly appreciate it. Thanks
Solved! Go to Solution.
02-17-2025 05:37 AM
I'm not sure I understand your question. With any COM port you can open, read, write, close. You can use labVIEW as well to create your simulator, why not?
02-17-2025 07:06 AM
I want to create the simulator completely separate from the original VI. I probably can use LabVIEW to create the simulator, but I feel it'd be easier with Python. Are there any advantages to creating it in LabVIEW?
02-17-2025 07:14 AM
It depends on the specific project. if you feel more comfortable with Python, go that way. You did not make clear what is your orignal problem with the serial ports, though.
02-17-2025 07:33 AM - edited 02-17-2025 07:34 AM
The main issue is that I don't exactly know the exact roles of the ports. When creating the virtual ports, they always come in pairs. COM3 and COM4 are connected to each other and nothing else (I attached the screenshot). Let's say I assign the port address as 4. The VI is programmed to send a request to that address and to read the answer from that address.
When the VI sends the request to port COM4, it's not sent from COM3, so how does the request get to COM4? And when the request is processed, and the answer is sent, what's the path of the answer? Should I program it so COM3 sends the answer to COM4 (and the VI reads it from COM4) or should I program it so COM4 sends the answer (and the VI reads it from COM4)?
I hope this clears things up a bit.
02-17-2025 07:41 AM
The vi opens COM4. The simulation code opens COM3. Done.
Please don't think about serial port numbers as "addresses". This may generate confusion in some cases.
02-17-2025 07:50 AM
We use Instrument Interface Address in the VI, that's what I was referring to.
Thank you for the advice.
02-17-2025 12:17 PM
Not knowing much about Virtual COM Ports, and not familiar with com0com, I did a Web search and found this link about creating a virtual COM port in an earlier request on this Forum.
Once you get your Com ports set up, it seems to me that once you figure out the slightly complex method of juggling Virtual and Physical COM ports, it would be just as easy to write the demo codes using LabVIEW VISA. Pay close attention to the post from @rolf, who discusses using Bytes at Port when you want to ask "are there data waiting for me", but to then (assuming your device send strings with Termination characters, such as <LF> or <CR><LF> and asking to read 1000 bytes.
Note also that @crossrulz has an excellent video presentation on Serial Communication. Sorry I falied to bookmark it -- maybe someone else will provide the link?
Bob Schor
02-17-2025 01:25 PM
@Bob_Schor wrote:
Note also that @crossrulz has an excellent video presentation on Serial Communication. Sorry I falied to bookmark it -- maybe someone else will provide the link?
Macros are a wonderful thing...VIWeek 2020/Proper way to communicate over serial
02-19-2025 08:09 AM
Thanks a lot guys. The VI can communicate with the virtual port now. A tip for anyone else trying simulate a COM port with a virtual instrument, pay attention to the correct syntax of the commands, and especially the termination characters, like <CR> and <LF>.