zhangqian
2023-09-17 181733a7142ee4de79061f7e5796f9cdb21fc7d8
pkg/plc/apacheplc4x/modbus.go
@@ -52,7 +52,7 @@
func readHoldingRegisterSingle(connection plc4go.PlcConnection, address int) ([]byte, error) {
   tag := fmt.Sprintf("tag:%v", address)
   tagAddress := fmt.Sprintf("holding-register:%d:UINT", address)
   tagAddress := fmt.Sprintf("holding-register:%d:DINT", address)
   // 读模式
   readRequest, err := connection.ReadRequestBuilder().AddTagAddress(tag, tagAddress).Build()
@@ -82,7 +82,7 @@
func readHoldingRegisterList(connection plc4go.PlcConnection, address, length int) ([]byte, error) {
   tag := fmt.Sprintf("tag:%v:%v", address, length)
   tagAddress := fmt.Sprintf("holding-register:%d:UINT[%d]", address, length)
   tagAddress := fmt.Sprintf("holding-register:%d:DINT[%d]", address, length)
   // 读模式
   readRequest, err := connection.ReadRequestBuilder().AddTagAddress(tag, tagAddress).Build()
@@ -117,8 +117,8 @@
func ReadHoldingRegister(ipAddr string, address, length int) ([]byte, error) {
   connection, err := GetModbusConnection(ipAddr)
   dealErr(err, ipAddr)
   if err != nil {
      dealErr(err, ipAddr)
      return nil, err
   }
   defer connection.Close()
@@ -131,13 +131,13 @@
func WriteHoldingRegister(ipAddr string, address int, value any) (string, error) {
   connection, err := GetModbusConnection(ipAddr)
   dealErr(err, ipAddr)
   if err != nil {
      dealErr(err, ipAddr)
      return "", err
   }
   defer connection.Close()
   tag := fmt.Sprintf("tag:%v:w", address)
   tagAddress := fmt.Sprintf("holding-register:%d:UINT", address)
   tagAddress := fmt.Sprintf("holding-register:%d:DINT", address)
   // 写模式
   writeRequest, err := connection.WriteRequestBuilder().AddTagAddress(tag, tagAddress, value).Build()