Connecting Schneider M340 / M221 / M241 to the cloud via Modbus TCP
This guide covers the complete setup process for connecting Schneider Modicon-series PLCs to the Eziwan platform: M340 (BMX P34), M221, M241, M251, and M262. Each series has its own specific configuration requirements.
Schneider Compatibility Chart
M340 Series (BMX P34)
| CPU | Firmware | %MW accessible | ETH Module | CPU Unit ID |
|---|---|---|---|---|
| BMX P34 1000 | ≥ 2.30 | 0..1023 (1,024 words) | BMX NOE or ETH module | 255 |
| BMX P34 2010 | ≥ 2.30 | 0..9999 (10,000 words) | Integrated ETH | 255 |
| BMX P34 2020 | ≥ 2.30 | 0..9999 | Integrated ETH | 255 |
| BMX P34 2030 | ≥ 2.30 | 0..9999 | Integrated ETH | 255 |
M221 Series (TM221)
| CPU | Firmware | % of MWs accessible | Unit ID |
|---|---|---|---|
| TM221CE16R | ≥ 1.0 | 0..9999 | 1 |
| TM221C16T | ≥ 1.0 | 0..9999 | 1 |
| TM221ME16R (Ethernet) | ≥ 1.0 | 0..9999 | 1 |
| TM221M16R (+ ETH module) | ≥ 1.0 | 0..9999 | 1 |
M241 Series (TM241)
| CPU | Firmware | %MW accessible | Unit ID |
|---|---|---|---|
| TM241CE40R | ≥ 1.0 | 0..9999 | 1 |
| TM241CE40T | ≥ 1.0 | 0..9999 | 1 |
| TM241C40R (+ TMBM module) | ≥ 1.0 | 0..9999 | 1 |
M251 and M262 Series
| CPU | Firmware | Protocols | Unit ID |
|---|---|---|---|
| TM251MESE | ≥ 1.0 | Modbus TCP, EtherNet/IP | 1 |
| TM262M15MESS8T | ≥ 1.0 | Modbus TCP, EtherNet/IP, native MQTT | 1 |
The M262 has a native MQTT client—Eziwan can directly receive data published by the M262 without going through Modbus polling. Contact Eziwan support for MQTT configuration.
EcoStruxure Configuration — M340 Series
Enabling the Modbus TCP Server on the BMX P34
In EcoStruxure Control Expert (Unity Pro):
- Structure View → double-click on the
BMX P34 xxxxCPU - "Configuration" tab → click on the Ethernet interface (ETH 1 or NOE module)
- "Services" tab → check "Modbus Server" ✓
- Port: 502 (do not change unless necessary)
- "Ethernet Addresses" tab → enter the static IP address
Advanced Settings (recent firmware versions):
- Inactive connection timeout: increase to 120s (default 30s) for long-running connections
- IP filtering (firmware ≥ 2.60): restrict access to the Eziwan gateway’s IP address
BMX NOE 0100 / BMX NOE 0110 Module
For M340 models with an external Ethernet module:
| Parameter | BMX NOE 0100 | BMX NOE 0110 |
|---|---|---|
| Data Rate | 10/100 Mbit | 10/100 Mbit |
| I/O Scanner | No | Yes |
| Modbus Server | Yes | Yes |
| Configuration | Via CPU Properties | Via Module Properties |
| Unit ID | Configurable | Configurable |
On the BMX NOE 0110, the Modbus TCP server may have a Unit ID other than 255. Check the module's configuration in EcoStruxure and use the Unit ID configured in Eziwan.
EcoStruxure Configuration — M221 / M241 Series
SoMachine / EcoStruxure Machine Expert
Modbus TCP configuration on the M221 and M241 is performed in EcoStruxure Machine Expert (formerly SoMachine):
- Configuration → "Ethernet" tab
- Enter the static IP address and subnet mask
- Configuration → "Modbus TCP Slave" tab (or "Modbus TCP Servant")
- Check "Enabled" ✓
- Port: 502
- Unit ID: 1 (default on M221/M241 — different from the M340!)
Key Difference Between the M340 and the M221/M241
| Parameter | M340 (BMX P34) | M221 / M241 (TM2xx) |
|---|---|---|
| Default Unit ID | 255 | 1 |
| Configuration software | EcoStruxure Control Expert | EcoStruxure Machine Expert |
| Max %MW | 10,000 (CPU >= 2010) | 9,999 |
| Modbus server | Enabled in CPU properties | Enabled in Ethernet configuration |
This is the most common pitfall: if you configure Eziwan with Unit ID 255 on an M221 or M241, the connection will fail with a Modbus exception or a timeout. Use Unit ID 1 on the M221/M241.
Modbus Register Addressing by Range
M340 — %MW Mapping ↔ Modbus Register
Variable EcoStruxure │ Adresse Modbus │ Type Modbus
─────────────────────────────────────────────────────
%MW0 │ 0 │ Holding Register (FC=03)
%MW100 │ 100 │ Holding Register
%MWn │ n │ (direct, 0-based)
%QW0.0 │ 0 │ Input Register (FC=04) *
%IW0.0 │ 0 │ Discrete Input (FC=02) *
%Q0.0 to %Q0.7 │ bits 0 through 7 │ Coil (FC=01)
*The exact mapping of analog inputs and outputs depends on the hardware configuration.
M221 / M241 — %MW Mapping ↔ Modbus Register
The mapping is the same as for the M340: %MWn corresponds to the Modbus address n.
Advanced Data Type Management
REAL Variables (32-bit floating-point) in 2 Registers
A variable named REAL in Unity Pro / EcoStruxure occupies two consecutive %MW units in IEEE 754:
REAL variable "Temperature" stored at %MW100:
%MW100: most significant word (MSW, bytes A and B)
%MW101: low-weight word (LSW, bytes C and D)
Order: ABCD (big-endian by default on M340/M221/M241)
Eziwan type to configure: float32_abcd
If the values are incorrect (constant error factor):
Try float32_cdab (little-endian per register). Some Unity Pro projects use the DWORD_TO_REAL function with a different order.
DINT / UDINT variables (32-bit integer) across 2 registers
DINT variable "Counter" at %MW200:
%MW200 : partie haute (MSW)
%MW201 : partie basse (LSW)
Type Eziwan : int32_abcd
Boolean Compression in a %MW
To minimize the number of Modbus requests, group the Boolean states into a single memory word:
(* EcoStruxure Control Expert — Programme *)
(* Group of 16 states in %MW300 *)
%MW300 := 0; (* Reset *)
IF %Q0.0 THEN %MW300 := %MW300 OR 16#0001; END_IF; (* Pump 1 *)
IF %Q0.1 THEN %MW300 := %MW300 OR 16#0002; END_IF; (* Pump 2 *)
IF %I0.5 THEN %MW300 := %MW300 OR 16#0004; END_IF; (* P1 error *)
IF %I0.6 THEN %MW300 := %MW300 OR 16#0008; END_IF; (* P2 error *)
IF %M10 THEN %MW300 := %MW300 OR 16#0010; END_IF; (* Alarme *)
With this technique, 16 Booleans can be read with a single Modbus query (FC=03, 1 register).
Recommended Organization of %MW for Monitoring
To maximize query efficiency (automatic grouping by Eziwan):
Range %MW0 to %MW9 : Operator setpoints (editable)
Range %MW10 to %MW49 : Simple analog measurements (int16 ×10)
Range %MW50 to %MW99: Dual analog measurements (REAL in 2 registers)
Range %MW100 to %MW149: 16-bit counters
Range %MW150 to %MW199: 32-bit counters (DINT, 2 registers each)
Range %MW200 to %MW249: Machine states (bitfields)
Range %MW250 to %MW299: Error codes
Range %MW300 to %MW349: Manufacturer settings (read-only for customers)
Connection Test
Testing from Python
from pymodbus.client import ModbusTcpClient
import struct
def tester_connexion_schneider(ip: str, unit_id: int = 255):
"""
Test de connexion Modbus TCP.
unit_id : 255 pour M340, 1 pour M221/M241
"""
client = ModbusTcpClient(ip, port=502, timeout=3)
if not client.connect():
print(f"✗ Connexion TCP impossible à {ip}:502")
return
print(f"✓ Connexion TCP établie → {ip}:502 (Unit ID {unit_id})")
# Reading Test: %MW100 to %MW109
result = client.read_holding_registers(
address=100, count=10, slave=unit_id
)
if not result.isError():
print(f"✓ Modbus FC=03 OK — %MW100 à %MW109 : {result.registers}")
# Decoding float32 if %MW100+101 contains a REAL (test)
if len(result.registers) >= 2:
raw = struct.pack(">HH", result.registers[0], result.registers[1])
float_val = struct.unpack(">f", raw)[0]
if abs(float_val) < 1e6: # Valeur plausible ?
print(f" → Si %MW100-%MW101 est un REAL : {float_val:.2f}")
else:
exc = getattr(result, 'exception_code', '?')
print(f"✗ Erreur Modbus FC=03 — exception code: {exc}")
# Diagnostics selon le code
messages = {
1: "Unsupported FC → Modbus server not enabled",
2: "Adresse invalide → plage %MW dépassée (M340 1000: max 1024)",
3: "Valeur invalide → count trop grand",
4: "Erreur serveur → serveur non initialisé, CPU en STOP",
6: "Serveur occupé → trop de connexions simultanées",
}
if exc in messages:
print(f" Diagnostic : {messages[exc]}")
client.close()
# Tests
tester_connexion_schneider("192.168.1.20", unit_id=255) # M340
tester_connexion_schneider("192.168.1.30", unit_id=1) # M221/M241
Advanced Troubleshooting
| Symptom | Probable Cause | Solution |
|---|---|---|
| TCP connection refused | Modbus server not enabled | Check "Modbus Server" in EcoStruxure |
| TCP connection refused | Network misconfigured | Ping the PLC from a PC on the same network |
| Exception 02 (invalid address) | BMX P34 1000 — address > 1023 | Shift the supervision zone between 0 and 1023 |
| Exception 06 (server busy) | Too many clients connected | Close unused local SCADA connections |
| Incorrect Unit ID | M221/M241 with Unit ID 255 | Change to Unit ID 1 in the Eziwan configuration |
| All values set to 0 | Variables not assigned in the program | Verify that %MW100+ are powered by the program |
| Incorrect REAL | CDAB byte order instead of ABCD | Try float32_cdab in Eziwan |
| Disconnects every 30 seconds | Default M340 idle timeout | Increase "idle timeout" to 120s in EcoStruxure |
| NOE module not responding | Module IP different from CPU | Use the NOE module’s IP, not the CPU’s |
| %IW and %QW registers inaccessible | FC=04 or FC=01 required, not FC=03 | Use the appropriate FCs or copy to %MW |
- Modbus TCP with a Schneider M340 — Complete Guide — detailed configuration and frame structure
- Modbus TCP/IP Guide — Python code and protocol comparison
- Download the Schneider compatibility sheet → — PDF with all tested models
- Technical support →
Frequently Asked Questions
Which Schneider PLCs are compatible?
The entire Modicon product line that communicates via Modbus TCP: M221, M241, M251, M340, M580, as well as the Premium and Quantum models equipped with Ethernet couplers. The serial-based series (Twido, TSX) connect via the gateway’s RS-485 port.
Should the PLC program be modified?
Not for reading data: the gateway queries the existing %MW words in Modbus TCP. Only when writing setpoints, if necessary, may it be necessary to reserve a dedicated range of words in the program.
Which network port should be accessible?
Modbus TCP port 502 is used only on the local network between the gateway and the PLC. Nothing is exposed to the Internet: the gateway establishes an outbound VPN tunnel to the cloud.
How do you diagnose a connection that isn't working?
Check the following in this order: ping the PLC from the gateway, ensure port 502 is open (no local firewall), verify the Unit ID is correct, and ensure the %MW addressing is aligned (offset 0 vs. 1 depending on the tools). The Eziwan console displays Modbus frames and error codes in real time.
Related Resources
- Remote Access to Schneider PLCs — Secure Remote Access to EcoStruxure
- Connecting an M340/M221 to the Cloud — Step-by-Step Guide
- Complete Modbus Guide — Registers, Functions, and Troubleshooting
- Modbus to the Cloud — The Modbus Data Collection Solution
- Connecting a PLC to the cloud — all supported brands