| | |
| | | { |
| | | private readonly SqlSugarRepository<WcsPlc> _wcsPlcRep; |
| | | private readonly SysCacheService _sysCacheService; |
| | | private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId); |
| | | public WcsPlcService(SqlSugarRepository<WcsPlc> wcsPlcRep, SysCacheService sysCacheService) |
| | | { |
| | | _wcsPlcRep = wcsPlcRep; |
| | |
| | | var modService = new { PLCTaskAction.boRunningState, PLCTaskAction.boOffline, PLCTaskAction.boRefresh, PLCTaskAction.boDemo, PLCTaskAction.boDrumReversal, PLCTaskAction.boOutLock, PLCTaskAction.boEnterLock }; |
| | | return new { listPlc, modService }; |
| | | } |
| | | |
| | | [HttpGet] |
| | | [ApiDescriptionSettings(Name = "GetCarDL")] |
| | | [DisplayName("获取穿梭车电量")] |
| | | public async Task<dynamic> GetCarDL() |
| | | { |
| | | var listPlc = await _wcsPlcRep.AsQueryable() |
| | | .Where(s => s.Type == PLCTypeEnum.ShuttleCar) |
| | | .ToListAsync(); |
| | | |
| | | List<Dictionary<string, string>> _dicList = new List<Dictionary<string, string>>(); |
| | | foreach (var modPlc in listPlc) |
| | | { |
| | | var modbus = new ModbusUtil(modPlc); |
| | | var listPlcDevice = _db.Queryable<WcsDevice>().First(s => s.PlcId == modPlc.Id); |
| | | var (result, value) = modbus.GetDBValue(listPlcDevice.PosType, listPlcDevice.PlcPos); |
| | | if (result.IsSucceed) |
| | | { |
| | | var listPlcStation = _db.Queryable<WcsPosition>().Where(s => s.DeviceId == modPlc.Id).ToList(); |
| | | var modCarDl = listPlcStation.FirstOrDefault(s => s.Text == "电池电量"); |
| | | var (resultDl, valueDl) = modbus.GetDBValue(modCarDl.PosType, modCarDl.PlcPos); |
| | | if (resultDl.IsSucceed) |
| | | { |
| | | Dictionary<string, string> _dic = new Dictionary<string, string>(); |
| | | _dic.Add(modPlc.Text, valueDl); |
| | | |
| | | _dicList.Add(_dic); |
| | | } |
| | | } |
| | | } |
| | | return new { _dicList }; |
| | | } |
| | | /// <summary> |
| | | /// 获取位置信息 |
| | | /// </summary> |