ModbusMasterSerialPort
- Namespace
- ZEquipment
- Implements
FUNCTION_BLOCK ModbusMasterSerialPort IMPLEMENTS ZCore.IModbusMasterRtu, ZCore.IObject, ZCore.IError
This function block implements a Modbus master in order to be able to address a Modbus device via a serial interface. The Beckhoff function block ModbusRtuMaster_KL6x22B is used internally. -- ModbusRtuMaster_KL6x22B The data structures required for the link with the serial communication port are included in the Beckhoff function block.
The following Modbus function codes are supported
- Read Coils (0x01): to read contiguous status of coils
- Read Discrete Inputs (0x02): to read contiguous status of discrete inputs
- Read Holding Registers (0x03): to read the contents of a contiguous block of holding registers
- Read Input Register (0x04): to read from contiguous input registers
- Write Single Coil (0x05): to write a single output to either ON or OFF
- Write Single register (0x06): to write a single holding register
- Write Multiple Coils (0x0F): to force each coil in a sequence of coils to either ON or OFF
- Write Multiple Registers (0x10): to write a block of contiguous registers
Since only one request can be active at a serial interface at the same time, the requests are bufferd internally and processed on after the other.
This function block is the managed user object of ModbusMasterSerialPortImpl for use inside the framework.
Constructor
FB_init
METHOD FB_init (
[input] bInitRetains : BOOL,
[input] bInCopyCode : BOOL,
[input] parent : ZCore.IManagedObject,
[input] logger : ZCore.ILogger) : BOOL
When constructing this object a logging device can be specified.
Inputs
bInitRetainsBOOLbInCopyCodeBOOLparentIManagedObjectInterface to the ManagedObject that is the parent of this object
loggerILoggerif wanted, interface to an external housed logging device like LoggerFile7FF
Returns
- BOOL
Properties
Busy
PROPERTY Busy : BOOL
This property returns TRUE if the object is Busy executing a sequence or still in its
initialization phase (if applicable). It returns FALSE if the object is Idle or in an
Error state.
Property Value
- BOOL
Done
PROPERTY Done : BOOL
If the object is in idle state (often mentioned as "the object is not busy and not on error"),
this is indicated by this property returning TRUE.
Property Value
- BOOL
Error
PROPERTY Error : BOOL
If the object aborts its execution with an error, this is indicated by this property returning TRUE.
Information about the error may be retrieved by utilizing the methods that are implemented from the
IError.
Returns TRUE if a fault occured within a sequence or the initialization phase
of an object, respectively. If this property returns TRUE, use
to get insights about the origin of the fault.
Property Value
- BOOL
Methods
ErrorId
METHOD ErrorId () : UDINT
Returns the error code of the first error source for this object. The method recursively goes down the error stack until the initial source of error of this object can be found. For performance reasons, the error stack is not cleared when the error state is reset. So this method should always used in conjunction with Error.
Returns
- UDINT
ErrorMessage
METHOD ErrorMessage () : ZCore.ZString
Returns the error description of the first error source for this object. The method recursively goes down the error stack until the initial source of error of this object can be found. For performance reasons, the error stack is not cleared when the error state is reset. So this method should always used in conjunction with Error.
Returns
ErrorSource
METHOD ErrorSource () : ZCore.IError
This method returns the direct error source of this object. This method can then be used to retrieve the actual error source by using the method of the returned IError.
Returns
ReadCoilsAsync
METHOD ReadCoilsAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (number) of the coils to be read
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method writes to
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
ReadDiscreteInputsAsync
METHOD ReadDiscreteInputsAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
Use this function to read the status of discrete inputs in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (number) of inputs to be read
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method writes to
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
ReadHoldingRegisterAsync
METHOD ReadHoldingRegisterAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used to read the contents of a contiguous block of holding registers in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (number) of registgers to be read parameters
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method writes to
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
ReadInputRegisterAsync
METHOD ReadInputRegisterAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used to read from contiguous input registers in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (number) of registers to be read
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method writes to
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
SetLogger
METHOD SetLogger (
[input] logger : ZCore.ILogger)
Use this function to enable logging for this modbus master instance. If logging is
enabled, every parameter request (Read and Write)
is written to the logger.
If no Logging Instance is given here (logger=0), logging is generally deactivated.
Inputs
loggerILogger
TraceErrorStack
METHOD TraceErrorStack (
[input] trace : ZCore.IErrorTrace)
This method is used internally when recording an error trace.
Inputs
traceIErrorTrace
WriteMultipleCoilsAsync
METHOD WriteMultipleCoilsAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used to force each coil in a sequence of coils either ON or OFF in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (number) of coils to be written
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method reads from
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
WriteMultipleRegisterAsync
METHOD WriteMultipleRegisterAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] quantity : DWORD,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used to write a block of contiguous registers in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
quantityDWORDdefines the quantity (count) of registers to be written
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method reads from
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
WriteSingleCoilAsync
METHOD WriteSingleCoilAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used to write a single output to eithe ON or OFF in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method reads from
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s
WriteSingleRegisterAsync
METHOD WriteSingleRegisterAsync (
[input] taskToken : ZCore.ITaskToken,
[input] unitId : BYTE,
[input] modbusAddress : DWORD,
[input] bufferPtr : ZCore.ZPointer,
[input] bufferSize : UDINT,
[input] timeout : LREAL)
This method is used ot write a singel hlding register in a remote device.
Inputs
taskTokenITaskTokenunitIdBYTEdefines the station address of the target device for ModbusRTU
modbusAddressDWORDdefines the modbus starting address of the server on which the operation should take place
bufferPtrZPointerPointer to the location this method writes to
bufferSizeUDINTSize of the location buffer is pointing to
timeoutLREALTimeout value for waiting for a response frome the slave in s