| | |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | processModel, err := taskService.GetProcessParams(procedure, order) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | } |
| | | |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK || plcConfig.ID == 0 { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "请先配置PLC") |
| | | return |
| | | } |
| | | plcConfig.MaxTryTimes = 2 |
| | | err = SendParams(processModel.ParamsMap, plcConfig) |
| | | |
| | | device, err := service.GetCurrentDevice() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!") |
| | | ctx.FailWithMsg(ecode.DBErr, err.Error()) |
| | | return |
| | | } |
| | | if device.NeedSetProcessParams { |
| | | processModel, err := taskService.GetProcessParams(procedure, order) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | } |
| | | err = SendParams(processModel.ParamsMap, plcConfig) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!") |
| | | return |
| | | } |
| | | } |
| | | |
| | | plcConfig.CurrentTryTimes = 0 |
| | | err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, procedure.Channel, order.Amount.IntPart()) |
| | | if err != nil { |
| | |
| | | ) |
| | | |
| | | type Device struct { |
| | | DeviceID string `json:"deviceID,omitempty"` |
| | | DeviceName string `json:"deviceName,omitempty"` |
| | | NeedSetProcessParams bool `json:"needSetProcessParams,omitempty"` //是否需要设置工艺参数 |
| | | DeviceID string `json:"deviceID"` |
| | | DeviceName string `json:"deviceName"` |
| | | NeedSetProcessParams bool `json:"needSetProcessParams"` //是否需要设置工艺参数 |
| | | } |
| | | |
| | | type DeviceListResponse struct { |
| | |
| | | device.NeedSetProcessParams = needSetProcessParams |
| | | return model.NewDeviceSearch().SetID(device.ID).Save(device) |
| | | } |
| | | |
| | | func GetCurrentDevice() (device *model.Device, err error) { |
| | | if conf.Conf.CurrentDeviceID == "" { |
| | | return nil, errors.New("当前设备ID不存在,请检查") |
| | | } |
| | | device, err = model.NewDeviceSearch().SetDeviceId(conf.Conf.CurrentDeviceID).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | return nil, errors.New("设备不存在") |
| | | } |
| | | return device, nil |
| | | } |