Skip to content

lib-modbus 库参考 ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793750634/FIN+5.3.1+lib-modbus 中文整理基于 FIN 5.3.1

导读: 本页为 lib-modbus 的 API / 标签 / 函数参考文档。

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • lib
  • meta
  • docs
  • tags
  • funcs
  • views
  • Overview
  • Supported Protocols
    • TCP/IP
    • RTU over TCP/IP
  • Register Map
    • Addressing
    • Ping
    • Data Type
    • Read/Write
    • Scale Factor
    • Dis, Unit, Tags
  • Current Points
  • Writable Points
  • History
  • Block Reads
    • modbusBlockGap
    • modbusBlockMax
    • def
  • modbusLearn(conn, arg: null)
  • modbusPing(conn)
  • modbusRead(conn, regs)
  • modbusRegMap(name)
  • modbusRegMaps()
  • modbusSyncCur(points)
  • modbusWrite(conn, reg, val)

概述(中译) ​

Modbus 连接器


API 正文(英文) ​

docs ​

Overview • Supported Protocols • Register Map • Current Points • Writable Points • History • Block Reads


tags ​

modbusBlockGapApplied to modbusConn to allow for gaps in block reads
modbusBlockMaxApplied to modbusConn to limit the maximum number of registers to read in a block read
modbusConnModbus connector
modbusConnRefUsed on a proxy point to reference its parent modbusConn
modbusCurModbus address to use for current value subscriptions
modbusPointPoint which synchronizes data via a Haystack connector
modbusReadTimeoutHow long to wait before timing out on a modbus read
modbusRegMapUriApplied to modbusConn to define the register map CSV file
modbusSlaveApplied to modbusConn to identify the slave address on this modbus network
modbusWriteUsed on a modbus proxy point to store the id of the entity in the remote system used to write writeVal
modbusWriteTimeoutHow long to wait before timing out on a modbus write

funcs ​

modbusLearnDeprecated - use connLearn()
modbusPingDeprecated - use connPing()
modbusReadRead a point value for given register name on connector instance
modbusRegMapReturn given register map contents
modbusRegMapsList installed register maps including source
modbusSyncCurDeprecated - use connSyncCur()
modbusWriteWrite a value to given register name on connecter instance

views ​

modbusRegMapManage Modbus register map files

lib modbus ​

Overview ​

The ModbusExt implements connector support for Modbus protocol.

Supported Protocols ​

ModbusExt supports two protocols for accessing Modbus slave devices:

TCP/IP ​

To setup a connector to access a Modbus slave over TCP/IP, we use the modbus-tcp URI scheme:

dis: "Modbus TCP/IP Connector"
conn
modbusConn
uri: `modbus-tcp://host/`
modbusSlave: 1
modbusRegMapUri: `data/modbus/xxx.csv`

RTU over TCP/IP ​

To access the slave using serial RTU over a TCP connection, use the modbus-rtutcp scheme:

dis: "Modbus RTU over TCP/IP Connector"
conn
modbusConn
uri: `modbus-rtutcp://host/`
modbusSlave: 1
modbusRegMapUri: `data/modbus/xxx.csv`

Register Map ​

Modbus connectors are required to define a register map using the modbusRegMapUri tag. The register map specifies which points get read/written out of a Modbus slave. The register map URI must be a path relative to the project's home directory or can be a fan:// URI to a CSV file bundled in a pod.

Register maps are simple CSV files:

name, addr,  data, rw, scale, dis,  unit, tags
ping, 40001, u2,   r,  ,      Ping, ,
do0,  00017, bit,  rw, ,      DO-0, ,
do1,  00017, bit,  rw, ,      DO-1, ,
ai0,  40001, u2,   r,  ,      AI-0, ,
ai1,  40002, u2,   r,  *10,   AI-1, kW,   power

Addressing ​

Register address are defined with addr column and specified using Modbus convention:

0xxxx  Coil              00001-065536
1xxxx  Discrete Input    10001-165536
3xxxx  Input Register    30001-365536
4xxxx  Holding Register  40001-465536

Ping ​

A valid ping register is required in order to test connectivity to slave.

Data Type ​

The data column specifies how register data is modeled.

bit  Bool
u1   Unsigned  8-bit Int
u2   Unsigned 16-bit Int
u4   Unsigned 32-bit Int
s1   Signed  8-bit Int
s2   Signed 16-bit Int
s4   Signed 32-bit Int
s8   Signed 64-bit Int
f4   32-bit Float
f8   64-bit Float

Bit Mask ​

The bit data type supports a position notation for cases where bits are packed into input or holding registers:

name, addr,  data,  rw
do0,  40101, bit:0, rw
do1,  40101, bit:1, rw
do2,  40101, bit:2, rw

Word and Byte Order ​

If register data is not stored in network byte order, you can specify the order using a suffix:

u2le   Unsigned 16-bit Int  Little endian byte and word order
u2leb  Unsigned 16-bit Int  Little endian byte order only
u2lew  Unsigned 16-bit Int  Little endian word order only

Read/Write ​

Read and write permissions are configured using rw column:

rw  Register may be read and written
r   Register is read-only
w   Register is write-only

Scale Factor ​

An optional scale factor can be applied to registers using the scale column. The scale format is [op] [num] where the factor is a numeric constant.

add:    +1.5
minus:  -0.25
mult:   *10
div:    /1000

Dis, Unit, Tags ​

The dis, unit, and tags column allow optional pre-configuration for the point during the learn process:

name, addr,  data, rw, dis,  unit, tags
ai1,  40002, u2,   r,  AI-1, kW,   power foo bar

Current Points ​

Modbus proxy points are configured with modbusCur tag, which maps to a valid register map name:

point
modbusConnRef: @conn
modbusCur: ai0

Writable Points ​

Modbus proxy points are configured to write to remote system points via the modbusWrite tag:

point
writable
modbusConnRef: @conn
modbusWrite: ao5

History ​

History synchronization is not supported by Modbus. You will need to use collection to store history.

Block Reads ​

Modbus connectors will attempt to optimize consecutive registers into a single block read when possible. This behavior can be tuned by adding the modbusBlockGap and modbusBlockMax tags to your modbusConn rec, or by configuring them on the connector's associated conn tuning rec.

modbusBlockGap ​

By default, blocks require all points to be in truly consecutive registers:

// block 1
40001 u2
40002 u2
40003 u2

// block 2
40005 u2

If you have a small gap in an otherwise sequential run of registers, you can tune to maintain a single read by adding the modbusBlockGap tag to your conn rec. This tag specifies the maximum number of registers that can be skipped for a single block:

modbusConn
modbusBlockGap: 1

// block 1
40001 u2
40002 u2
40003 u2
40005 u2  // 400004 will be read but discarded

modbusBlockMax ​

By default, blocks are limited to 100 total registers (which includes skipped registers from modbusBlockGap). To force a connector to split blocks into smaller or larger chunks, add the modbusBlockMax tag to your conn rec:

modbusConn
modbusBlockMax: 2

// block 1
40001 u2
40002 u2

// block 2
40003 u2
40004 u2

Be aware a block read failure will result in the entire block's points being marked as fault.



def ​

func:modbusLearn ​

modbusLearn(conn, arg: null) ​

Deprecated - use connLearn()


meta ​

admin✓
deffunc:modbusLearn
deprecated✓
isfunc
liblib:modbus
namemodbusLearn

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusPing ​

modbusPing(conn) ​

Deprecated - use connPing()


meta ​

admin✓
deffunc:modbusPing
deprecated✓
isfunc
liblib:modbus
namemodbusPing

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusRead ​

modbusRead(conn, regs) ​

Read a point value for given register name on connector instance. The regs argument may be a single Str name, or a Str[] for a block read. The grid returned will contain a row for each register requested and two columns: name and val.


meta ​

admin✓
deffunc:modbusRead
isfunc
liblib:modbus
namemodbusRead

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusRegMap ​

modbusRegMap(name) ​

Return given register map contents. Do not include the file extension in the name.

modbusRegMap("myRegisterMap")


meta ​

deffunc:modbusRegMap
isfunc
liblib:modbus
namemodbusRegMap

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusRegMaps ​

modbusRegMaps() ​

List installed register maps including source.


meta ​

deffunc:modbusRegMaps
isfunc
liblib:modbus
namemodbusRegMaps

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusSyncCur ​

modbusSyncCur(points) ​

Deprecated - use connSyncCur()


meta ​

admin✓
deffunc:modbusSyncCur
deprecated✓
isfunc
liblib:modbus
namemodbusSyncCur

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:modbusWrite ​

modbusWrite(conn, reg, val) ​

Write a value to given register name on connecter instance.


meta ​

admin✓
deffunc:modbusWrite
isfunc
liblib:modbus
namemodbusWrite

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

modbusBlockGap ​

Applied to modbusConn to allow for gaps in block reads. See modbus for more information.


meta ​

defmodbusBlockGap
isint
liblib:modbus
tagOnmodbusConn

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit
intUnitless integer number


def ​

modbusBlockMax ​

Applied to modbusConn to limit the maximum number of registers to read in a block read. See modbus for more information.


meta ​

defmodbusBlockMax
isint
liblib:modbus
tagOnmodbusConn

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit
intUnitless integer number


def ​

modbusConn ​

Modbus connector


meta ​

connFeatures
defmodbusConn
iconmodbus
isconn
liblib:modbus

usage ​

modbusConn  conn

supertypes ​

markerMarker labels a dict with typing information
entityTop-level dicts with a unique identifier
connConnector for communication to a remote system

tags ​

actorTimeoutTimeout for messages send to the connector's actor thread
connErrError message associated when connStatus indicates an error condition
connLingerLinger timeout used to keep a connector open
connOpenRetryFreqDuration used for connector open retries
connPingFreqDuration used to configure the auto-ping feature on a given connector
connStateCurrent connection state of a connector as one of the predefined strings
connStatusCurrent status of a connector as one of the predefined strings See Connectors
connTuningRefReference to a tuning configuration defined by a connTuning rec
disDisplay name for an entity
disabledIndicates the entity is in a disabled state
idDefines the unique identifier of an entity in system using a ref value type
modbusBlockGapApplied to modbusConn to allow for gaps in block reads
modbusBlockMaxApplied to modbusConn to limit the maximum number of registers to read in a block read
modbusReadTimeoutHow long to wait before timing out on a modbus read
modbusRegMapUriApplied to modbusConn to define the register map CSV file
modbusSlaveApplied to modbusConn to identify the slave address on this modbus network
modbusWriteTimeoutHow long to wait before timing out on a modbus write
uriUniversal resource identifier


def ​

modbusConnRef ​

Used on a proxy point to reference its parent modbusConn


meta ​

defmodbusConnRef
isref
liblib:modbus
ofmodbusConn
tagOnmodbusPoint

supertypes ​

valData value type
scalarScalar is an atomic value kind
refReference to an entity


def ​

modbusCur ​

Modbus address to use for current value subscriptions. See modbus for format.


meta ​

defmodbusCur
isstr
liblib:modbus
tagOnmodbusPoint

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters


def ​

modbusPoint ​

Point which synchronizes data via a Haystack connector.


meta ​

defmodbusPoint
isconnPoint
liblib:modbus

usage ​

modbusPoint  point

supertypes ​

markerMarker labels a dict with typing information
entityTop-level dicts with a unique identifier
pointData point such as a sensor or actuator
connPointPoint associated with a connector for data synchronization with a remote system

tags ​

connTuningRefReference to a tuning configuration defined by a connTuning rec
curSupports current value
curCalibrationCalibration value to apply to adjust the value read from the connector before updating curVal
curConvertConversion to apply when reading curVal from connector
disDisplay name for an entity
disMacroDisplay name using macro syntax
disabledIndicates the entity is in a disabled state
enumDefines an eumeration of string key names
equipRefReference to equip which contains this entity
ghgFactorHisIdentifies point record with interval emission factor data that the Greenhouse Gas Emission Engine uses to calculate emissions
hisSupports historization of data
hisConvertConversion to apply when reading history data from connector
idDefines the unique identifier of an entity in system using a ref value type
kindKind name used to identity a value data type
maxValInclusive maximum for a numeric value
minValInclusive minimum for a numeric value
modbusConnRefUsed on a proxy point to reference its parent modbusConn
modbusCurModbus address to use for current value subscriptions
modbusWriteUsed on a modbus proxy point to store the id of the entity in the remote system used to write writeVal
navNameNavigation name commonly used with disMacro to create computed display strings
pointFunctionClassifies the point as a sensor, command, or setpoint
pointQuantityQuantity the point senses or controls
pointSubjectWhat the point senses or controls
siteRefReference to site which contains the entity
spaceRefReference to space which contains this entity
systemRefReference to system
tzTimezone identifier from standard timezone database
unitUnit identifier from standard unit database
writableSupports writing data
writeConvertConversion to apply when writing writeVal to the connector


def ​

modbusReadTimeout ​

How long to wait before timing out on a modbus read.


meta ​

defmodbusReadTimeout
isduration
liblib:modbus
tagOnmodbusConn

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit
durationNumber with a unit of time


def ​

modbusRegMapUri ​

Applied to modbusConn to define the register map CSV file. This URI must be a path relative to the project's home directory or can be a "fan://" URI to a CSV file bundled in a pod.


meta ​

defmodbusRegMapUri
isuri
liblib:modbus
tagOnmodbusConn
uiInputmodbusExt::ModbusRegMapInput

supertypes ​

valData value type
scalarScalar is an atomic value kind
uriUniversal resource identifier


def ​

modbusSlave ​

Applied to modbusConn to identify the slave address on this modbus network.


meta ​

defmodbusSlave
isint
liblib:modbus
tagOnmodbusConn

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit
intUnitless integer number


def ​

modbusWrite ​

Used on a modbus proxy point to store the id of the entity in the remote system used to write writeVal. See modbus for format.


meta ​

defmodbusWrite
isstr
liblib:modbus
tagOnmodbusPoint

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters


def ​

modbusWriteTimeout ​

How long to wait before timing out on a modbus write.


meta ​

defmodbusWriteTimeout
isduration
liblib:modbus
tagOnmodbusConn

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit
durationNumber with a unit of time


def ​

view:modbusRegMap ​

Manage Modbus register map files


meta ​

admin✓
appNameconn
defview:modbusRegMap
disKeyui::regMap
iconview
isview
liblib:modbus

supertypes ​

featureFeature namespace of definitions formatted as feature:name
viewFresco UI view

src ​

view: { uiType:"modbusExt::RegMapView" }
data: { expr:"modbusRegMapList()" }