| | |
| | | return nil, errors.New("conf.Conf.Services.Serial config not set yet") |
| | | } |
| | | label := fmt.Sprintf("D%d", address) |
| | | return plccom.ReadPLC(plccom.DeviceTypeMitsubishi, ipAddr, label) |
| | | return plccom.ReadPLC(plccom.DeviceTypeMitsubishi, ipAddr, label, dataLength) |
| | | } |
| | | return |
| | | } |
| | | |
| | | func ReadByModbusTCP(ipAddr string, address, length int) ([]byte, error) { |
| | | if conf.Conf.PLC.Package == constvar.PlcPackageApache { |
| | | newLength := length / 2 |
| | | if newLength == 0 { |
| | | newLength = 1 |
| | | } |
| | | return apacheplc4x.ReadHoldingRegister(ipAddr, address, newLength) |
| | | return apacheplc4x.ReadHoldingRegister(ipAddr, address, length) |
| | | } else if conf.Conf.PLC.Package == constvar.PlcPackageApacheLongConnection { |
| | | conn, err := plc.GetModbusConnection(ipAddr) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | newLength := length / 2 |
| | | if newLength == 0 { |
| | | newLength = 1 |
| | | } |
| | | return plc.ReadHoldingRegister(conn, address, newLength) |
| | | return plc.ReadHoldingRegister(conn, address, length) |
| | | } else { |
| | | return modbusx.Read(ipAddr, uint16(address), uint16(length)) |
| | | } |
| | |
| | | Parity: plcConfig.Parity, |
| | | } |
| | | if conf.Conf.PLC.Package == constvar.PlcPackageApache { |
| | | newLength := length / 2 |
| | | if newLength == 0 { |
| | | newLength = 1 |
| | | } |
| | | return apacheplc4x.ReadHoldingRegisterByRTU(rtuConfig, address, newLength) |
| | | return apacheplc4x.ReadHoldingRegisterByRTU(rtuConfig, address, length) |
| | | } else { |
| | | return modbusx.ReadByRTU(rtuConfig, uint16(address), uint16(length)) |
| | | } |