Modbus Adaptor

Introduction

Modbus is a master/slave protocol, the device requesting the information is called the Modbus master and the devices supplying information are Modbus slaves. In a standard Modbus network, there is one master and up to 247 slaves, each with a unique slave address from 1 to 247. The master can also write information to the slaves.

Modbus adaptor implements the goburrow/modbus to support both TCP and RTU protocols, it acting as the controller(master) node and connects to or manipulating the Modbus worker(slave) devices on the edge side.

Modbus Registers Operation

  • Coil Registers: readable and writable, 1 bit (off/on)

  • Discrete Input Registers: readable, 1 bit (off/on)

  • Input Registers: readable, 16 bits (0 to 65,535), essentially measurements and statuses

  • Holding Registers: readable and writable, 16 bits (0 to 65,535), essentially configuration values

Registration Information

VersionsRegister NameEndpoint SocketAvailable
v1alpha1adaptors.edge.cattle.io/modbusmodbus.sock*

Support Model

KindGroupVersionAvailable
ModbusDevicedevices.edge.cattle.iov1alpha1*

Support Platform

OSArch
linuxamd64
linuxarm
linuxarm64

Usage

$ kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/modbus/deploy/e2e/all_in_one.yaml

Authority

Grant permissions to Octopus as below:

Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
modbusdevices.devices.edge.cattle.io [] [] [create delete get list patch update watch]
modbusdevices.devices.edge.cattle.io/status [] [] [get patch update]

Example

  • Specifies a ModbusDevice device link to connect a serial port thermometer.

    apiVersion: edge.cattle.io/v1alpha1
    kind: DeviceLink
    metadata:
    name: modbus-rtu
    spec:
    adaptor:
    node: edge-worker
    name: adaptors.edge.cattle.io/modbus
    model:
    apiVersion: "devices.edge.cattle.io/v1alpha1"
    kind: "ModbusDevice"
    template:
    metadata:
    labels:
    device: modbus-rtu
    spec:
    parameters:
    syncInterval: 10s
    timeout: 10s
    protocol:
    rtu:
    endpoint: /dev/tty.usbserial-1410
    workerID: 1
    parity: "N"
    stopBits: 2
    dataBits: 8
    baudRate: 9600
    properties:
    - name: temperature
    description: data collection of temperature sensor
    readOnly: true
    visitor:
    register: HoldingRegister
    offset: 0
    quantity: 1
    orderOfOperations:
    - type: Divide
    value: "10"
    type: float

For more ModbusDevice device link examples, please refer to the deploy/e2e directory and make a quick experience with deploy/e2e/simulator.yaml.

ModbusDevice

ParameterDescriptionSchemaRequired
metadatametav1.ObjectMetafalse
specDefines the desired state of ModbusDevice.ModbusDeviceSpectrue
statusDefines the observed state of ModbusDevice.ModbusDeviceStatusfalse

ModbusDeviceSpec

ParameterDescriptionSchemaRequired
extensionSpecifies the extension of device.*ModbusDeviceExtensionfalse
parametersSpecifies the parameters of device.*ModbusDeviceParametersfalse
protocolSpecifies the protocol for accessing the device.*ModbusDeviceProtocoltrue
propertiesSpecifies the properties of device.[]ModbusDevicePropertyfalse

ModbusDeviceStatus

ParameterDescriptionSchemaRequired
propertiesReports the properties of device.[]ModbusDeviceStatusPropertyfalse

ModbusDeviceParameters

ParameterDescriptionSchemaRequired
syncIntervalSpecifies the amount of interval that synchronized to limb, default to 15s.stringfalse
timeoutSpecifies the amount of timeout, default to 10s.stringfalse

ModbusDeviceProtocol

ParameterDescriptionSchemaRequired
rtuSpecifies the connection protocol as RTU.*ModbusDeviceProtocolRTUfalse
tcpSpecifies the connection protocol as TCP.*ModbusDeviceProtocolTCPfalse

ModbusDeviceProtocolRTU

ParameterDescriptionSchemaRequired
endpointSpecifies the serial port of device, which is in form of "/dev/ttyS0".stringtrue
workerIDSpecifies the worker ID of device.inttrue
baudRateSpecifies the baud rate of connection, a measurement of transmission speed, default to 19200.intfalse
dataBitsSpecifies the data bit of connection, selected from [5, 6, 7, 8], default to 8.intfalse
paritySpecifies the parity of connection, selected from [N - None, E - Even, O - Odd], the use of N(None) parity requires 2 stop bits, default to E.stringfalse
stopBitsSpecifies the stop bit of connection, selected from [1, 2],the use of N(None) parity requires 2 stop bits, default to 1.intfalse

ModbusDeviceProtocolTCP

ParameterDescriptionSchemaRequired
endpointSpecifies the IP address of device, which is in form of "ip:port".stringtrue
workerIDSpecifies the worker ID of device.inttrue

ModbusDeviceProperty

ParameterDescriptionSchemaRequired
nameSpecifies the name of property.stringtrue
descriptionSpecifies the description of property.stringfalse
typeSpecifies the type of property.ModbusDevicePropertyTypetrue
visitorSpecifies the visitor of property.*ModbusDevicePropertyVisitortrue
readOnlySpecifies if the property is readonly., default to false.booleanfalse
valueSpecifies the value of property, only available in the writable property.stringfalse

ModbusDeviceStatusProperty

ParameterDescriptionSchemaRequired
nameReports the name of property.stringfalse
typeReports the type of property.ModbusDevicePropertyTypefalse
valueReports the value of property.stringfalse
updatedAtReports the updated timestamp of property.*metav1.Timefalse

ModbusDevicePropertyType

ParameterDescriptionSchema
stringProperty data type is string.string
intProperty data type is int.string
floatProperty data type is float.string
booleanProperty data type is boolean.string

ModbusDevicePropertyVisitor

ParameterDescriptionSchemaRequired
registerSpecifies the register to visit.ModbusDeviceRegisterTypetrue
offsetSpecifies the starting offset of register for read/write data.inttrue
quantitySpecifies the quantity of register.inttrue
orderOfOperationsSpecifies the operations in order if needed.[]ModbusDeviceArithmeticOperationfalse

ModbusDeviceRegisterType

ParameterDescriptionSchema
CoilRegisterReadable and writable, 1 bit (off/on).string
DiscreteInputRegisterReadonly, 1 bit (off/on).string
InputRegisterReadonly, 16 bits (0 to 65,535), essentially measurements and statuses.string
HoldingRegisterReadable and writable, 16 bits (0 to 65,535), essentially configuration values.string

ModbusDeviceArithmeticOperation

ParameterDescriptionSchemaRequired
typeSpecifies the type of arithmetic operation.ModbusDeviceArithmeticOperationTypefalse
valueSpecifies the value for arithmetic operation, which is in form of float string.stringfalse

ModbusDeviceArithmeticOperationType

ParameterDescriptionSchema
AddArithmetic operation of add.string
SubtractArithmetic operation of subtract.string
MultiplyArithmetic operation of multiply.string
DivideArithmetic operation of divide.string

ModbusDeviceExtension

ParameterDescriptionSchemaRequired
mqttSpecifies the MQTT settings.*v1alpha1.MQTTOptionsSpecfalse