| | |
| | | } |
| | | |
| | | func ReadHoldingRegisterSingle(connection plc4go.PlcConnection, address int) ([]byte, error) { |
| | | tag := fmt.Sprintf("tag:%v", address) |
| | | tagAddress := fmt.Sprintf("holding-register:%d:UINT", address) |
| | | |
| | | // 读模式 |
| | | readRequest, err := connection.ReadRequestBuilder().AddTagAddress("tag", tagAddress).Build() |
| | | readRequest, err := connection.ReadRequestBuilder().AddTagAddress(tag, tagAddress).Build() |
| | | if err != nil { |
| | | fmt.Printf("preparing read-request:%s\n", err.Error()) |
| | | return nil, err |
| | |
| | | } |
| | | |
| | | 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) |
| | | |
| | | // 读模式 |
| | | readRequest, err := connection.ReadRequestBuilder().AddTagAddress("tag", tagAddress).Build() |
| | | readRequest, err := connection.ReadRequestBuilder().AddTagAddress(tag, tagAddress).Build() |
| | | if err != nil { |
| | | fmt.Printf("preparing read-request:%s\n", err.Error()) |
| | | return nil, err |
| | |
| | | } |
| | | |
| | | func WriteHoldingRegister(connection plc4go.PlcConnection, address int, value any) (string, error) { |
| | | tag := fmt.Sprintf("tag:%v:w", address) |
| | | tagAddress := fmt.Sprintf("holding-register:%d:UINT", address) |
| | | |
| | | // 写模式 |
| | | writeRequest, err := connection.WriteRequestBuilder().AddTagAddress("tag", tagAddress, value).Build() |
| | | writeRequest, err := connection.WriteRequestBuilder().AddTagAddress(tag, tagAddress, value).Build() |
| | | if err != nil { |
| | | fmt.Printf("preparing read-request:%s\n", err.Error()) |
| | | return "", err |