modbus-tcp-0.2.1: Communicate with Modbus devices over TCP

Safe HaskellNone
LanguageHaskell2010

System.Modbus.TCP

Description

An implementation of the Modbus TPC/IP protocol.

This implementation is based on the MODBUS Application Protocol Specification V1.1b (http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf).

Synopsis

Documentation

data TCP_ADU Source

MODBUS TCP/IP Application Data Unit

See: MODBUS Application Protocol Specification V1.1b, section 4.1

data Header Source

MODBUS Application Protocol Header

See: MODBUS Application Protocol Specification V1.1b, section 4.1

data FunctionCode Source

The function code field of a MODBUS data unit is coded in one byte. Valid codes are in the range of 1 ... 255 decimal (the range 128 - 255 is reserved and used for exception responses). When a message is sent from a Client to a Server device the function code field tells the server what kind of action to perform. Function code 0 is not valid.

Sub-function codes are added to some function codes to define multiple actions.

See: MODBUS Application Protocol Specification V1.1b, sections 4.1 and 5

Constructors

ReadCoils

See: MODBUS Application Protocol Specification V1.1b, section 6.1

ReadDiscreteInputs

See: MODBUS Application Protocol Specification V1.1b, section 6.2

ReadHoldingRegisters

See: MODBUS Application Protocol Specification V1.1b, section 6.3

ReadInputRegisters

See: MODBUS Application Protocol Specification V1.1b, section 6.4

WriteSingleCoil

See: MODBUS Application Protocol Specification V1.1b, section 6.5

WriteSingleRegister

See: MODBUS Application Protocol Specification V1.1b, section 6.6

ReadExceptionStatus

See: MODBUS Application Protocol Specification V1.1b, section 6.7

Diagnostics

See: MODBUS Application Protocol Specification V1.1b, section 6.8

GetCommEventCounter

See: MODBUS Application Protocol Specification V1.1b, section 6.9

GetCommEventLog

See: MODBUS Application Protocol Specification V1.1b, section 6.10

WriteMultipleCoils

See: MODBUS Application Protocol Specification V1.1b, section 6.11

WriteMultipleRegisters

See: MODBUS Application Protocol Specification V1.1b, section 6.12

ReportSlaveID

See: MODBUS Application Protocol Specification V1.1b, section 6.13

ReadFileRecord

See: MODBUS Application Protocol Specification V1.1b, section 6.14

WriteFileRecord

See: MODBUS Application Protocol Specification V1.1b, section 6.15

MaskWriteRegister

See: MODBUS Application Protocol Specification V1.1b, section 6.16

ReadWriteMultipleRegisters

See: MODBUS Application Protocol Specification V1.1b, section 6.17

ReadFIFOQueue

See: MODBUS Application Protocol Specification V1.1b, section 6.18

EncapsulatedInterfaceTransport

See: MODBUS Application Protocol Specification V1.1b, section 6.19

UserDefinedCode Word8

See: MODBUS Application Protocol Specification V1.1b, section 5

ReservedCode Word8

See: MODBUS Application Protocol Specification V1.1b, section 5

OtherCode Word8 
ExceptionCode FunctionCode 

data ExceptionCode Source

See: MODBUS Application Protocol Specification V1.1b, section 7

Constructors

IllegalFunction

The function code received in the query is not an allowable action for the server (or slave). This may be because the function code is only applicable to newer devices, and was not implemented in the unit selected. It could also indicate that the server (or slave) is in the wrong state to process a request of this type, for example because it is unconfigured and is being asked to return register values.

IllegalDataAddress

The data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, the PDU addresses the first register as 0, and the last one as 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 4, then this request will successfully operate (address-wise at least) on registers 96, 97, 98, 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 5, then this request will fail with Exception Code 0x02 "Illegal Data Address" since it attempts to operate on registers 96, 97, 98, 99 and 100, and there is no register with address 100.

IllegalDataValue

A value contained in the query data field is not an allowable value for server (or slave). This indicates a fault in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register.

SlaveDeviceFailure

An unrecoverable error occurred while the server (or slave) was attempting to perform the requested action.

Acknowledge

Specialized use in conjunction with programming commands. The server (or slave) has accepted the request and is processing it, but a long duration of time will be required to do so. This response is returned to prevent a timeout error from occurring in the client (or master). The client (or master) can next issue a Poll Program Complete message to determine if processing is completed.

SlaveDeviceBusy

Specialized use in conjunction with programming commands. The server (or slave) is engaged in processing a long–duration program command. The client (or master) should retransmit the message later when the server (or slave) is free.

MemoryParityError

Specialized use in conjunction with function codes ReadFileRecord and WriteFileRecord and reference type 6, to indicate that the extended file area failed to pass a consistency check.

GatewayPathUnavailable

Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an internal communication path from the input port to the output port for processing the request. Usually means that the gateway is misconfigured or overloaded.

GatewayTargetDeviceFailedToRespond

Specialized use in conjunction with gateways, indicates that no response was obtained from the target device. Usually means that the device is not present on the network.

command Source

Arguments

:: TransactionId 
-> ProtocolId 
-> UnitId 
-> FunctionCode

PDU function code.

-> ByteString

PDU data.

-> Socket 
-> ExceptT MB_Exception IO TCP_ADU 

Sends a raw MODBUS command.

readHoldingRegisters Source

Arguments

:: TransactionId 
-> ProtocolId 
-> UnitId 
-> Word16

Register starting address.

-> Word16

Quantity of registers.

-> Socket 
-> ExceptT MB_Exception IO [Word16] 

readInputRegisters Source

Arguments

:: TransactionId 
-> ProtocolId 
-> UnitId 
-> Word16

Starting address.

-> Word16

Quantity of input registers.

-> Socket 
-> ExceptT MB_Exception IO [Word16] 

writeSingleRegister Source

Arguments

:: TransactionId 
-> ProtocolId 
-> UnitId 
-> Word16

Register address.

-> Word16

Register value.

-> Socket 
-> ExceptT MB_Exception IO () 

writeMultipleRegisters Source

Arguments

:: TransactionId 
-> ProtocolId 
-> UnitId 
-> Word16

Register starting address

-> [Word16]

Register values to be written

-> Socket 
-> ExceptT MB_Exception IO Word16