Modbus TCP

Hello,

I 've readen some post but no response. I try to develop a soft to command an logic controler

The communication protocol is modbus TCP

Is somebody have class to communicate in modbus TCP or tips to make it

thanks in advance

Noel

Noel,

I have used a C library on Github that provides support for Modbus TCP and EtherNet/IP. I have not used the Modbus TCP portion but the EtherNet/IP works very well with Rockwell ControlLogix PLCs. The Github URL is:
https://github.com/libplctag/libplctag

I’ve written a Xojo wrapper module for the library. You can get it at:
libplctag
The wrapper is written for version 2.3 but it should work for the current 2.4 version. I usually put the dll file in the same folder as the executable.

Dennis

Hello @Noel_Wetischek !

You’ll notice that whenever someone posts about Industrial Automation there are only a small handful of us that work in this industry, so the replies aren’t as rapid as on other topics.

I’ve done a great amount of programming for Modbus RTU, and it’s my understanding that Modbus TCP/IP is basically “Modbus RTU over IP”… or so I hear.

I’m overdue to look into this topic so I’ll start digging now and see if there isn’t some help I can offer.

Welcome to the Forum by the way!

Hi Noel,

I’m taking a look at the official spec on this (Modbus_Messaging_Implementation_Guide_V1_0b.pdf) and it’ll take me several reads to absorb and not fall asleep. I’ll also likely find some software that emulates a Modbus TCP/IP “Client” (formerly referred to as “Master”) that’s intended for use debugging “Server” nodes. And I’m headed out for a week holiday with family, so it’s unlikely I’ll have more to contribute to this thread till after the 29th of the month. However, I really do hope I can be of help. My company has a need to fully understand and work with this protocol - so it’s something I plan on sticking to. Best of luck for now!

William,

This page, http://www.dalescott.net/modbus-development/ has a good listing of Modbus simulators. Worth checking out.

By the way, I confirmed my Xojo wrapper for the libplctag library (see my earlier post) does work with version 2.4 of the library. If you are on Windows, the 2.4 version is worthwhile since Windows performance has been improved.

Dennis

Thanks a lot Dennis and William

I’ll try your wrapper soon.

I have first to understand how to call/load the external library

Noel

Hi @Dennis_Hoskins

Is the wrapper still around ? The Google link seems to be not working :folded_hands:

Many Thanks :grinning_face:

Hi there,
I made this small library / app to connect to my hitachi heat pump using modbus
it is a reusable library all written in xojo.
hope this helps.
tested on macos only but should work on other platforms

VNS Xojo Modbus 1.1 — Modbus TCP and RTU for Xojo, free (MIT)

Hello all,

VNS Xojo Modbus is a free, open-source (MIT) Modbus client library written in pure Xojo
(API 2) — no plugin, no native library, no Declare. Version 1.1 is out:

:backhand_index_pointing_right: GitHub - JYPochez/VNS-Xojo-Modbus: a small library and example Xojo app to connect to a device using Modbus · GitHub

In one minute

Drag a ModbusTCPClient onto your window, fill in its events in the IDE, and read:

ModbusClient1.Address = "192.168.1.50"
ModbusClient1.ReadHoldingRegisters(0, 10)   ' connects by itself

' ModbusClient1.RequestCompleted(request As ModbusRequest)
For i As Integer = 0 To request.Values.LastIndex
  System.DebugLog(request.Values(i).ToString)
Next
  • Asynchronous and event-driven, never blocks the UI; no AddHandler needed.
  • Request queue, timeouts, automatic reconnection, readable error messages.
  • 16 / 32 / 64-bit values, signed, unsigned and float, in the four word orders.
  • Describe a whole device as a plain-text table of points (hr1080:int16, ir30:float32:cdab,
    co5, hr1089.4) with scaling, units, labels, “no data” values and write ranges, and let the
    poller read them in as few requests as possible.

New in 1.1

  • Modbus RTU over a serial line: ModbusRTUClient, a SerialConnection subclass with the same
    API as the TCP client — CRC-16, frame timing, broadcast writes, an option for RS-485 adapters
    that echo what they send, and a trace of every frame.
  • More function codes, on both clients: 22 Mask Write Register, 23 Read/Write Multiple
    Registers, 08 / 00 loopback (Return Query Data), 17 Report Server ID, 43 / 14 Read
    Device Identification (vendor, product, revision…). Supported now: 01–06, 08, 15, 16, 17, 22,
    23, 43.
  • A ModbusTransport interface: the same poller works over TCP or RTU.
  • Two apps in the repository:
    • VNS Modbus TCP — a complete app for a Hitachi airH2O / Yutaki heat pump (123 registers,
      monitoring and guarded writes), the worked example of the library;
    • VNS Modbus RTU — a generic serial Modbus tester: pick the port and line settings, send any
      function, see the values and the raw frames in hex, save a log.
  • A developer guide (step by step + full API reference) and a Modbus protocol reference
    (TCP / RTU frames, every function’s layout, exceptions, limits).

VNS Modbus RTU tester

:warning: Looking for RTU testers

The RTU part has not been tested on a real device: I don’t have a serial Modbus device. The
frames and CRCs are checked against reference values by the self-test, and everything compiles
and runs on macOS, but nothing has been tried on a real RS-485 / RS-232 line yet.

If you have a Modbus RTU device (meter, PLC, inverter, sensor…) and a USB serial adapter, could
you give VNS Modbus RTU a try? There is a short test list in
docs/RTU_TESTING.md —
start with the loopback (FC 08), which touches no register. Save log… produces a report with
the versions, settings and every frame; post it here or open a GitHub issue. “It works” is a
useful answer too!

Status

  • Xojo 2026r2.1 or later. Tested on macOS (desktop and console), TCP against a simulator
    and a real Hitachi ATW-MBS-02 gateway. Windows and Linux use no platform-specific code but have
    not been tried yet — reports welcome.
  • A Python Modbus TCP simulator is included in tools/, so you can try everything without
    hardware.

Feedback, questions and pull requests welcome.

Jean-Yves

@Jean-Yves_Pochez what perfect timing! I’m doing a rebuild of some devices that have both Modbus TCP and RTU. This is a busy week, but I will do my utmost best to assist you - and very much appreciate your no-plug-in approach!