public bool GetInfo() { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; string input = string.Empty; try { if (getInfoNum == 1) { #region 获取温度左前25 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetTemStrs1.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTemStrs1.Split(',')[j], output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int k = 0; k < this.floors[j].Stations[0].Temperatures.Length / 2; k++) { this.Floors[j].Stations[0].Temperatures[k] = (float)int.Parse(output.Substring(k * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier) / 10; } } #endregion #region 获取真空 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetVacuumStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetVacuumStr, output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), true, true); for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].Vacuum = (float)int.Parse(output.Substring(j * 8, 8), System.Globalization.NumberStyles.AllowHexSpecifier); } //for (int j = 0; j < this.Floors.Count; j++) //{ // uint num = uint.Parse(output.Substring(32 - j * 8, 8), System.Globalization.NumberStyles.AllowHexSpecifier); // byte[] floatVals = BitConverter.GetBytes(num); // this.Floors[j].Vacuum = BitConverter.ToSingle(floatVals, 0); //} #endregion } else if (getInfoNum == 3) { #region 获取温度左后25 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetTemStrs2.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTemStrs2.Split(',')[j], output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int k = 0; k < this.floors[j].Stations[0].Temperatures.Length / 2; k++) { this.Floors[j].Stations[0].Temperatures[Option.TemperaturePointCount / 2 + k] = (float)int.Parse(output.Substring(k * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier) / 10; } } #endregion #region 获取三色灯状态 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetTrichromaticLampStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTrichromaticLampStr, output)); return(false); } if (output.Substring(6, 1) == "1") { this.TriLamp = TriLamp.Red; } else if (output.Substring(7, 1) == "1") { this.TriLamp = TriLamp.Green; } else if (output.Substring(8, 1) == "1") { this.TriLamp = TriLamp.Yellow; } else { this.TriLamp = TriLamp.Unknown; } #endregion } else if (getInfoNum == 5) { #region 获取温度右前25 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetTemStrs3.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTemStrs3.Split(',')[j], output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int k = 0; k < this.floors[j].Stations[1].Temperatures.Length / 2; k++) { this.Floors[j].Stations[1].Temperatures[k] = (float)int.Parse(output.Substring(k * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier) / 10; } } #endregion } else if (getInfoNum == 7) { #region 获取温度右后25 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetTemStrs4.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTemStrs4.Split(',')[j], output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int k = 0; k < this.floors[j].Stations[1].Temperatures.Length / 2; k++) { this.Floors[j].Stations[1].Temperatures[Option.TemperaturePointCount / 2 + k] = (float)int.Parse(output.Substring(k * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier) / 10; } } #endregion #region 获取网控状态 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetNetControlStatusStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetNetControlStatusStr, output)); return(false); } for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].IsNetControlOpen = output.Substring(6 + j, 1) == "1"; } #endregion } else if (getInfoNum == 9) { #region 获取运行时间 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plc.GetInfo(false, GetRuntimeStrs[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRuntimeStrs[j], output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); this.Floors[j].RunMinutes = int.Parse(output.Substring(0, 4), System.Globalization.NumberStyles.AllowHexSpecifier); this.Floors[j].RunMinutesSet = int.Parse(output.Substring(8, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } #endregion #region 获取剩余时间 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetRemainTimeStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRemainTimeStr, output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].RunRemainMinutes = int.Parse(output.Substring(j * 8, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } #endregion } if (getInfoNum % 2 == 0) { #region 获取真空状态 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetVacuumStatusStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetVacuumStatusStr, output)); return(false); } for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].IsVacuum = output.Substring(6 + j, 1) == "0"; } #endregion #region 报警信息 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetAlarmStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetAlarmStr, output)); return(false); } this.Alarm2BinString = PanasonicPLC.Convert2BinStringForAlarm(output.TrimEnd('\r')); if (this.Alarm2BinString != this.PreAlarm2BinString) { this.AlarmStr = string.Empty; for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].AlarmStr = string.Empty; } List <AlarmLog> alarmLogs = new List <AlarmLog>(); for (int x = 0; x < this.Alarm2BinString.Length; x++) { if (x > Alarm.Alarms.Count - 1) { break; } char c = this.Alarm2BinString[x]; char cPre = this.PreAlarm2BinString.Length < this.Alarm2BinString.Length ? '0' : this.PreAlarm2BinString[x]; if (c == '1') { Alarm alarm = (from a in Alarm.Alarms where a.Id == x + 1 select a).ToList()[0]; if (alarm.FloorNum == 0) { if (cPre == '0') { AlarmLog.Stop(AlarmType.Oven, x + 1, this.Id, out msg); } } else if (alarm.FloorNum > 0 && alarm.FloorNum <= this.Floors.Count) { this.Floors[alarm.FloorNum - 1].AlarmStr += alarm.AlarmStr + ","; if (cPre == '0') { AlarmLog alarmLog = new AlarmLog(); alarmLog.AlarmId = x + 1; alarmLog.AlarmType = AlarmType.Floor; alarmLog.TypeId = this.Floors[alarm.FloorNum - 1].Id; alarmLogs.Add(alarmLog); } } } else if (c == '0') { Alarm alarm = (from a in Alarm.Alarms where a.Id == x + 1 select a).ToList()[0]; if (alarm.FloorNum == 0) { this.AlarmStr += alarm.AlarmStr + ","; if (cPre == '1') { AlarmLog alarmLog = new AlarmLog(); alarmLog.AlarmId = x + 1; alarmLog.AlarmType = AlarmType.Oven; alarmLog.TypeId = this.Id; alarmLogs.Add(alarmLog); } } else if (alarm.FloorNum > 0 && alarm.FloorNum <= this.Floors.Count) { if (cPre == '1') { AlarmLog.Stop(AlarmType.Floor, x + 1, this.Floors[alarm.FloorNum - 1].Id, out msg); } } } } if (!AlarmLog.Add(alarmLogs, out msg)) { Error.Alert(msg); } } this.PreAlarm2BinString = this.Alarm2BinString; #endregion #region 获取烤箱门状态 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetDoorStatusStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetDoorStatusStr, output)); return(false); } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < this.Floors.Count; j++) { switch (int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier)) { case 0: this.Floors[j].DoorStatusNotFinal = DoorStatus.关闭; break; case 1: this.Floors[j].DoorStatusNotFinal = DoorStatus.打开; break; case 2: this.Floors[j].DoorStatusNotFinal = DoorStatus.异常; break; default: this.Floors[j].DoorStatusNotFinal = DoorStatus.未知; break; } } //Thread.Sleep(100); #endregion #region 获取烤箱门的运动状态 for (int k = 0; k < 2; k++) { input = Current.option.GetOvenDoorRunStrs.Split(',')[k]; output = string.Empty; if (!this.Plc.GetInfo(false, input, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", input, output)); return(false); } for (int j = 0; j < this.Floors.Count; j++) { if (output.Substring(6 + j, 1) == "1") { if (k == 0) { this.Floors[j].DoorIsOpenning = true; } else { this.Floors[j].DoorIsClosing = true; } } else { if (k == 0) { this.Floors[j].DoorIsOpenning = false; } else { this.Floors[j].DoorIsClosing = false; } } } } #endregion } #region 获取运行状态 output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetRunStatusStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRunStatusStr, output)); return(false); } for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].IsBaking = output.Substring(6 + j, 1) == "1"; } Thread.Sleep(100); #endregion #region 获取烤箱夹具状态 if (!this.Plc.GetInfo(false, Current.option.GetOvenClampStatusStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetOvenClampStatusStr, output)); return(false); } int[] iOut = new int[10]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } for (int j = 0; j < this.Floors.Count; j++) { for (int k = 0; k < this.Floors[j].Stations.Count; k++) { switch (iOut[j * 2 + k]) { case 1: this.Floors[j].Stations[k].ClampStatus = ClampStatus.无夹具; break; case 2: this.Floors[j].Stations[k].ClampStatus = this.Floors[j].Stations[k].ClampStatus == ClampStatus.空夹具 ? ClampStatus.空夹具 : ClampStatus.满夹具; break; case 4: this.Floors[j].Stations[k].ClampStatus = ClampStatus.异常; break; default: this.Floors[j].Stations[k].ClampStatus = ClampStatus.未知; break; } } } #endregion #region 获取是否运行完成 for (int k = 0; k < 2; k++) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.GetBakingIsFinishedStrs.Split(',')[k], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetBakingIsFinishedStrs.Split(',')[k], output)); return(false); } for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].Stations[k].IsBakeFinished = output.Substring(6 + j, 1) == "1"; } } #endregion #region 写指令 控制开关门、启动运行、卸真空 for (int j = 0; j < this.Floors.Count; j++) { if (this.Floors[j].DoorIsOpenning && this.Floors[j].DoorStatusNotFinal != DoorStatus.打开) { this.Floors[j].DoorStatus = DoorStatus.正在打开; } else if (this.Floors[j].DoorIsClosing && this.Floors[j].DoorStatusNotFinal != DoorStatus.关闭) { this.Floors[j].DoorStatus = DoorStatus.正在关闭; } else { this.Floors[j].DoorStatus = this.Floors[j].DoorStatusNotFinal; } #region 控制开门 if (this.Floors[j].toOpenDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.OpenOvenDoorStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.OpenOvenDoorStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送开门指令到{0}:{1}", this.Floors[j].Name, Current.option.OpenOvenDoorStrs.Split(',')[j])); this.Floors[j].toOpenDoor = false; } #endregion #region 控制关门 if (this.Floors[j].toCloseDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.CloseOvenDoorStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.CloseOvenDoorStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送关门指令到{0}:{1}", this.Floors[j].Name, Current.option.CloseOvenDoorStrs.Split(',')[j])); this.Floors[j].toCloseDoor = false; } #endregion #region 启动运行 if (this.Floors[j].toStartBaking) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.StartBakingStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.StartBakingStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送启动运行指令到{0}:{1}", this.Floors[j].Name, Current.option.StartBakingStrs.Split(',')[j])); this.Floors[j].toStartBaking = false; } #endregion #region 结束运行 if (this.Floors[j].toStopBaking) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.StopBakingStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.StopBakingStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送停止运行指令到{0}:{1}", this.Floors[j].Name, Current.option.StopBakingStrs.Split(',')[j])); this.Floors[j].toStopBaking = false; } #endregion #region 开启网控 if (this.Floors[j].toOpenNetControl) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.OpenNetControlStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.OpenNetControlStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送开启网控指令到{0}:{1}", this.Floors[j].Name, Current.option.OpenNetControlStrs.Split(',')[j])); this.Floors[j].toOpenNetControl = false; } #endregion #region 报警复位 if (this.Floors[j].toAlarmReset) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.OvenAlarmResetStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.OvenAlarmResetStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送报警复位指令到{0}:{1}", this.Floors[j].Name, Current.option.OvenAlarmResetStrs.Split(',')[j])); this.Floors[j].toAlarmReset = false; } #endregion #region 泄真空 if (this.Floors[j].toUploadVacuum) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.UnloadVacuumStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.UnloadVacuumStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送泄真空指令到{0}:{1}", this.Floors[j].Name, Current.option.UnloadVacuumStrs.Split(',')[j])); this.Floors[j].toUploadVacuum = false; } #endregion } #endregion } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.getInfoNum++; if (getInfoNum >= 10) { this.AlreadyGetAllInfo = true; } this.getInfoNum %= 10; return(true); }
public bool GetInfo() { lock (this) { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { #region 获取信息 if (!this.Plc.GetInfo(false, "%01#RDD0020000204**", out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", "%01#RDD0020000204**", output)); return(false); } int[] iOut = new int[5]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } if (iOut[4] == 1) { if (!Current.BatteryScaner.IsReady) { Current.BatteryScaner.CanScan = true; LogHelper.WriteInfo(Current.BatteryScaner.Name + "【扫码日志】收到上料机给的请求扫码信号!"); } Current.BatteryScaner.IsReady = true; } else { Current.BatteryScaner.IsReady = false; Current.BatteryScaner.CanScan = false; } switch (iOut[3]) { case 1: this.TriLamp = TriLamp.Green; break; case 2: this.TriLamp = TriLamp.Yellow; break; case 3: this.TriLamp = TriLamp.Red; break; default: this.TriLamp = TriLamp.Unknown; break; } if (!this.Plc.GetInfo(false, "%01#RCP6R0212R0211R0210R0215R0214R0213**", out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", "%01#RCP6R0212R0211R0210R0215R0214R0213**", output)); return(false); } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j]) { case 1: //this.EmptyClampCount[j]++; this.Stations[j].Status = StationStatus.可放; break; case 2: if (output.Substring(6 + j, 1) == "1") { this.FillClampCount[j]++; this.Stations[j].Status = StationStatus.可取; } else { this.Stations[j].ClampStatus = ClampStatus.空夹具; this.Stations[j].Status = StationStatus.工作中; } break; case 4: this.Stations[j].ClampStatus = ClampStatus.异常; this.Stations[j].Status = StationStatus.可用; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; this.Stations[j].Status = StationStatus.可用; break; } //if (iOut[j] == 1) //{ // if (EmptyClampCount[j] > 2) // { // this.Stations[j].ClampStatus = ClampStatus.无夹具; // EmptyClampCount[j] = 3; // } //} //else //{ // EmptyClampCount[j] = 0; //} if (iOut[j] == 2 && output.Substring(6 + j, 1) == "1") { if (FillClampCount[j] > 2) { this.Stations[j].ClampStatus = ClampStatus.满夹具; FillClampCount[j] = 3; } } else { FillClampCount[j] = 0; } if (output.Substring(9 + j, 1) == "1") { this.CurrentPutStationId = this.Stations[j].Id; } //this.Stations[j].IsClampScanReady = iOut[j + 4] == 1; } //两台上料机信号传递(上料机器人和搬运机器人干涉防呆) //if (Current.feeders.Count(f => f.IsAlive) == Current.feeders.Count) //{ // if (Current.Robot.Plc.Id == this.Plc.Id) // { // var val = Current.feeders.First(f => f.Id != this.Id).D1026; // if (bOutputs[26] != val) // { // if (!this.Plc.SetInfo("D1026", val, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // } // for (var i = 0; i < Current.blankers.Count; i++) // { // var blanker = Current.blankers[i]; // if (blanker.IsAlive) // { // if (bOutputs[27 + i] != blanker.D2027) // { // var addr = string.Format("D{0:D4}", 1027 + i); // if (!this.Plc.SetInfo(addr, blanker.D2027, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // } // } // } // } // else // { // var val = Current.feeders.First(f => f.Id != this.Id).D1025; // if (bOutputs[25] != val) // { // if (!this.Plc.SetInfo("D1025", val, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // } // } //} #endregion Thread.Sleep(20); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; } return(true); }
public bool GetInfo() { lock (this) { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { if (!this.Plc.GetInfo(false, Current.option.GetBlankerInfoStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetBlankerInfoStr, output)); return(false); } int[] iOut = new int[3]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j]) { case 1: this.Stations[j].ClampStatus = ClampStatus.无夹具; this.Stations[j].Status = StationStatus.可放; break; case 2: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].Status = StationStatus.工作中; break; case 3: this.Stations[j].ClampStatus = ClampStatus.空夹具; this.Stations[j].Status = StationStatus.可取; break; case 4: this.Stations[j].ClampStatus = ClampStatus.异常; this.Stations[j].Status = StationStatus.可用; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; this.Stations[j].Status = StationStatus.可用; break; } } switch (iOut[2]) { case 1: this.TriLamp = TriLamp.Green; break; case 2: this.TriLamp = TriLamp.Yellow; break; case 3: this.TriLamp = TriLamp.Red; break; default: this.TriLamp = TriLamp.Unknown; break; } Thread.Sleep(100); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; } return(true); }
public bool GetInfo() { if (!this.Plcs[0].IsPingSuccess) { IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plcs[0].IP); return false; } string msg = string.Empty; string output = string.Empty; try { if (getInfoNum % 2 == 0) { #region 获取温度 for (int j = 0; j < this.Floors.Count; j++) { output = string.Empty; if (!this.Plcs[0].GetInfo(false, GetTemStrs[j], out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", GetTemStrs[j], output)); return false; } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int k = 0; k < this.floors[j].Temperatures.Length; k++) { this.Floors[j].Temperatures[k] = (float)int.Parse(output.Substring(k * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier) / 10; } Thread.Sleep(100); } #endregion } else if (getInfoNum == 1) { #region 获取真空 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetVacuumStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetVacuumStr, output)); return false; } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), true); for (int j = 0; j < this.Floors.Count; j++) { uint num = uint.Parse(output.Substring(16 - j * 8, 8), System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals = BitConverter.GetBytes(num); this.Floors[j].Vacuum = BitConverter.ToSingle(floatVals, 0); } Thread.Sleep(100); #endregion #region 获取运行状态 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetRunStatusStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRunStatusStr, output)); return false; } for (int j = 0; j < this.Floors.Count; j++) { if (output.Substring(6 + j, 1) == "1") { this.Floors[j].IsBaking = true; this.Floors[j].Runmode = RunMode.自动; } else if (output.Substring(9 + j, 1) == "1") { //this.Floors[j].IsBaking = true; this.Floors[j].IsBaking = false;//手动调试加热不算加热 this.Floors[j].Runmode = RunMode.手动; } else { this.Floors[j].IsBaking = false; this.Floors[j].Runmode = RunMode.未运行; } } Thread.Sleep(100); #endregion #region 获取三色灯状态 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetTrichromaticLampStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetTrichromaticLampStr, output)); return false; } if (output.Substring(6, 1) == "1") { this.triLamp = TriLamp.Red; } else if (output.Substring(7, 1) == "1") { this.triLamp = TriLamp.Green; } else if (output.Substring(8, 1) == "1") { this.triLamp = TriLamp.Yellow; } else { this.triLamp = TriLamp.Unknown; } #endregion } else if (getInfoNum == 3) { #region 获取工艺时间 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetRunMinutesSetStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRunMinutesSetStr, output)); return false; } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].RunMinutesSet = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); Thread.Sleep(100); } #endregion #region 获取已运行时间 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetRuntimeStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetRuntimeStr, output)); return false; } output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].RunMinutes = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); Thread.Sleep(100); } #endregion #region 报警信息 output = string.Empty; if (!this.Plcs[0].GetInfo(false, Current.option.GetAlarmStr, out output, out msg)) { Error.Alert(msg); this.Plcs[0].IsAlive = false; return false; } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetAlarmStr, output)); return false; } this.Alarm2BinString = PanasonicPLC.Convert2BinStringForAlarm(output.TrimEnd('\r')); if (this.Alarm2BinString != this.PreAlarm2BinString) { this.AlarmStr = string.Empty; for (int j = 0; j < this.Floors.Count; j++) { this.Floors[j].AlarmStr = string.Empty; } List<AlarmLog> alarmLogs = new List<AlarmLog>(); for (int x = 0; x < this.Alarm2BinString.Length; x++) { if (x > Alarm.Alarms.Count - 1) { break; } char c = this.Alarm2BinString[x]; char cPre = this.PreAlarm2BinString.Length < this.Alarm2BinString.Length ? '0' : this.PreAlarm2BinString[x]; if (c == '1') { Alarm alarm = (from a in Alarm.Alarms where a.Id == x + 1 select a).ToList()[0]; if (alarm.FloorNum == 0) { this.AlarmStr += alarm.AlarmStr + ","; if (cPre == '0') { AlarmLog alarmLog = new AlarmLog(); alarmLog.AlarmId = x + 1; alarmLog.AlarmType = AlarmType.Oven; alarmLog.TypeId = this.Id; alarmLogs.Add(alarmLog); } } else if (alarm.FloorNum > 0 && alarm.FloorNum <= this.Floors.Count) { this.Floors[alarm.FloorNum - 1].AlarmStr += alarm.AlarmStr + ","; if (cPre == '0') { AlarmLog alarmLog = new AlarmLog(); alarmLog.AlarmId = x + 1; alarmLog.AlarmType = AlarmType.Floor; alarmLog.TypeId = this.Floors[alarm.FloorNum - 1].Id; alarmLogs.Add(alarmLog); } } } else if (c == '0') { Alarm alarm = (from a in Alarm.Alarms where a.Id == x + 1 select a).ToList()[0]; if (alarm.FloorNum == 0) { if (cPre == '1') { AlarmLog.Stop(AlarmType.Oven, x + 1, this.Id, out msg); } } else if (alarm.FloorNum > 0 && alarm.FloorNum <= this.Floors.Count) { if (cPre == '1') { AlarmLog.Stop(AlarmType.Floor, x + 1, this.Floors[alarm.FloorNum - 1].Id, out msg); } } } } if (!AlarmLog.Add(alarmLogs, out msg)) { Error.Alert(msg); } } this.PreAlarm2BinString = this.Alarm2BinString; #endregion } } catch (Exception ex) { Error.Alert(ex); } this.Plcs[0].IsAlive = true; this.getInfoNum++; if (getInfoNum >= 4) { this.AlreadyGetAllInfo = true; } this.getInfoNum %= 4; return true; }
public bool GetInfo() { lock (this) { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { if (!this.Plc.GetInfo(false, "%01#RDD0001400016**", out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", "%01#RDD0001400016**", output)); return(false); } int[] iOut = new int[3]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j]) { case 1: this.Stations[j].ClampStatus = ClampStatus.无夹具; this.Stations[j].Status = StationStatus.可放; break; case 2: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].Status = StationStatus.工作中; break; case 3: this.Stations[j].ClampStatus = ClampStatus.空夹具; this.Stations[j].Status = StationStatus.可取; break; case 4: this.Stations[j].ClampStatus = ClampStatus.异常; this.Stations[j].Status = StationStatus.可用; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; this.Stations[j].Status = StationStatus.可用; break; } } switch (iOut[2]) { case 1: this.TriLamp = TriLamp.Green; break; case 2: this.TriLamp = TriLamp.Yellow; break; case 3: this.TriLamp = TriLamp.Red; break; default: this.TriLamp = TriLamp.Unknown; break; } #region 获取信息 //var bOutputs = new ushort[] { }; //if (!this.Plc.GetInfo("D2000", (ushort)30, out bOutputs, out msg)) //{ // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; //} //for (int j = 0; j < this.Stations.Count; j++) //{ // int jj = 1 - j; // if (bOutputs[10 + j] == 1) // { // this.Stations[jj].ClampStatus = ClampStatus.空夹具; // this.Stations[jj].Status = StationStatus.可取; // this.Stations[jj].SampleInfo = SampleInfo.未知; // } // else if (bOutputs[10 + j] == 2) // { // this.Stations[jj].ClampStatus = ClampStatus.无夹具; // this.Stations[jj].Status = StationStatus.可放; // } // else if (bOutputs[10 + j] == 3) // { // this.Stations[jj].ClampStatus = ClampStatus.满夹具; // this.Stations[jj].Status = StationStatus.工作中; // } // else if (bOutputs[10 + j] == 4) // { // this.Stations[jj].ClampStatus = ClampStatus.异常; // this.Stations[jj].Status = StationStatus.不可用; // } // else if (bOutputs[10 + j] == 5) //NG回炉 // { // this.Stations[jj].ClampStatus = ClampStatus.满夹具; // this.Stations[jj].Status = StationStatus.可取; // this.Stations[jj].SampleStatus = SampleStatus.水分NG; // } // else // { // this.Stations[jj].ClampStatus = ClampStatus.未知; // this.Stations[jj].Status = StationStatus.不可用; // } // var samResultVal = bOutputs[21 + j]; // if (samResultVal == 3 || samResultVal == 4) // { // var sampleStatus = samResultVal == 3 ? SampleStatus.水分OK : SampleStatus.水分NG; // if (this.Stations[jj].ClampStatus != ClampStatus.无夹具) // { // this.Stations[jj].SampleStatus = sampleStatus; // } // var floorStation = Station.GetStation(this.Stations[jj].FromStationId); // if (floorStation != null && floorStation.GetPutType == GetPutType.烤箱) // { // floorStation.GetFloor().Stations.ForEach(s => // { // if(s.ClampStatus == ClampStatus.满夹具) // { // s.SampleStatus = sampleStatus; // } // }); // } // } //} //switch (bOutputs[18]) //{ // case 1: this.TriLamp = TriLamp.Red; break; // case 2: this.TriLamp = TriLamp.Yellow; break; // case 3: this.TriLamp = TriLamp.Green; break; // default: this.TriLamp = TriLamp.Unknown; break; //} //this.Stations[0].DoorStatus = DoorStatus.打开; //this.Stations[1].DoorStatus = DoorStatus.打开; //if (bOutputs[25] == 1) //{ // if (!this.IsRasterInductive) // { // LogHelper.WriteInfo(string.Format("{0} --> 人员进入安全光栅感应区", this.Name)); // if (!Current.RGV.IsPausing && Current.RGV.Position <= Current.option.RGVStopPosition4RasterInductive) // { // if (Current.RGV.Stop(out msg)) // { // Error.Alert(string.Format("人员进入 {0} 安全光栅感应区域,已远程发送急停信号给 {1}", this.Name, Current.RGV.Name)); // } // else // { // Error.Alert(string.Format("人员进入 {0} 安全光栅感应区域,远程发送急停信号给 {1} 失败!", this.Name, Current.RGV.Name)); // } // } // } // this.IsRasterInductive = true; // this.AlarmStr = "安全光栅报警!"; //} //else //{ // if (this.IsRasterInductive) // { // LogHelper.WriteInfo(string.Format("{0} --> 安全光栅感应报警结束", this.Name)); // //if (!otherBlanker.IsRasterInductive && Current.RGV.IsPausing) // //{ // // if (Current.RGV.Restart(out msg)) // // { // // Tip.Alert(string.Format("{0} 安全光栅感应报警结束,已远程发送继续运动信号给 {1}", this.Name, Current.RGV.Name)); // // } // // else // // { // // Error.Alert(string.Format("{0} 安全光栅感应报警结束,远程发送继续运动信号给 {1} 失败!", this.Name, Current.RGV.Name)); // // } // //} // } // this.IsRasterInductive = false; // this.AlarmStr = ""; //} //this.D2027 = bOutputs[27]; //if (this.toCancelRasterInductive) //{ // if (!this.Plc.SetInfo("D2019", (ushort)1, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // LogHelper.WriteInfo(string.Format("成功发送光栅感应报警复位指令到{0}:{1}", this.Name, "D2019:1")); // this.toCancelRasterInductive = false; //} //for (int j = 0; j < this.Stations.Count; j++) //{ // int jj = 1 - j; // if (this.Stations[j].SampleInfo == SampleInfo.无样品) // { // if (bOutputs[21 + jj] == 0) // { // if (!this.Plc.SetInfo("D" + (2021 + jj).ToString("D4"), (ushort)1, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // LogHelper.WriteInfo(string.Format("成功发送无水分夹具指令到{0}:{1}", this.Name, "D" + (2021 + jj).ToString("D4") + "1")); // } // } // if (this.Stations[j].SampleInfo == SampleInfo.有样品) // { // if (bOutputs[21 + jj] == 0) // { // if (!this.Plc.SetInfo("D" + (2021 + jj).ToString("D4"), (ushort)2, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } // LogHelper.WriteInfo(string.Format("成功发送有水分夹具指令到{0}:{1}", this.Name, "D" + (2021 + jj).ToString("D4") + "2")); // } // } //} //避让功能 //if (Current.Feeder.Plc.IsAlive && bOutputs[26] != Current.Feeder.D1025) //{ // if (!this.Plc.SetInfo("D2026", Current.Feeder.D1025, out msg)) // { // Error.Alert(msg); // this.Plc.IsAlive = false; // return false; // } //} #endregion Thread.Sleep(100); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; } return(true); }
public bool GetInfo() { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { if (!this.Plc.GetInfo(false, Current.option.GetFeederInfoStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetFeederInfoStr, output)); return(false); } int[] iOut = new int[10]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j]) { case 1: this.EmptyClampCount[j]++; break; case 2: this.Stations[j].ClampStatus = ClampStatus.空夹具; break; case 3: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].SampleStatus = SampleStatus.非样品位; break; case 31: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].SampleStatus = SampleStatus.样品位; break; case 4: this.Stations[j].ClampStatus = ClampStatus.异常; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; break; } if (iOut[j] == 1) { if (EmptyClampCount[j] > 2) { this.Stations[j].ClampStatus = ClampStatus.无夹具; EmptyClampCount[j] = 3; } } else { EmptyClampCount[j] = 0; } switch (iOut[j + 2]) { case 1: this.Stations[j].DoorStatus = DoorStatus.打开; break; case 2: this.Stations[j].DoorStatus = DoorStatus.关闭; break; case 4: this.Stations[j].DoorStatus = DoorStatus.异常; break; default: this.Stations[j].DoorStatus = DoorStatus.未知; break; } if (this.Stations[j].ClampStatus == ClampStatus.无夹具) { this.Stations[j].Status = StationStatus.可放; } else if (this.Stations[j].ClampStatus == ClampStatus.满夹具) { this.Stations[j].Status = StationStatus.可取; } else if (this.Stations[j].ClampStatus == ClampStatus.空夹具) { this.Stations[j].Status = StationStatus.工作中; } else { this.Stations[j].Status = StationStatus.可用; } } switch (iOut[5]) { case 0: this.Stations.ForEach(s => s.IsClampScanReady = false); this.ClampScaner.IsReady = false; break; case 1: this.Stations[0].IsClampScanReady = true; this.ClampScaner.IsReady = true; this.CurrentPutStationId = this.Stations[0].Id; break; case 2: this.Stations[1].IsClampScanReady = true; this.ClampScaner.IsReady = true; this.CurrentPutStationId = this.Stations[1].Id; break; } if (iOut[6] == 1) { if (!this.BatteryScaner.IsReady) { this.BatteryScaner.CanScan = true; } this.BatteryScaner.IsReady = true; } else { this.BatteryScaner.IsReady = false; this.BatteryScaner.CanScan = false; } switch (iOut[7]) { case 0: if (this.JawMoveType == JawMoveType.PulltabToRotary) { //if(this.CurrentPutClampBatteryCount < Clamp.BatteryCount) //{ if (!Battery.UpdateClampId(this.CacheBatteryOut(), Station.GetStation(CurrentPutStationId).ClampId, out msg)) { LogHelper.WriteError(msg); } //} } else if (this.JawMoveType == JawMoveType.PulltabToBatteryCache) { this.BatteryCache.Push(this.CacheBatteryOut()); } else if (this.JawMoveType == JawMoveType.BatteryCacheToRotary) { if (this.CurrentBatteryCount < Clamp.BatteryCount) { if (!Battery.UpdateClampId(this.BatteryCache.Pop().ToString(), Station.GetStation(CurrentPutStationId).ClampId, out msg)) { LogHelper.WriteError(msg); } } } else if (this.JawMoveType == JawMoveType.SampleToRotary) { /// } this.JawMoveType = JawMoveType.Motionless; break; case 1: this.JawMoveType = JawMoveType.PulltabToRotary; break; case 2: this.JawMoveType = JawMoveType.PulltabToBatteryCache; break; case 3: this.JawMoveType = JawMoveType.BatteryCacheToRotary; break; case 4: this.JawMoveType = JawMoveType.SampleToRotary; break; } this.CurrentBatteryCount = iOut[8]; this.BatteryCache.SetCount(iOut[9]); #region 写指令 控制开关门 for (int j = 0; j < this.Stations.Count; j++) { #region 控制开门 if (this.Stations[j].toOpenDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.OpenFeederDoorStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.OpenOvenDoorStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送开门指令到{0}:{1}", this.Stations[j].Name, Current.option.OpenOvenDoorStrs.Split(',')[j])); this.Stations[j].toOpenDoor = false; } #endregion #region 控制关门 if (this.Stations[j].toCloseDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.CloseFeederDoorStrs.Split(',')[j], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.CloseOvenDoorStrs.Split(',')[j], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送关门指令到{0}:{1}", this.Stations[j].Name, Current.option.CloseOvenDoorStrs.Split(',')[j])); this.Stations[j].toCloseDoor = false; } #endregion } #endregion Thread.Sleep(100); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; return(true); }
public bool GetInfo() { if (!this.Plc.IsPingSuccess) { if (this.RotaterId > 0) { this.Rotater.IsAlive = false; } this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { if (!this.Plc.GetInfo(false, Current.option.GetBlankerInfoStr, out output, out msg)) { Error.Alert(msg); this.Rotater.IsAlive = false; this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetBlankerInfoStr, output)); return(false); } int[] iOut = new int[13]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j]) { case 1: this.Stations[j].ClampStatus = ClampStatus.无夹具; this.Stations[j].Status = StationStatus.可放; break; case 2: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].Status = StationStatus.工作中; break; case 3: this.Stations[j].ClampStatus = ClampStatus.空夹具; this.Stations[j].Status = StationStatus.可取; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; this.Stations[j].Status = StationStatus.可用; break; } } if (this.RotaterId > 0) { switch (iOut[6]) { case 1: this.Rotater.Station.ClampStatus = ClampStatus.无夹具; break; case 2: case 3: this.Rotater.Station.ClampStatus = ClampStatus.空夹具; break; default: this.Rotater.Station.ClampStatus = ClampStatus.异常; break; } switch (iOut[7]) { case 1: this.Rotater.Station.DoorStatus = DoorStatus.打开; break; case 2: this.Rotater.Station.DoorStatus = DoorStatus.关闭; break; default: this.Rotater.Station.DoorStatus = DoorStatus.异常; break; } if (this.Rotater.Station.ClampStatus == ClampStatus.无夹具 && this.Rotater.Station.DoorStatus == DoorStatus.打开) { this.Rotater.Station.Status = StationStatus.可放; } else if (this.Rotater.Station.ClampStatus == ClampStatus.空夹具 && this.Rotater.Station.DoorStatus == DoorStatus.打开) { this.Rotater.Station.Status = StationStatus.可取; } else { this.Rotater.Station.Status = StationStatus.工作中; } ClampOri clampOri = this.Stations[0].ClampOri; switch (iOut[12]) { case 1: this.Rotater.Station.ClampOri = clampOri == ClampOri.A ? ClampOri.B : ClampOri.A; break; case 2: this.Rotater.Station.ClampOri = clampOri; break; default: this.Rotater.Station.ClampOri = ClampOri.未知; break; } #region 控制开门 if (this.Rotater.Station.toOpenDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.RotaterOpenDoorStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.RotaterOpenDoorStr, output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送旋转台开门指令到{0}:{1}", this.Rotater.Station.Name, Current.option.RotaterOpenDoorStr)); this.Rotater.Station.toOpenDoor = false; } #endregion #region 控制关门 if (this.Rotater.Station.toCloseDoor) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.RotaterCloseDoorStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.RotaterCloseDoorStr, output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送旋转台关门指令到{0}:{1}", this.Rotater.Station.Name, Current.option.RotaterCloseDoorStr)); this.Rotater.Station.toCloseDoor = false; } #endregion #region 控制旋转 for (int x = 0; x < 2; x++) { if (this.Rotater.Station.toRotate[x]) { output = string.Empty; if (!this.Plc.GetInfo(false, Current.option.RotaterRotateStrs.Split(',')[x], out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.RotaterRotateStrs.Split(',')[x], output)); return(false); } LogHelper.WriteInfo(string.Format("成功发送旋转台旋转指令到{0}:{1}", this.Rotater.Station.Name, Current.option.RotaterRotateStrs.Split(',')[x])); this.Rotater.Station.toRotate[x] = false; } } #endregion } if (this.CacheId > 0) { for (int j = 0; j < this.Cache.Stations.Count; j++) { switch (iOut[8 + j]) { case 1: this.Cache.Stations[j].ClampStatus = ClampStatus.无夹具; this.Cache.Stations[j].Status = StationStatus.可放; break; case 2: this.Cache.Stations[j].ClampStatus = this.Cache.Stations[j].Clamp.Batteries.Count > 0 ? ClampStatus.满夹具 : ClampStatus.空夹具; this.Cache.Stations[j].Status = StationStatus.工作中; break; case 3: this.Cache.Stations[j].ClampStatus = this.Cache.Stations[j].Clamp.Batteries.Count > 0 ? ClampStatus.满夹具 : ClampStatus.空夹具; this.Cache.Stations[j].Status = StationStatus.可取; break; case 4: this.Cache.Stations[j].ClampStatus = ClampStatus.异常; this.Cache.Stations[j].Status = StationStatus.可用; break; default: this.Cache.Stations[j].ClampStatus = ClampStatus.未知; this.Cache.Stations[j].Status = StationStatus.可用; break; } this.Cache.Stations[j].Status = StationStatus.工作中; } } Thread.Sleep(100); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; return(true); }
public bool GetInfo() { lock (this) { if (!this.Plc.IsPingSuccess) { this.Plc.IsAlive = false; LogHelper.WriteError("无法连接到 " + this.Plc.IP); return(false); } string msg = string.Empty; string output = string.Empty; try { if (!this.Plc.GetInfo(false, Current.option.GetFeederInfoStr, out output, out msg)) { Error.Alert(msg); this.Plc.IsAlive = false; return(false); } if (output.Substring(3, 1) != "$") { LogHelper.WriteError(string.Format("与PLC通信格式错误,input:{0},output:{1}", Current.option.GetFeederInfoStr, output)); return(false); } int[] iOut = new int[6]; output = PanasonicPLC.ConvertHexStr(output.TrimEnd('\r'), false); for (int j = 0; j < iOut.Length; j++) { iOut[j] = int.Parse(output.Substring(j * 4, 4), System.Globalization.NumberStyles.AllowHexSpecifier); } if (iOut[0] == 1) { if (!this.BatteryScaner.IsReady) { this.BatteryScaner.CanScan = true; LogHelper.WriteInfo(this.BatteryScaner.Name + "【扫码日志】收到上料机给的请求扫码信号!"); } this.BatteryScaner.IsReady = true; } else { this.BatteryScaner.IsReady = false; this.BatteryScaner.CanScan = false; } for (int j = 0; j < this.Stations.Count; j++) { switch (iOut[j + 1]) { case 1: this.EmptyClampCount[j]++; this.Stations[j].Status = StationStatus.可放; break; case 2: this.Stations[j].ClampStatus = ClampStatus.空夹具; this.Stations[j].Status = StationStatus.工作中; break; case 3: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].Status = StationStatus.可取; break; case 31: this.Stations[j].ClampStatus = ClampStatus.满夹具; this.Stations[j].Status = StationStatus.可取; break; case 4: this.Stations[j].ClampStatus = ClampStatus.异常; this.Stations[j].Status = StationStatus.可用; break; default: this.Stations[j].ClampStatus = ClampStatus.未知; this.Stations[j].Status = StationStatus.可用; break; } if (iOut[j + 1] == 1) { if (EmptyClampCount[j] > 2) { this.Stations[j].ClampStatus = ClampStatus.无夹具; EmptyClampCount[j] = 3; } } else { EmptyClampCount[j] = 0; } this.Stations[j].IsClampScanReady = iOut[j + 4] == 1; } switch (iOut[3]) { case 1: this.TriLamp = TriLamp.Green; break; case 2: this.TriLamp = TriLamp.Yellow; break; case 3: this.TriLamp = TriLamp.Red; break; default: this.TriLamp = TriLamp.Unknown; break; } if (iOut[4] == 1 || iOut[5] == 1) { if (!this.ClampScaner.IsReady) { this.ClampScaner.CanScan = true; } this.ClampScaner.IsReady = true; } else { this.ClampScaner.IsReady = false; this.ClampScaner.CanScan = false; } //switch (iOut[5]) //{ // case 0: this.Stations.ForEach(s => s.IsClampScanReady = false); Current.ClampScaner.IsReady = false; break; // case 1: this.Stations[0].IsClampScanReady = true; Current.ClampScaner.IsReady = true; this.CurrentPutStationId = this.Stations[0].Id; break; // case 2: this.Stations[1].IsClampScanReady = true; Current.ClampScaner.IsReady = true; this.CurrentPutStationId = this.Stations[1].Id; break; //} //switch (iOut[7]) //{ // case 0: // if (this.JawMoveType == JawMoveType.PulltabToRotary) // { // //if(this.CurrentPutClampBatteryCount < Clamp.BatteryCount) // //{ // if (!Battery.UpdateClampId(this.CacheBatteryOut(), Station.GetStation(CurrentPutStationId).ClampId, out msg)) // { // LogHelper.WriteError(msg); // } // //} // } // else if (this.JawMoveType == JawMoveType.PulltabToBatteryCache) // { // this.BatteryCache.Push(this.CacheBatteryOut()); // } // else if (this.JawMoveType == JawMoveType.BatteryCacheToRotary) // { // if (this.CurrentBatteryCount < Clamp.BatteryCount) // { // if (!Battery.UpdateClampId(this.BatteryCache.Pop().ToString(), Station.GetStation(CurrentPutStationId).ClampId, out msg)) // { // LogHelper.WriteError(msg); // } // } // } // else if (this.JawMoveType == JawMoveType.SampleToRotary) // { // /// // } // this.JawMoveType = JawMoveType.Motionless; // break; // case 1: this.JawMoveType = JawMoveType.PulltabToRotary; break; // case 2: this.JawMoveType = JawMoveType.PulltabToBatteryCache; break; // case 3: this.JawMoveType = JawMoveType.BatteryCacheToRotary; break; // case 4: this.JawMoveType = JawMoveType.SampleToRotary; break; //} //this.CurrentBatteryCount = iOut[8]; //this.BatteryCache.SetCount(iOut[9]); Thread.Sleep(10); } catch (Exception ex) { Error.Alert(ex); } this.Plc.IsAlive = true; this.AlreadyGetAllInfo = true; } return(true); }