wxw
2025-06-09 dbde3162fd361dcba4316b58754ccecf39a81a9f
Admin.NET/WCS.Application/Hub/PlcDeviceHub.cs
@@ -16,7 +16,6 @@
[MapHub("/hubs/PlcDevice")]
public class PlcDeviceHub : Hub<IPlcDeviceHub>
{
    private static readonly IHubContext<PlcDeviceHub, IPlcDeviceHub> _plcDeviceHubContext = App.GetService<IHubContext<PlcDeviceHub, IPlcDeviceHub>>();
    private static readonly SysCacheService _sysCacheService = App.GetRequiredService<SysCacheService>();
    private static bool boRunningState = false;
    private static CancellationTokenSource cts;//取消线程标识
@@ -71,9 +70,9 @@
            // 用于保存每个设备的初始状态
            var initialStates = new Dictionary<long, WcsDeviceOutput>();
            var listPlc = _db.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine).ToList();
            var listPlc = _db.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine).Where(s => s.Enable == YesNoEnum.Y).ToList();
            var listPlcId = listPlc.Select(s => s.Id).ToList();
            var listPlcDevice = _db.Queryable<WcsDevice>().Where(s => s.DeviceType == DeviceTypeEnum.Business && listPlcId.Contains(s.PlcId)).Select<WcsDeviceOutput>().ToList();
            var listPlcDevice = _db.Queryable<WcsDevice>().Where(s => s.DeviceType == DeviceTypeEnum.Business && listPlcId.Contains(s.PlcId) && s.IsDelete).Select<WcsDeviceOutput>().ToList();
            var listPlcDeviceId = listPlcDevice.Select(s => s.Id).ToList();
            var listPlcStation = _db.Queryable<WcsPosition>().Where(s => listPlcDeviceId.Contains(s.DeviceId)).ToList();
            while (true)
@@ -142,7 +141,6 @@
                            {
                                (result, var palletNo) = modConn.GetPlcDBValue(modPositionPalletNo.PosType, modDevice.DbNumber, modPositionPalletNo.PlcPos, modPositionPalletNo.StringLength);
                                modDevice.PalletNo = Convert.ToString(palletNo);
                                Console.WriteLine(modDevice.DbNumber + "." + modPositionPalletNo.PlcPos + "----------");
                            }
                            if (modPlc.Type == PLCTypeEnum.ConveyorLine)
                            {
@@ -189,6 +187,13 @@
                                    modDevice.PickStorey = Convert.ToInt32(pickStorey);
                                }
                                if (modPlc.Type == PLCTypeEnum.StackingMachine)
                                {
                                    //跺机的起始工位用取货排列层
                                    modDevice.StartLocatNo = $"{modDevice.PickRow.ToString()}{modDevice.PickCol.ToString()}{modDevice.PickStorey.ToString()}";
                                    //跺机的目的工位用放货排列层
                                    modDevice.EndLocatNo = $"{modDevice.ReleaseRow.ToString()}{modDevice.ReleaseCol.ToString()}{modDevice.ReleaseStorey.ToString()}";
                                }
                            }
                        }
                        //else
@@ -204,7 +209,7 @@
                        if (initialStates.TryGetValue(modDevice.Id, out var initialState))
                        {
                            if (modDevice.Status != initialState.Status ||
                                modDevice.Plc != initialState.Plc ||
                                (modDevice.Plc.IsNullOrEmpty() && modDevice.Plc != initialState.Plc) ||
                                modDevice.Wcs != initialState.Wcs ||
                                modDevice.TaskNo != initialState.TaskNo ||
                                modDevice.TaskType != initialState.TaskType ||
@@ -220,7 +225,7 @@
                                     modDevice.PickStorey != initialState.PickStorey)))
                            {
                                // 通知用户变更
                                _plcDeviceHubContext.Clients.All.PublicPlcDevice(modDevice);
                                HubUtil.PublicPlcDevice(modDevice);
                            }
                        }
                        initialStates[modDevice.Id] = modDevice.Adapt<WcsDeviceOutput>();