| | |
| | | return |
| | | } |
| | | |
| | | params.DeviceID = conf.Conf.System.DeviceId |
| | | if params.Method == constvar.PlcMethodModbusTCP && (params.Address == "" || params.Port == 0) { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "当接口方式为modbusTCP时,address和port不能为空") |
| | | ctx.FailWithMsg(ecode.ParamsErr, "当接口方式为modbusTCP时,地址和端口号不能为空") |
| | | return |
| | | } |
| | | if params.Method == constvar.PlcMethodSerial && (params.BaudRate == 0 || params.SerialName == "") { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "当接口方式为serial时,baudRate和serialName不能为空") |
| | | ctx.FailWithMsg(ecode.ParamsErr, "当接口方式为serial时,波特率和串口名称不能为空") |
| | | return |
| | | } |
| | | |
| | | if params.Method == constvar.PlcMethodModbusRTU && (params.DataBit == 0 || params.StopBit == 0 || params.Parity == 0) { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "当接口方式为modbusRTU时,数据位,停止位,校验位不能为空") |
| | | return |
| | | } |
| | | |
| | |
| | | DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.System.DeviceId).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | return &model.DevicePlc{ |
| | | DeviceID: "", |
| | | Brand: "", |
| | | Method: "", |
| | | Address: "", |
| | | Port: 0, |
| | | BaudRate: 0, |
| | | SerialName: "", |
| | | DataBit: 0, |
| | | StopBit: 0, |
| | | Parity: 0, |
| | | IsOpen: false, |
| | | Detail: "", |
| | | Details: make([]*model.DevicePlcAddress, 0), |
| | | }, ecode.OK |
| | | } |