| | |
| | | ctx.OkWithDetailed(taskData) |
| | | } |
| | | |
| | | // TaskStart |
| | | // GetProcessParams |
| | | // @Tags Task |
| | | // @Summary 任务开始 |
| | | // @Summary 任务开始(获取工艺参数) |
| | | // @Produce application/json |
| | | // @Param id path int true "工序id" |
| | | // @Success 200 {object} contextx.Response{data=response.ProcessParamsResponse} "成功" |
| | | // @Router /v1/task/start/{id} [get] |
| | | func (slf *TaskApi) TaskStart(c *gin.Context) { |
| | | func (slf *TaskApi) GetProcessParams(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // SendProcessParams |
| | | // TaskStart |
| | | // @Tags Task |
| | | // @Summary 下发工艺参数 |
| | | // @Summary 下发工艺参数(开始任务) |
| | | // @Produce application/json |
| | | // @Param id path int true "工序id" |
| | | // @Success 200 {object} contextx.Response{service.GetProcessModel} "成功" |
| | | // @Router /v1/task/sendProcessParams/{id} [post] |
| | | func (slf *TaskApi) SendProcessParams(c *gin.Context) { |
| | | func (slf *TaskApi) TaskStart(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | |
| | | } |
| | | |
| | | logx.Info("----------------开始下发工艺参数-----------------") |
| | | var missNumbers int |
| | | var failedNumbers int |
| | | for k, v := range paramsMap { |
| | | if address, ok := plc_address.Get(k); ok { |
| | | result, err := plc.WriteHoldingRegister(conn, address, v) |
| | | if err != nil { |
| | | logx.Errorf("WriteHoldingRegister err:%v, address: %v, key: %v value: %v", err.Error(), address, k, v) |
| | | failedNumbers++ |
| | | logx.Errorf("plc write err:%v, address: %v, key: %v value: %v", err.Error(), address, k, v) |
| | | } else { |
| | | delete(paramsMap, k) |
| | | logx.Infof("WriteHoldingRegister ok: key: %v, value: %v, result: %v", k, v, result) |
| | | logx.Infof("plc write ok: key: %v, value: %v, result: %v", k, v, result) |
| | | } |
| | | } else { |
| | | logx.Errorf("miss param address, k:%v, v:%v", k, v) |
| | | missNumbers++ |
| | | } |
| | | } |
| | | if missNumbers >= 1 { |
| | | caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicGetPlcAddress, conf.Conf.NsqConf.NodeId), fmt.Sprintf(constvar.NsqTopicSendPlcAddress, conf.Conf.NsqConf.NodeId)) |
| | | var addressResult common.ResponsePlcAddress |
| | | err := caller.Call(common.RequestPlcAddress{DeviceId: conf.Conf.System.DeviceId}, &addressResult, time.Second*2) |
| | | if err != nil { |
| | | logx.Infof("SendParams2 err: %v", err.Error()) |
| | | return err |
| | | } |
| | | if failedNumbers >= 1 { //写入plc失败, 重试 |
| | | tryTimes++ |
| | | return SendParams(paramsMap, tryTimes) |
| | | } |