Documentation ¶
Overview ¶
Package driver is used to execute device-sdk's commands
Index ¶
- Constants
- Variables
- func NewProtocolDriver() sdkModel.ProtocolDriver
- func TransformCommandValueToDataBytes(commandInfo *CommandInfo, value *sdkModel.CommandValue) ([]byte, error)
- func TransformDataBytesToResult(req *sdkModel.CommandRequest, dataBytes []byte, commandInfo *CommandInfo) (*sdkModel.CommandValue, error)
- type CommandInfo
- type ConnectionInfo
- type DeviceClient
- type Driver
- func (d *Driver) AddDevice(deviceName string, protocols map[string]models.ProtocolProperties, ...) error
- func (d *Driver) DisconnectDevice(deviceName string, protocols map[string]models.ProtocolProperties) error
- func (d *Driver) HandleReadCommands(deviceName string, protocols map[string]models.ProtocolProperties, ...) (responses []*sdkModel.CommandValue, err error)
- func (d *Driver) HandleWriteCommands(deviceName string, protocols map[string]models.ProtocolProperties, ...) error
- func (d *Driver) Initialize(lc logger.LoggingClient, asyncCh chan<- *sdkModel.AsyncValues, ...) error
- func (d *Driver) RemoveDevice(deviceName string, protocols map[string]models.ProtocolProperties) error
- func (d *Driver) Stop(force bool) error
- func (d *Driver) UpdateDevice(deviceName string, protocols map[string]models.ProtocolProperties, ...) error
- type ModbusClient
Constants ¶
View Source
const ( BOOL = "BOOL" INT16 = "INT16" INT32 = "INT32" INT64 = "INT64" UINT16 = "UINT16" UINT32 = "UINT32" UINT64 = "UINT64" FLOAT32 = "FLOAT32" FLOAT64 = "FLOAT64" DISCRETES_INPUT = "DISCRETES_INPUT" COILS = "COILS" INPUT_REGISTERS = "INPUT_REGISTERS" HOLDING_REGISTERS = "HOLDING_REGISTERS" PRIMARY_TABLE = "primaryTable" STARTING_ADDRESS = "startingAddress" IS_BYTE_SWAP = "isByteSwap" IS_WORD_SWAP = "isWordSwap" // RAW_TYPE define binary data type which read from Modbus device RAW_TYPE = "rawType" SERVICE_STOP_WAIT_TIME = 1 )
View Source
const ( ProtocolTCP = "modbus-tcp" ProtocolRTU = "modbus-rtu" Address = "Address" Port = "Port" UnitID = "UnitID" BaudRate = "BaudRate" DataBits = "DataBits" StopBits = "StopBits" // Parity: N - None, O - Odd, E - Even Parity = "Parity" )
Variables ¶
View Source
var PrimaryTableBitCountMap = map[string]uint16{ DISCRETES_INPUT: 1, COILS: 1, INPUT_REGISTERS: 16, HOLDING_REGISTERS: 16, }
Functions ¶
func NewProtocolDriver ¶
func NewProtocolDriver() sdkModel.ProtocolDriver
func TransformCommandValueToDataBytes ¶
func TransformCommandValueToDataBytes(commandInfo *CommandInfo, value *sdkModel.CommandValue) ([]byte, error)
func TransformDataBytesToResult ¶ added in v1.1.0
func TransformDataBytesToResult(req *sdkModel.CommandRequest, dataBytes []byte, commandInfo *CommandInfo) (*sdkModel.CommandValue, error)
Types ¶
type CommandInfo ¶
type CommandInfo struct { PrimaryTable string StartingAddress uint16 ValueType sdkModel.ValueType // how many register need to read Length uint16 IsByteSwap bool IsWordSwap bool RawType sdkModel.ValueType }
ConnectionInfo is command info
type ConnectionInfo ¶
type ConnectionInfo struct { Protocol string Address string Port int BaudRate int DataBits int StopBits int Parity string UnitID uint8 }
ConnectionInfo is device connection info
type DeviceClient ¶
type DeviceClient interface { OpenConnection() error GetValue(commandInfo interface{}) ([]byte, error) SetValue(commandInfo interface{}, value []byte) error CloseConnection() error }
DeviceClient is a interface for modbus client lib to implementation It's responsibility are handle connection, read data bytes value and write data bytes value
type Driver ¶
type Driver struct { Logger logger.LoggingClient AsyncCh chan<- *sdkModel.AsyncValues // contains filtered or unexported fields }
func (*Driver) AddDevice ¶ added in v1.1.0
func (d *Driver) AddDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error
func (*Driver) DisconnectDevice ¶
func (*Driver) HandleReadCommands ¶
func (d *Driver) HandleReadCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModel.CommandRequest) (responses []*sdkModel.CommandValue, err error)
func (*Driver) HandleWriteCommands ¶
func (d *Driver) HandleWriteCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModel.CommandRequest, params []*sdkModel.CommandValue) error
func (*Driver) Initialize ¶
func (d *Driver) Initialize(lc logger.LoggingClient, asyncCh chan<- *sdkModel.AsyncValues, deviceCh chan<- []sdkModel.DiscoveredDevice) error
func (*Driver) RemoveDevice ¶ added in v1.1.0
func (*Driver) UpdateDevice ¶ added in v1.1.0
func (d *Driver) UpdateDevice(deviceName string, protocols map[string]models.ProtocolProperties, adminState models.AdminState) error
type ModbusClient ¶
type ModbusClient struct { // IsModbusTcp is a value indicating the connection type IsModbusTcp bool // TCPClientHandler is ued for holding device TCP connection TCPClientHandler MODBUS.TCPClientHandler // TCPClientHandler is ued for holding device RTU connection RTUClientHandler MODBUS.RTUClientHandler // contains filtered or unexported fields }
ModbusClient is used for connecting the device and read/write value
func NewDeviceClient ¶
func NewDeviceClient(connectionInfo *ConnectionInfo) (*ModbusClient, error)
func (*ModbusClient) CloseConnection ¶
func (c *ModbusClient) CloseConnection() error
func (*ModbusClient) GetValue ¶
func (c *ModbusClient) GetValue(commandInfo interface{}) ([]byte, error)
func (*ModbusClient) OpenConnection ¶
func (c *ModbusClient) OpenConnection() error
func (*ModbusClient) SetValue ¶
func (c *ModbusClient) SetValue(commandInfo interface{}, value []byte) error
Click to show internal directories.
Click to hide internal directories.