How-to
How to build a virtual PLC test bench for protocol practice
Short answer
One laptop runs the whole bench: a Modbus TCP server simulator, a master test client, a Node-RED OPC UA server and a SCADA trial connect over loopback, so you can practice addressing, sessions, scaling, alarms and fault diagnosis without a PLC. Work through three bounded projects and finish with seven pass criteria you can defend.
On this page
You do not need a PLC on your desk to get good at industrial communication. One laptop runs the whole bench: a Modbus TCP server simulator listening on TCP port 502 at 127.0.0.1, a Modbus master client, a Node-RED OPC UA server on port 4840 and a SCADA trial, all talking over the loopback address. Build three bounded projects on it — a Modbus TCP exchange, an OPC UA tag path, and one SCADA screen with a live alarm and trend — and you will have practiced addressing, sessions, scaling, alarming and fault diagnosis, which is exactly what a screening interview probes. This article gives you the tool roles, ten build steps, the protocol numbers that decide pass or fail, and seven checks that turn the bench into evidence you can defend.
What you are building #
One software bench, four roles, three deliverables. Each deliverable has pass criteria you can read off the screen, so the endpoint is evidence, not familiarity.
| Bench role | What it does | Tool that fills it |
|---|---|---|
| Modbus TCP server (the simulated device) | Serves coils and holding registers to any master | The Modbus Server Simulation app for Windows simulates a Modbus TCP/IP server for testing masters, PLCs and SCADA; the free-modbus-tools collection lists open-source server simulators |
| Modbus TCP client (the master) | Reads and writes those tables | QModMaster, a free Qt-based master for Modbus RTU and TCP on Windows and Linux; the Simply Modbus client tool turns a Windows PC into a Modbus TCP client |
| Data source and OPC UA server | Publishes the same values as a browsable tag tree | Node-RED with the node-red-contrib-opcua-compact-server node, a programmable OPC UA server that exposes Node-RED data from PLCs, MQTT, Modbus or databases |
| SCADA client | Tags, one screen, alarms, one trend | Any SCADA package with a trial or learning edition |
Two more options worth knowing. MBServer bundles both client and server Modbus TCP functionality in one collection. And if you program S7 controllers, the offline simulator in your engineering environment can replace the Node-RED source; what STEP 7 is in a PLC project, and which one you need sorts out those packages before you install anything.
The build, in ten steps #
- Fix the addresses first. Run everything on the loopback address 127.0.0.1; add a host-only VM subnet (for example 192.168.100.0/24, server at 192.168.100.10, SCADA client at 192.168.100.20) only when you want to practice routers, gateways or firewall rules. One safety rule covers the whole bench: it never touches the plant network, because a stray master polling a real device can disrupt a running process. Record every address and protocol role in one table.
- Map three test signals in the Modbus server: a heartbeat coil at address 0, a 16-bit counter register at holding address 0, and a raw analog value at holding address 2. Note per tool whether you are seeing the 40001-style display name or the zero-based frame address — two views of the same register.
- Make the data move. Toggle the heartbeat every second, increment the counter once per second, and park the analog register at 8192 counts for the worked example below.
- Connect the master on the loopback address, read all three points, and watch the counter climb and the heartbeat toggle. A ping proves reachability, not protocol; the first successful read is your first protocol event.
- Prove word order with a 32-bit pattern. Write the value 100000 (0x000186A0) into two consecutive holding registers: high word 0x0001, decimal 1; low word 0x86A0, decimal 34464. Read back 100000 and your word order matches. Read back 2,258,632,705 and the words are swapped, because 34,464 × 65,536 + 1 is what the swapped pattern decodes to.
- Exercise a write. Send one write-single-register transaction to a reserved scratch register, read it back, and require an exact match before moving on.
- Publish the OPC UA layer. Run Node-RED with the compact server node, feed it the same three signals, connect a test client, and browse the address space instead of typing node names from memory. Record every NodeId you bind.
- Connect the SCADA trial. Add its driver or an OPC UA connection, create tags for the three signals, and put quality, timestamp, raw value and scaled value on one commissioning view. Keep that view until every check passes.
- Add one screen, one alarm, one trend. The screen shows equipment state, the process value, a setpoint you can enter, communication status and a bad-quality banner. Configure a high alarm on the scaled analog tag — threshold from the worked example below — and a state alarm on the heartbeat; then trigger, acknowledge, clear and retrigger both. Trend the raw and scaled values together.
- Inject one fault at a time. Change one address, stop the server, then deny a tag; record what the screen showed and where the diagnostic surfaced, and restore before the next fault. One change per test is what makes a result readable.
Modbus TCP: the numbers that decide pass or fail #
The server listens on TCP port 502, so that is the port every client on this bench targets unless you deliberately change it. The MODBUS application protocol lets one read-holding-registers request carry up to 125 registers, and that limit sets your first design decision: read the whole test block in one transaction. Twenty registers polled as one block every 1,000 ms is 1 request per second; the same twenty registers polled singly are 20 requests per second — same data, twenty times the transactions. On serial RTU the same habit stalls an entire drive link; the timing math in why Modbus RTU drive polling on one serial port is slow shows the cost on real hardware.
Addressing is the classic failure. Display name 40001 is frame address 0, so a client that asks for address 1 receives 40002; a constant off-by-one at both ends means a convention mismatch, not a broken link. A 32-bit value that reads back as the swapped signature from step 5 means register order is wrong, and that order is device-specific — the test decides it, not a default. Keep the protocol's job straight, too: it moves register values between endpoints and never loads or reads your controller program, as why Modbus cannot transfer a PLC ladder program over TCP explains.
OPC UA: prove the tag path, not just the session #
The server publishes its endpoint on port 4840 by default, and the SCADA client holds a session on that endpoint. A connected session proves transport and trust, nothing more. Browse the address space and bind tags by the NodeIds you recorded in step 7; a tag that stays bad while the session is good points at namespace, NodeId, permission or data quality, in that order. If you enable message security, the client must also trust the server certificate — so a certificate failure is a connection-level fault and a bad tag is a tag-level fault, and you will never confuse the two. Decision: browse-and-bind, always, because the browse output doubles as your tag documentation.
Scaling and the alarm threshold: the worked example #
The analog channel carries raw counts 0–16383 (14-bit full scale, 2^14 − 1) representing level 0.0–250.0 mm, and step 3 parks 8192 counts in holding address 2. The SCADA tag carries the linear scale: engineering value = raw × 250.0 / 16383.
- Raw 8192: 8192 × 250.0 / 16383 = 2,048,000 / 16383 = 125.007, displayed as 125.0 mm.
- High alarm at 200.0 mm: raw equivalent = 200.0 × 16383 / 250.0 = 13,106.4 counts.
Registers hold integers, so the alarm decision splits by where it evaluates. On the scaled SCADA tag, set it at exactly 200.0 mm: the tag does the arithmetic, display and alarm agree, and the event text reads in engineering units. If the alarm must live on raw counts — in a controller that sees only the register — set it at 13,107 counts, the first whole count at or above the setpoint: 13,107 × 250.0 / 16383 = 200.01 mm, while 13,106 would trip at 199.99 mm, just under it. Keep raw and scaled side by side on the commissioning view until this check passes.
The seven checks and the evidence they leave #
The bench values below — 1,000 ms poll period, 3,000 ms timeout — are choices this article makes for the bench, not vendor defaults.
- Session: the client connects without repeated reconnect attempts.
- Heartbeat: the Boolean follows every one-second toggle, and its quality and timestamp change with it.
- Counter: after ten minutes it reads 600 at both ends (1 increment/s × 600 s); a constant difference is a convention fault, a frozen value is stale data.
- Word order: the 32-bit pattern reads back 100000, not the swapped signature.
- Scale: raw 8192 displays as 125.0 mm on the scaled tag.
- Alarm lifecycle: normal, active, acknowledged, cleared — in that order, with timestamps matching your injections, on both alarms.
- Comms loss: stop the server and the tags go to bad quality within about four seconds (one poll period plus the timeout) instead of freezing. A screen full of question marks is this exact fault, and why HMI values show question marks: PLC comms timeouts walks it on live hardware.
Keep one page per deliverable: the architecture sketch, the register and tag table, every check with its expected and observed values, and the fault log. Three pages later, that is a body of evidence, not a hobby.
When the bench hands off to hardware #
The virtual bench deliberately ends where physical behavior begins: device discovery, firmware-specific protocol behavior, scan-time effects under load, and electrical faults all need hardware in hand. That boundary is the decision point — build virtual until one of those four appears, then add hardware. When you get there, a physical PLC test bench build guide for a water SCADA project shows how the hardware step is structured. If the SCADA client will live at the line instead of on your laptop, that is the moment to specify a panel PC for the SCADA client — the same role you just built in software, packaged for the cabinet. To slot the bench into a longer plan, how to learn PLC, SCADA and DAQ from scratch sequences these skills from first simulator to first job.
Questions asked
Which Modbus function codes should the first practice project cover?
Four: FC 03 reads holding registers, FC 06 writes one register, FC 16 writes a block of registers with a protocol cap of 123 per request, and FC 05 writes a single coil. Add FC 01 and FC 02 for reading coils and discrete inputs once you simulate discrete I/O. Diagnostic, masking and file-record functions can wait until these four pass end to end on the bench.
Can the same bench practice serial Modbus RTU?
Yes. The open-source simulators listed for the bench support Modbus RTU and RTU over TCP alongside plain TCP, so switch both endpoints to RTU inside a TCP connection and you can practice slave addressing with the unit ID, request pacing and exception codes without a serial port or a null-modem cable. Expect serial rules to bite: one RTU link carries one conversation at a time, so keep the poll table small.
Do I need virtual machines, or is one session enough?
One session is enough to start: every tool listens on its own port on the same machine, the Modbus server on 502 and the OPC UA server on 4840, and the clients connect back over the loopback adapter. Add virtual machines only when you want separate subnets, a router or firewall between endpoints, or two servers on one network. Until one of those appears, a VM is setup time that teaches nothing about protocols.
How do I make the bench count in a job application?
Be ready to state three numbers from memory: the port your server listened on, the raw and scaled values from your scaling check, and the fault signature that exposed a word-order problem. Then describe one injected fault and exactly how the screen responded. That recall is what separates someone who ran the project from someone who watched a video, and it survives follow-up questions far better than a folder of screenshots.
Should OPC UA security be on for a local bench?
Connect the first time with the security policy set to None so the session itself is visible, then deliberately switch to a signed-and-encrypted policy and add the certificate-trust step. The switch is the lesson: certificate problems fail at connection time, while a wrong NodeId fails per tag after a healthy connect. Record which policy each project used, and treat unencrypted OPC UA on a plant network as the exception you justify, never the default.