private void tmWorker(object sender, System.Timers.ElapsedEventArgs e) { try { tmWorkTimer.Stop(); foreach (KeyValuePair <string, Car> kvp in dicCar) { //反馈给总控WCS设备状态 string id = Guid.NewGuid().ToString(); string deviceNo = kvp.Value.CarNo; string mode = kvp.Value.Mode.ToString(); string status = kvp.Value.Status.ToString(); string taskNo = kvp.Value.TaskNo; string fork = kvp.Value.ForkStatus.ToString(); string load = kvp.Value.Load.ToString(); string aisleNo = kvp.Value.CarNo.Substring(0, 2); string column = kvp.Value.Column.ToString(); string layer = kvp.Value.Layer.ToString(); string alarmCode = kvp.Value.AlarmCode.ToString(); DataRow[] drs = dtDeviceAlarm.Select(string.Format("Flag=2 and AlarmCode={0}", alarmCode)); string alarmDesc = ""; if (alarmCode != "0") { if (drs.Length > 0) { alarmDesc = drs[0]["AlarmDesc"].ToString(); } else { alarmDesc = "穿梭车未知错误!"; } } string sender1 = "admin"; string Json = "[{\"id\":\"" + id + "\",\"deviceNo\":\"" + Program.WarehouseCode + deviceNo + "\",\"mode\":\"" + mode + "\",\"status\":\"" + status + "\",\"taskNo\":\"" + taskNo + "\",\"fork\":\"" + fork + "\",\"load\":\"" + load + "\",\"aisleNo\":\"" + aisleNo + "\",\"column\":\"" + column + "\",\"layer\":\"" + layer + "\",\"alarmCode\":\"" + alarmCode + "\",\"sendDate\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\",\"sender\":\"" + sender1 + "\",\"field1\":\"\",\"field2\":\"" + alarmDesc + "\",\"field3\":\"\"" + "}]"; Logger.Debug("上报设备编号[" + deviceNo + "]的状态"); string message = Program.send("transWCSDevice", Json); App.Dispatching.Process.RtnMessage rtnMessage = JsonHelper.JSONToObject <App.Dispatching.Process.RtnMessage>(message); Logger.Debug("上报设备编号[" + deviceNo + "]的状态,收到反馈:" + rtnMessage.returnCode + ":" + rtnMessage.message); } } catch (Exception ex) { Logger.Error("frmMonitor在上报设备状态时发生错误:" + ex.Message); } finally { tmWorkTimer.Start(); ClearMemory(); } }
private void tmWorker(object sender, System.Timers.ElapsedEventArgs e) { try { tmWorkTimer.Stop(); foreach (KeyValuePair <string, Crane> kvp in dicCrane) { //反馈给总控WCS设备状态 string id = Guid.NewGuid().ToString(); string deviceNo = "01" + kvp.Value.CraneNo; string mode = kvp.Value.Mode.ToString(); string status = kvp.Value.Status.ToString(); string taskNo = kvp.Value.TaskNo; string fork = kvp.Value.ForkStatus.ToString(); string load = kvp.Value.Load.ToString(); string aisleNo = kvp.Value.Row.ToString(); string column = kvp.Value.Column.ToString(); string layer = kvp.Value.Layer.ToString(); string alarmCode = kvp.Value.AlarmCode.ToString(); string sender1 = "admin"; string Json = "[{\"id\":\"" + id + "\",\"deviceNo\":\"" + deviceNo + "\",\"mode\":\"" + mode + "\",\"status\":\"" + status + "\",\"taskNo\":\"" + taskNo + "\",\"fork\":\"" + fork + "\",\"load\":\"" + load + "\",\"aisleNo\":\"" + aisleNo + "\",\"column\":\"" + column + "\",\"layer\":\"" + layer + "\",\"alarmCode\":\"" + alarmCode + "\",\"sendDate\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\",\"sender\":\"" + sender1 + "\",\"field1\":\"\",\"field2\":\"\",\"field3\":\"\"" + "}]"; Logger.Info("上报设备状态"); string message = Program.send("transWCSDevice", Json); App.Dispatching.Process.RtnMessage rtnMessage = JsonHelper.JSONToObject <App.Dispatching.Process.RtnMessage>(message); Logger.Info("上报设备状态,收到反馈:" + rtnMessage.returnCode + ":" + rtnMessage.message); } } catch (Exception ex) { Logger.Error("frmMonitorB在上报设备状态时发生错误:" + ex.Message); } finally { tmWorkTimer.Start(); } }