forked from flosse/go-modbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
86 lines (60 loc) · 1.78 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Copyright (C) 2014, Markus Kohlhase <[email protected]>
*
* Modbus API
*/
package modbus
type Transporter interface {
Connect() error
Close() error
Send(pdu *Pdu) (*Pdu, error)
}
type Client interface {
/**************
* Bit access *
**************/
/* Physical Discrete Inputs */
// Function Code 2
ReadDiscreteInputs(address, quantity uint16) (inputs []bool, err error)
/* Internal Bits Or Physical Coils */
// Function Code 1
ReadCoils(address, quantity uint16) (coils []bool, err error)
// Function Code 5
WriteSingleCoil(address uint16, coil bool) error
// Function Code 15
WriteMultipleCoils(address uint16, coils []bool) error
/******************
* 16 bits access *
******************/
/* Physical Input Registers */
// Function Code 4
ReadInputRegisters(address, quantity uint16) (readRegisters []int16, err error)
// Function Code 3
ReadHoldingRegisters(address, quantity uint16) (readRegisters []int16, err error)
// Function Code 6
WriteSingleRegister(address uint16, value int16) error
// Function Code 16
WriteMultipleRegisters(address, quantity uint16, values []int16) error
// Function Code 23
ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, values []int16) (readRegisters []int16, err error)
// Function Code 22
MaskWriteRegister(address uint16, andMask, orMask int16) error
// Function Code 24
ReadFifoQueue(address uint16) (count uint16, values []int16, err error)
/**********************
* File record access *
**********************/
// TODO: specify methods
/***************
* Diagnostics *
**************/
// TODO: specify methods
}
type Handler interface {
Handle(req *Pdu) (res *Pdu)
}
type Server interface {
SetHandler(h *Handler)
Start() error
Stop() error
}