| | |
| | | "apsClient/model/response" |
| | | _ "apsClient/model/response" |
| | | "apsClient/pkg/contextx" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/plc/apacheplc4x" |
| | | "apsClient/service" |
| | | "github.com/gin-gonic/gin" |
| | |
| | | } |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // GetProductProgressRealTime |
| | | // @Tags 生产数量 |
| | | // @Summary 实时获取生产进度 |
| | | // @Produce application/json |
| | | // @Param object body request.SendProcessParams true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.ProductProgress} "成功" |
| | | // @Router /v1/plc/productProgressRealTime [post] |
| | | func (slf *PlcApi) GetProductProgressRealTime(c *gin.Context) { |
| | | var params request.GetProductProgress |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | var finishNumber, totalNumber int64 |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK { |
| | | return |
| | | } |
| | | for _, addressItem := range plcConfig.Details { |
| | | if addressItem.FieldName == constvar.PlcStartAddressTypeFinishNumber { |
| | | value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type) |
| | | if err != nil { |
| | | logx.Infof("plc read finish number err: %v", err) |
| | | continue |
| | | } |
| | | finishNumber = cast.ToInt64(value) |
| | | logx.Infof("plc read finish number: %v", finishNumber) |
| | | break |
| | | } |
| | | } |
| | | |
| | | for _, addressItem := range plcConfig.Details { |
| | | if addressItem.FieldName == constvar.PlcStartAddressTypeTotalNumber { |
| | | value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type) |
| | | if err != nil { |
| | | logx.Infof("plc read total number err: %v", err) |
| | | continue |
| | | } |
| | | totalNumber = cast.ToInt64(value) |
| | | logx.Infof("plc read total number: %v", totalNumber) |
| | | break |
| | | } |
| | | } |
| | | resp := new(response.ProductProgress) |
| | | resp.FinishNumber = cast.ToInt(finishNumber) |
| | | resp.TotalNumber = cast.ToInt(totalNumber) |
| | | |
| | | plcStatus := 1 //断开连接 |
| | | isConnect := apacheplc4x.IsConnect() |
| | | if isConnect { |
| | | if resp.FinishNumber > 0 { //生产 |
| | | plcStatus = 2 |
| | | } else { //待机 |
| | | plcStatus = 3 |
| | | } |
| | | } |
| | | resp.PlcStatus = plcStatus |
| | | |
| | | ctx.OkWithDetailed(resp) |
| | | } |