Posts tagged modbus

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.

adressing

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.

communication

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

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusClient('192.168.88.88', port=502)
client.connect()

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)

client.close()

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apachebench, apple, arcconf, arch, architecture, areca, arping, asa, asdm, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, 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, coleslaw, colorscheme, common lisp, 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, fbsd, fedora, file, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, github, gitolite, 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, 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, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pvecm, pvresize, python, qemu, qemu-img, qm, qmrestore, quicklisp, 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, 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, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

View posts from 2017-03, 2017-02, 2017-01, 2016-12, 2016-11, 2016-10, 2016-09, 2016-08, 2016-07, 2016-06, 2016-05, 2016-04, 2016-03, 2016-02, 2016-01, 2015-12, 2015-11, 2015-10, 2015-09, 2015-08, 2015-07, 2015-06, 2015-05, 2015-04, 2015-03, 2015-02, 2015-01, 2014-12, 2014-11, 2014-10, 2014-09, 2014-08, 2014-07, 2014-06, 2014-05, 2014-04, 2014-03, 2014-01, 2013-12, 2013-11, 2013-10


Unless otherwise credited all material Creative Commons License by sjas