Posts tagged rs0485

modbus basics

posted on 2016-07-05 14:11

Here is a handful of facts I came across lately, in no particular order. Also you really really should read this link and the wiki pages.


The following are the data types at specific memory adresses with which you can work with via the bus system.

  • discrete inputs: RO boolean, size: 1 bit
  • input registers: RO integer, size: 16 bits, for measurements / statuses
  • coil: RW boolean, size: 1 bit
  • holding registers: RW integer, size: 16 bits, essentially configuration values

master / slave vs. client / server

There can only be one server on the bus. Multimaster = recipe for disaster, from what I read until now.

A modbus client is basically a master. With it you query the one of the slaves / servers for data. You either get a register's content, or set it, depending on its type. (See above.)

communication types

There exist several:

  • Modbus ASCII: basically plaintext, but slower, used mainly on 7- or 8-bit serial lines
  • Modbus RTU: 'remote terminal unit', used mainly on 8-bit async lines like EIA-485/RS485
  • Modbus TCP: same as RTU, but checksumming is done through TCP, usually TCP port 502 is used, for ethernet networks

Further Modbus requests can be transferred via UDP, too.

They all differ in how the requests have to be structured.


All types of communication with the bus transport the following information, plus/minus their specific headers and start/stop bits.

  • address
  • function
  • data

example with pymodbus library

Plain copy paste, without further comments:

from pymodbus.client.sync import ModbusTcpClient as ModbusClient

import logging

log = logging.getLogger()

client = ModbusClient('', port=502)

r0  =  client.read_holding_registers(0,1,unit=0x01)
r1  =  client.read_holding_registers(1,1,unit=0x01)
r2  =  client.read_holding_registers(2,1,unit=0x01)
r3  =  client.read_holding_registers(3,1,unit=0x01)
r4  =  client.read_holding_registers(4,1,unit=0x01)
r5  =  client.read_holding_registers(5,1,unit=0x01)
r6  =  client.read_holding_registers(6,1,unit=0x01)
r7  =  client.read_holding_registers(7,1,unit=0x01)
r8  =  client.read_holding_registers(8,1,unit=0x01)
r9  =  client.read_holding_registers(9,1,unit=0x01)
r10 = client.read_holding_registers(10,1,unit=0x01)
r11 = client.read_holding_registers(11,1,unit=0x01)
r12 = client.read_holding_registers(12,1,unit=0x01)
r13 = client.read_holding_registers(13,1,unit=0x01)
r14 = client.read_holding_registers(14,1,unit=0x01)
r15 = client.read_holding_registers(15,1,unit=0x01)
r16 = client.read_holding_registers(16,1,unit=0x01)
r17 = client.read_holding_registers(17,1,unit=0x01)
r18 = client.read_holding_registers(18,1,unit=0x01)
r19 = client.read_holding_registers(19,1,unit=0x01)
r20 = client.read_holding_registers(20,1,unit=0x01)
r21 = client.read_holding_registers(21,1,unit=0x01)
r22 = client.read_holding_registers(22,1,unit=0x01)
r23 = client.read_holding_registers(23,1,unit=0x01)
r24 = client.read_holding_registers(24,1,unit=0x01)
r25 = client.read_holding_registers(25,1,unit=0x01)
r26 = client.read_holding_registers(26,1,unit=0x01)
r27 = client.read_holding_registers(27,1,unit=0x01)
r28 = client.read_holding_registers(28,1,unit=0x01)
r29 = client.read_holding_registers(29,1,unit=0x01)
r30 = client.read_holding_registers(30,1,unit=0x01)


This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, 16.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, PS1, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apache2.4, apachebench, apple, applet, arcconf, arch, architecture, areca, arping, asa, asdm, autoconf, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blockdev, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, cmd, coleslaw, colorscheme, common lisp, configuration management, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fakeroot, fbsd, fdisk, fedora, file, files, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, gitbucket, github, gitolite, global, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, innodb, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, make-jpkg, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pct, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plasma, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pveam, pvecm, pvesm, pvresize, python, python3, qemu, qemu-img, qm, qmrestore, quicklisp, quickshare, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, ubuntu16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x11vnc, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

Unless otherwise credited all material Creative Commons License by sjas