| | |
| | | func (slf DevicePlcService) GetDevicePlc() (*model.DevicePlc, int) { |
| | | DevicePlc, err := model.NewDevicePlcSearch().SetDeviceId(conf.Conf.CurrentDeviceID).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | logx.Errorf("GetDevicePlc failed:%v", err) |
| | | return &model.DevicePlc{ |
| | | DeviceID: "", |
| | | Brand: "", |
| | |
| | | }, ecode.OK |
| | | } |
| | | if err != nil { |
| | | logx.Errorf("GetDevicePlc failed:%v", err) |
| | | return nil, ecode.DBErr |
| | | } |
| | | |
| | |
| | | func (slf DevicePlcService) GetDeviceChannelAmount() (int, error) { |
| | | plcConfig, code := slf.GetDevicePlc() |
| | | if code != ecode.OK || plcConfig.ID == 0 { |
| | | logx.Errorf("GetDeviceChannelAmount failed:%v, code:%v", plcConfig, code) |
| | | return 0, errors.New("未获取到PLC地址,请在工艺模型库中上传!") |
| | | } |
| | | if len(plcConfig.Details) == 0 { |
| | | logx.Errorf("GetDeviceChannelAmount failed, addressList == 0, %+v", plcConfig) |
| | | return 0, errors.New("未获取到PLC地址,请在工艺模型库中上传!") |
| | | } |
| | | return len(plcConfig.Details) / 2, nil |