| | |
| | | package apacheplc4x |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/pkg/logx" |
| | | "context" |
| | | "errors" |
| | |
| | | |
| | | func readHoldingRegisterSingle(connection plc4go.PlcConnection, address int) ([]byte, error) { |
| | | tag := fmt.Sprintf("tag:%v", address) |
| | | tagAddress := fmt.Sprintf("holding-register:%d:DINT", address) |
| | | tagAddress := getTagAddress(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:DINT[%d]", address, length) |
| | | tagAddress := getTagAddress(address) |
| | | |
| | | // 读模式 |
| | | readRequest, err := connection.ReadRequestBuilder().AddTagAddress(tag, tagAddress).Build() |
| | |
| | | return readHoldingRegisterSingle(connection, address) |
| | | } |
| | | |
| | | func getTagAddress(address int) string { |
| | | intType := conf.Conf.PLC.ModbusIntType |
| | | if intType == "" { |
| | | intType = "DINT" |
| | | } |
| | | return fmt.Sprintf("holding-register:%d:%v", address, intType) |
| | | } |
| | | |
| | | func WriteHoldingRegister(ipAddr string, address int, value any) (string, error) { |
| | | connection, err := GetModbusConnection(ipAddr) |
| | | dealErr(err, ipAddr) |
| | |
| | | } |
| | | defer connection.Close() |
| | | tag := fmt.Sprintf("tag:%v:w", address) |
| | | tagAddress := fmt.Sprintf("holding-register:%d:DINT", address) |
| | | tagAddress := getTagAddress(address) |
| | | |
| | | // 写模式 |
| | | writeRequest, err := connection.WriteRequestBuilder().AddTagAddress(tag, tagAddress, value).Build() |