api.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2014 Quoc-Viet Nguyen. All rights reserved.
  2. // This software may be modified and distributed under the terms
  3. // of the BSD license. See the LICENSE file for details.
  4. package modbus
  5. type Client interface {
  6. // Bit access
  7. // ReadCoils reads from 1 to 2000 contiguous status of coils in a
  8. // remote device and returns coil status.
  9. ReadCoils(address, quantity uint16) (results []byte, err error)
  10. // ReadDiscreteInputs reads from 1 to 2000 contiguous status of
  11. // discrete inputs in a remote device and returns input status.
  12. ReadDiscreteInputs(address, quantity uint16) (results []byte, err error)
  13. // WriteSingleCoil write a single output to either ON or OFF in a
  14. // remote device and returns output value.
  15. WriteSingleCoil(address, value uint16) (results []byte, err error)
  16. // WriteMultipleCoils forces each coil in a sequence of coils to either
  17. // ON or OFF in a remote device and returns quantity of outputs.
  18. WriteMultipleCoils(address, quantity uint16, value []byte) (results []byte, err error)
  19. // 16-bit access
  20. // ReadInputRegisters reads from 1 to 125 contiguous input registers in
  21. // a remote device and returns input registers.
  22. ReadInputRegisters(address, quantity uint16) (results []byte, err error)
  23. //自定义函数
  24. PackReadHoldingRegisters(address, quantity uint16) (results []byte, err error)
  25. DePackRegisters(aduResponse []byte) (results []byte, err error)
  26. PackWriteMultipleRegisters(address, quantity uint16, value []byte) (results []byte, err error)
  27. DePackSetRegs(aduResponse []byte) (results []byte, err error)
  28. // ReadHoldingRegisters reads the contents of a contiguous block of
  29. // holding registers in a remote device and returns register value.
  30. ReadHoldingRegisters(address, quantity uint16) (results []byte, err error)
  31. // WriteSingleRegister writes a single holding register in a remote
  32. // device and returns register value.
  33. WriteSingleRegister(address, value uint16) (results []byte, err error)
  34. // WriteMultipleRegisters writes a block of contiguous registers
  35. // (1 to 123 registers) in a remote device and returns quantity of
  36. // registers.
  37. WriteMultipleRegisters(address, quantity uint16, value []byte) (results []byte, err error)
  38. // ReadWriteMultipleRegisters performs a combination of one read
  39. // operation and one write operation. It returns read registers value.
  40. ReadWriteMultipleRegisters(readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error)
  41. // MaskWriteRegister modify the contents of a specified holding
  42. // register using a combination of an AND mask, an OR mask, and the
  43. // register's current contents. The function returns
  44. // AND-mask and OR-mask.
  45. MaskWriteRegister(address, andMask, orMask uint16) (results []byte, err error)
  46. //ReadFIFOQueue reads the contents of a First-In-First-Out (FIFO) queue
  47. // of register in a remote device and returns FIFO value register.
  48. ReadFIFOQueue(address uint16) (results []byte, err error)
  49. }