LabVIEW serial code has the same test problem as every other serial code, with a graphical accent: the VI is finished, the instrument is not available, and a block diagram cannot be debugged against thin air. The fix is to remember what VISA actually opens — a COM port, not an instrument. Give LabVIEW one end of a com0com virtual pair, put a small simulated instrument on the other end, and your VISA reads and writes run against a partner that answers like the real hardware. This guide wires that up and names the two gotchas that account for nearly all failures.
The shape of the setup
Three pieces, in data-flow order: your LabVIEW VI opens a VISA session to one end of the pair (COM11 in this guide). The com0com pair carries the bytes across. A responder program — a few lines in any language — listens on the other end (COM10) and plays the instrument: it receives your VI’s query and writes back the reply the real instrument would give. Nothing in the VI knows the difference, which is the entire point: the code under test is the production code, port name aside.
Step 1: Create the pair and rename it — this step is not optional
Create the pair as in the first-pair guide, then rename both ends to COM numbers:
command> change CNCA0 PortName=COM10
command> change CNCB0 PortName=COM11
In LabVIEW work the rename matters more than anywhere else. VISA finds serial resources by scanning for ports, and a port still carrying its CNCA0 name can be invisible to that scan — the VI’s VISA resource control simply never offers it. Renaming to a COM number, and for stubborn cases putting the port into the Ports class with the PortName=COM# form, makes the virtual port enumerate exactly like a hardware port. The full reasoning and both forms are in the rename guide, and the symptom is catalogued in port not recognized.
Step 2: Check the port in NI MAX before opening LabVIEW
Open NI MAX (Measurement & Automation Explorer) and look under Devices and Interfaces for the serial ports. The renamed virtual port appears there as a standard COM port, indistinguishable in the list from a hardware one — that listing is your proof that the Windows side and the VISA side can both see it. If it is missing, fix that here, not in the block diagram: it is a naming or driver issue (Step 1, or the troubleshooting hub), never a LabVIEW issue. While you are in MAX, its test panels give you a terminal-like way to open the port and send a string — useful in the next step to prove the responder before the VI is involved.
Step 3: Put a simulated instrument on the other end
The responder’s contract is small: read a query, write the reply the instrument manual promises. If the instrument answers *IDN? with a manufacturer string, the responder does exactly that; if it streams measurement values after a trigger command, the responder sends a stored sample line. A minimal Python responder of about twenty lines — listening, matching the query, writing the canned reply — is built in the pySerial virtual port guide; run it on COM10 and it serves any VISA client, LabVIEW included. Prove this layer with NI MAX first: send the query from the test panel, watch the canned reply come back. Only then involve the block diagram, so that a failure afterwards is known to live in the VI.
Step 4: Run the VI against the virtual instrument
In the VI, the serial flow is the standard VISA one: VISA Open on the resource name for COM11 (an ASRL resource for the port), the serial configuration your instrument expects (baud rate, data bits, parity, termination behaviour), then VISA Write for the query and VISA Read for the reply, and VISA Close at the end. Set the same line settings the responder assumes — as with any serial link, a mismatch produces framing garbage rather than an error message. Develop the parsing, error handling and state machine here, against the responder’s canned and deliberately misbehaving replies; the block diagram cannot tell that the instrument is a Python script, and your error clusters will light up in exactly the places the real instrument would eventually have provoked.
Gotcha first, actually: termination characters
The most common ‘it almost works’ in VISA serial work is a read that seems to hang although the responder swears it replied. Serial reads through VISA typically end in one of three ways: the requested byte count arrives, the read times out, or a termination character — conventionally the line feed — is received and ends the read early, which is how the standard serial configuration in LabVIEW is set up by default. If your simulated instrument’s canned replies do not end with the termination character your VI expects, the read waits for it until the timeout, every time, and the data you do see arrives a timeout late. Match the two: make the responder terminate replies the way the real instrument does (its manual states the terminator), and set the VI’s termination behaviour to expect exactly that. Half of all ‘the virtual port is slow’ reports are this, on virtual and physical ports alike.
Gotcha: leftover characters and buffer behaviour
One difference between the pair and a cable will eventually bite a test session: with the driver default, bytes written while the far end is closed are not thrown away — they wait in the buffer and are delivered when the port is next opened. In LabVIEW terms that can look like a stale reply arriving as the answer to a fresh query, or an instrument that ‘answers before being asked’. It is documented com0com behaviour with a documented remedy (enabling receive buffer overrun emulation on the receiving end), and it is explained with its sibling symptom, startup hangs, in com0com hangs and leftover characters. Knowing it in advance converts a baffling afternoon into a two-minute fix.
Structuring the work: driver VI below, tests above
One organisational habit keeps LabVIEW serial projects testable as they grow: keep the VISA session in a small driver VI of your own — open, configure, write-query, read-reply, close — and let the application VIs call it with a port name. Switching between the virtual instrument and the real one then changes one constant at the top level instead of hunting through block diagrams, and the same driver VI serves the bench prototype, the automated test and the deployed system. It also makes the simulated instrument reusable across projects: the responder script plus the pair convention (COM10 device side, COM11 application side, as used throughout this guide) can live in a shared repository that every LabVIEW project on the team points at.
What you have proven, and the final step
Against the virtual instrument you have proven the VI: resource handling, queries, parsing, timeouts, error paths. You have not proven the instrument: its real reply timing, its flow-control expectations and its firmware’s eccentricities are all still its own. So the workflow ends where every honest virtual workflow ends — a final validation session against the real instrument on the real port, which in LabVIEW terms means changing the VISA resource constant and nothing else. If the setup itself is new to you, the general pattern behind this guide is laid out in testing a serial app without the hardware.
