| | |
| | | |
| | | 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() |
| | |
| | | |
| | | 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() |
| | |
| | | |
| | | 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() |
| | |
| | | |
| | | 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() |