How-to
How to read CompactLogix tags from a C# SCADA application
Short answer
Yes: a C# application reads a CompactLogix by acting as an EtherNet/IP client that requests the controller's symbolic tag read and write services over TCP port 44818. For ten tags, build that client directly and skip the OPC server; choose the documented Modbus TCP sample code for 5370 processors only when you need a register interface.
On this page
- How does a C# application read CompactLogix tags?
- Does the L27ERM support Modbus TCP without a gateway?
- Which data path should a ten-tag SCADA use?
- How do you build the direct EtherNet/IP client?
- Why does the read fail when the socket connects?
- How do you verify the path before you call it done?
- Does using AdvancedHMI force you to ship source?
- Questions asked
Yes — a C# SCADA can read a CompactLogix L27ERM with no HMI package and no OPC server in between. Your application acts as an EtherNet/IP client and requests the controller's symbolic tag services by tag name. The S7 protocol from your S7-1500 project, and a plain TCP socket, cannot read Logix tags; the wire protocol is different. For ten tags, build that client directly, and fall back to the documented Modbus TCP path on the 5370 family only when you want a register interface. This article walks the choice, the build order, and the verification.
How does a C# application read CompactLogix tags? #
Your C# application connects to the controller as an EtherNet/IP client on TCP port 44818, registers an encapsulation session, and then sends explicit CIP requests that carry the Logix symbolic tag read and write services, addressed by tag name. The stack has four layers, and each one must exist in your code or your library: the TCP connection to the controller's address, the encapsulation session registered over it, the explicit unconnected CIP requests carried on the session, and the conversion of the returned Logix data into C# values.
Two properties follow from that design. The unit of addressing is the tag name plus element count, not a register number — you ask for a controller-scope tag such as an illustrative Pump_Speed and receive its declared type. And "EtherNet/IP support" alone is not a claim of Logix access: a library can speak CIP for generic I/O devices and still not implement the controller's symbolic tag services, so the documentation has to name Logix tag reads specifically.
Two side paths do not apply here. Produced and consumed tags move data between Logix controllers configured in each other's I/O tree, per the Logix 5000 produced and consumed tags documentation; a C# client is not a consumer. Controllers bridge to Logix data with their own instructions — MSG on a Micro800, an S7-side instruction such as LCCF — and none of that helps a PC. The same tag services are what reading and writing Logix tags from CODESYS with CIP GenericService drives from another environment: the services are the interface, not any vendor's HMI.
Does the L27ERM support Modbus TCP without a gateway? #
Yes, with one qualification: the CompactLogix 5370 family — the L27ERM included — has a documented Modbus TCP path, but it is Rockwell's Modbus TCP Slave Sample Application loaded as controller code, not a server built into the firmware exposing tag names. The sample application's documentation covers exactly the CompactLogix 5370 processors, so treat this as a controller-side implementation task, not a feature you switch on.
In practice you import the sample logic into the controller project, your rungs copy tag data into the data areas the sample serves, and the C# side reads and writes those registers with any Modbus TCP client over TCP port 502. What you gain is a register interface any Modbus client can consume. What you pay is register allocation, the copy logic, scaling, and word-order testing for every 32-bit value; nothing on that wire carries a tag name, so the register map is yours to allocate and document.
Which data path should a ten-tag SCADA use? #
For ten tags on one PC, build the direct EtherNet/IP client: nothing extra to license, install, or keep alive, and the arithmetic below shows bandwidth is never the constraint — the choice turns on which engineering you want to own. Put numbers on the load first. Ten DINT tags carry 4 bytes each, so one full poll cycle moves 10 × 4 B = 40 B of tag data. At a 100 ms poll that is 10 cycles per second, or 40 B × 10 = 400 B/s in each direction. A 100 Mbit/s link carries 100,000,000 ÷ 8 = 12,500,000 B/s, so the tag data is 400 ÷ 12,500,000 × 100 ≈ 0.003% of the wire. Protocol overhead multiplies the payload a few times over and changes nothing: bandwidth does not decide this.
| Path | You write | You install | C# talks to | Choose it when |
|---|---|---|---|---|
| Direct EtherNet/IP client | Session handling, tag services, type conversion, timeouts, reconnect | Nothing beyond your application | The controller, by tag name | One PC and a handful of tags — this build |
| Modbus TCP sample code | Register mapping and copy logic in the controller | The sample application in the controller project | The controller, by register number | A proven Modbus client exists, or the plant requires a register interface |
| OPC server | OPC client code | A separate server component, traditionally licensed | The server, by OPC item | Several different consumers need the same data |
The decision for your case: one C# panel, ten tags — build the direct client. Use the Modbus sample when the C# side already has a working Modbus client or the plant standard is registers. Use OPC when more than one kind of consumer needs the same data. The station itself can be any Windows machine you control at the machine; many plants standardize on an industrial panel PC so the SCADA client and the operator share one screen.
How do you build the direct EtherNet/IP client? #
Build in this order: prove the endpoint, get a client layer that documents Logix tag reads, write a ten-row tag contract, make one scalar read work, then add batching, failure handling, and writes last. Each step below closes one failure mode before the next can hide it.
- Prove the endpoint. Read the controller's IP address from the project or module diagnostics, confirm the C# host has a route to that subnet, and rule out a duplicate address before anything else.
- Get a Logix-capable client layer. Either implement the encapsulation session and symbolic tag services yourself, or pick a library whose documentation names Logix tag reads and writes explicitly; "EtherNet/IP" alone can mean generic I/O connections only.
- Write the tag contract. Ten rows: exact tag name (case-sensitive), controller or program scope, Logix type, C# type, read or write, poll period. Map the common types explicitly: DINT to
int, INT toshort, REAL tofloat, BOOL tobool. - Make one scalar read work. Use a controller-scope DINT whose value you can watch change in the programming software; arrays, strings, user types, and program-scope paths come after that first transaction succeeds.
- Batch the cycle. Request all ten tags in one cycle rather than ten independent round trips; one transaction means one timeout path and one stale flag to maintain.
- Add bounded failure handling. Start with a 1,000 ms request timeout, mark values stale with the time of the last good poll, close failed sessions, reconnect with a delay rather than a tight loop, and keep all of it off the UI thread.
- Add writes last. Range-check and authorize the value in the panel, and interlock it in the controller logic, because a request arriving over the network earns no trust by itself — especially on a controller that runs a machine. Write, read back, and compare the two.
Why does the read fail when the socket connects? #
Work bottom-up: reachability, controller state, the stage where the client fails, then the tag name and type — in that order, because every step is cheap and the layer above it is meaningless until the layer below passes. A connected socket only proves the network path; everything between the session and the tag decode is still untested.
- Reachability. IP address, subnet mask, route, and a duplicate-address check — ping first, always.
- Controller state. The controller must be up with no fault on its Ethernet interface; a faulted or cycling interface explains every symptom above it.
- Failure stage. Log whether the client dies at TCP connect, session registration, the tag request, or decoding the reply — each names a different fix.
- Tag name and scope. Names are case-sensitive, and a program-scope tag needs its program path; a controller-scope tag is the correct first test.
- Type and element count. The requested type and element count must match the controller's declaration exactly, or the request is rejected.
- Traffic capture. When the library returns only a generic timeout, capture packets at the PC: did the request leave, did an answer return, did something between the two drop the exchange.
Every failure on this list looks identical on a panel: values stop updating. That is the same condition behind why HMI values show question marks when PLC comms time out, and the operator sees it before your log does.
How do you verify the path before you call it done? #
Verify three things before you sign it off: every value matches the online controller across its type range, every write reads back through the process logic, and a pulled cable marks data stale within three poll cycles and recovers cleanly.
- Value fidelity. Compare each of the ten values against the online tag in the programming software at zero, negative, and full-scale values the type permits; a DINT that displays correctly at 25 can still decode wrong at negative values.
- Write round-trip. Command a safe test value, read it back, and confirm the process logic neither clamped nor overwrote it.
- Failure and recovery. Pull the cable, confirm every displayed value is marked stale within three poll cycles, restore the link, and confirm recovery without stacked sessions. Three consecutive failed cycles is also the right alarm threshold — a single missed poll is noise — and a SCADA PLC communication alarm for link loss shows the pattern to build for it.
Does using AdvancedHMI force you to ship source? #
Yes — AdvancedHMI is distributed under a GPL-family license, and those terms require you to pass the corresponding source, modifications included, to your end user; if that does not fit how you ship, use your own client, the Modbus sample path, or a commercially licensed driver. The obligation travels with the code, so the decision is made when you choose the library, not when the panel ships.
Writing your own client keeps third-party terms out of the project only if every package you reference is permissively licensed; check each one before you sign off the station. The Modbus sample code carries the terms the vendor attaches to that sample — read the document that ships with it before loading it into a production controller. Shipping GPL-family code inside a closed package is the one path to rule out; the other three are all legitimate engineering choices.
Questions asked
Can I reuse my S7-1500 C# code for the CompactLogix?
Only the screen and architecture layers. The S7 protocol and EtherNet/IP are different wire protocols: different framing, different addressing, different data services. The socket class and the display code carry over; everything from the session handshake to the type conversion is new code for the Logix controller.
Is the Modbus TCP sample faster to get working?
Usually slower for ten tags. The direct client adds protocol code once on the PC; the Modbus path adds controller-side copy logic, register allocation, and word-order testing on both ends. Pick it only when a proven Modbus client already exists on the C# side or the plant standard demands a register interface.
How often should a ten-tag SCADA poll the controller?
Poll every 100 to 500 ms. Ten DINT tags are 40 bytes per cycle, so even a 100 ms poll moves 400 bytes per second of tag data, a rounding error on a 100 Mbit/s link. Request all ten tags in one cycle rather than sending ten single reads.
Do program-scope tags need different handling?
Yes. They are reached through their program path rather than a bare tag name, and the spelling is case-sensitive. Prove the first read on a controller-scope tag you can watch in the programming software, then add program-scope paths to the tag contract one at a time.
Does an OPC server remove the C# work?
It moves it. You trade protocol code for OPC client code plus a separate server component, which has traditionally been a licensed product on these controllers. With one PC and ten tags the direct client is the smaller system to own; OPC earns its place when several different consumers need the same data.