/// <summary> /// 分配设备的DB1,DB2地址区 /// </summary> /// <returns></returns> protected bool AllocDevDBAddr() { try { if (devModel != null) { //配置DB1 AllocDevComAddrsDB1(); //配置DB2 AllocDevComAddrsDB2(); for (int i = 0; i < dicCommuDataDB1.Count(); i++) { int commuID = i + 1; DevCommDatatype commObj = dicCommuDataDB1[commuID]; if (commObj == null) { continue; } dicDataDB1Last[commObj.CommuID] = commObj.Val; } if (dicCommuDataDB2.Count() > 0) { foreach (KeyValuePair <int, DevCommDatatype> keyVal in dicCommuDataDB2) { if (keyVal.Value == null) { continue; } DevCommDatatype commObj = keyVal.Value; dicDataDB2Last[commObj.CommuID] = commObj.Val; } } return(true); } else { return(false); } } catch (System.Exception ex) { //触发错误日志,2004 int errorCode = 2004; string reStr = ""; if (!ECAMWCS.GetErrorContent(errorCode, ref reStr)) { AddLog("配置设备" + this.devModel.DeviceID + " 出现异常," + ex.Message + "," + ex.StackTrace, EnumLogType.错误); } else { reStr = "设备:" + this.devModel.DeviceID + reStr; reStr += (ex.Message + "," + ex.StackTrace); OnErrorHappen(errorCode, reStr, true); } return(false); } }
/// <summary> /// 刷新设备状态 /// </summary> public virtual void DevRefreshStatus() { switch (devRunningStatus) { case 1: { //空闲 if (this.devModel.DeviceStatus != EnumDevStatus.空闲.ToString()) { this.devModel.DeviceStatus = EnumDevStatus.空闲.ToString(); //更新数据库 this.devBll.UpdateDevStatus(this.devModel.DeviceID, this.devModel.DeviceStatus); } break; } case 2: { //工作中 if (this.devModel.DeviceStatus != EnumDevStatus.工作中.ToString()) { this.devModel.DeviceStatus = EnumDevStatus.工作中.ToString(); //更新数据库 this.devBll.UpdateDevStatus(this.devModel.DeviceID, this.devModel.DeviceStatus); } break; } case 3: { //故障 if (this.devModel.DeviceStatus != EnumDevStatus.故障.ToString()) { this.devModel.DeviceStatus = EnumDevStatus.故障.ToString(); this.devBll.UpdateDevStatus(this.devModel.DeviceID, this.devModel.DeviceStatus); //错误,2104 int errorCode = 2104; string errStr = ""; if (!ECAMWCS.GetErrorContent(errorCode, ref errStr)) { AddLog(devName + " 发生故障", EnumLogType.错误); } else { errStr = devName + errStr; OnErrorHappen(errorCode, errStr, false); } } break; } default: break; } }
private void buttonGetCode_Click(object sender, EventArgs e) { string[] blockStrs = ECAMWCS.SplitStrings(this.textBoxCode.Text); if (blockStrs == null || blockStrs.Count() < 7) { MessageBox.Show("寄存器数据少于7个,请重新输入"); return; } byte[] idBytes = new byte[12]; byte[] byteArray = new byte[14]; for (int j = 0; j < 7; j++) { int val = int.Parse(blockStrs[j]); byteArray[2 * j] = (byte)(val & 0xff); byteArray[2 * j + 1] = (byte)((val >> 8) & 0xff); } Array.Copy(byteArray, 1, idBytes, 0, 12); string batteryID = System.Text.Encoding.UTF8.GetString(idBytes); this.textBoxCodeVal.Text = batteryID; AddLog("二维码转换成功"); }
private void Form1_Load(object sender, EventArgs e) { ctlManager = new ECAMWCS(); ctlManager.AttachErrorHandler(ErrorEventHandler); ctlManager.AttachLogHandler(LogEventHandler); this.buttonStart.Enabled = false; this.buttonStop.Enabled = false; // this.tabPage1.Enabled = false; devBll = new DeviceBll(); ctlTaskBll = new ControlTaskBll(); ctlTaskIFBll = new ControlInterfaceBll(); palletBll = new OCVPalletBll(); batteryBll = new OCVBatteryBll(); manTaskBll = new ManageTaskBll(); plcRwObj = new PLCRW(); plcRwObj.eventLinkLost += PlcLostConnectHandler; HFReaderIF readerIF = new HFReaderIF(); rfidRW = new SgrfidRW(1); this.comboBoxComports.Items.Clear(); int i = 0; string[] ports = System.IO.Ports.SerialPort.GetPortNames(); foreach (string port in ports) { this.comboBoxComports.Items.Add(port); i++; } if (ports != null && ports.Count() > 0) { this.comboBoxComports.Text = ports[0]; } rfidWorkingThread = new Thread(new ThreadStart(SysWorkingProc)); rfidWorkingThread.IsBackground = true; rfidWorkingThread.Name = "RFID读写卡测试线程"; }
//public string[] AddrDB1 //{ // get // { // return plcAddrDb1; // } // set // { // plcAddrDb1 = value; // } //} //public string[] AddrDB2 //{ // get // { // return plcAddrDb2; // } // set // { // plcAddrDb2 = value; // } //} //public byte[] DB1 //{ // get // { // return plcDataDb1; // } // private set { } //} //public byte[] DB2 //{ // get // { // return plcDataDb2; // } // private set { } //} #endregion #region 公共方法 public bool Init() { string reStr = ""; //分配地址 if (!AllocDevDBAddr()) { return(false); } //系统启动后,先把DB1数据读上来 if (this.devModel.DeviceID == "1001") { plcRW.StationNumber = 0x01; } else if (this.devModel.DeviceID == "1002") { plcRW.StationNumber = 0x02; } short[] db1Vals = null; if (dicCommuDataDB1.Count() > 0) { if (!plcRW.ReadMultiDB(devModel.DB1AddrStart, dicCommuDataDB1.Count(), ref db1Vals)) { AddLog("恢复设备命令失败", EnumLogType.错误); return(false); } for (int i = 0; i < dicCommuDataDB1.Count(); i++) { int commuID = i + 1; DevCommDatatype commObj = dicCommuDataDB1[commuID]; if (commObj == null) { continue; } commObj.Val = db1Vals[i]; dicDataDB1Last[commObj.CommuID] = commObj.Val; } } if (this.devModel.DeviceType == EnumDevType.堆垛机.ToString() || this.devModel.DeviceType == EnumDevType.机械手.ToString()) { byte val = byte.Parse(this.dicCommuDataDB1[1].Val.ToString()); if (val == 2) { startWriteParam = true; } else { startWriteParam = false; } val = byte.Parse(this.dicCommuDataDB1[2].Val.ToString()); if (val == 2) { writeCompleted = true; } else { writeCompleted = false; } val = byte.Parse(this.dicCommuDataDB1[3].Val.ToString()); taskCompletedReq = val; taskTypeSnd = int.Parse(this.dicCommuDataDB1[4].Val.ToString()); } if (!ReadDB2()) { AddLog(devName + " 读取设备状态数据失败", EnumLogType.错误); return(false); } //上拍数据初始化成和当前值相同 if (dicCommuDataDB2.Count() > 0) { foreach (KeyValuePair <int, DevCommDatatype> keyVal in dicCommuDataDB2) { if (keyVal.Value == null) { continue; } DevCommDatatype commObj = keyVal.Value; dicDataDB2Last[commObj.CommuID] = commObj.Val; } } if (!DevStatusRestore(ref reStr)) { string errStr = ""; int errCode = 2105; if (!ECAMWCS.GetErrorContent(errCode, ref errStr)) { AddLog(devName + " 恢复状态出现错误", EnumLogType.错误); } else { errStr = devName + reStr; OnErrorHappen(errCode, errStr, false); } return(false); } return(true); }
/// <summary> /// 处理业务 /// </summary> /// <returns></returns> public virtual bool ExeBusiness() { if (currentTask == null || currentTask.TaskStatus == EnumTaskStatus.待执行.ToString()) { return(true); } //判断是否有任务撤销 if (currentTask != null && currentTaskPhase < 5) { int taskFinish = int.Parse(dicCommuDataDB2[5].Val.ToString()); int taskRes = int.Parse(dicCommuDataDB1[3].Val.ToString()); if (taskFinish == 3 && taskRes != 3) { //任务清理 ClearDevCmd(); currentTask.TaskStatus = EnumTaskStatus.任务撤销.ToString(); ctlTaskBll.Update(currentTask); currentTaskDescribe = "任务撤销,等待'撤销信号'复位"; taskCompletedReq = 3; if (!DevCmdCommit()) { AddLog(devName + "发送命令失败", EnumLogType.错误); return(false); } // AddLog(devName + ",Test:任务撤销,发送‘任务完成应答信息:" + dicCommuDataDB1[3].Val.ToString(), EnumLogType.调试信息); return(true); } if (taskFinish == 1 && taskRes == 3) { taskCompletedReq = 1; if (!DevCmdCommit()) { AddLog(devName + "发送命令失败", EnumLogType.错误); return(false); } //AddLog(devName + ",Test:任务撤销应答复位,发送‘任务完成应答信息:" + dicCommuDataDB1[3].Val.ToString(), EnumLogType.调试信息); currentTaskPhase = 0; currentTask = null; currentTaskDescribe = "当前无任务"; return(true); } } //if (currentTask != null && (taskElapseCounter > taskTimeOutCounts)) taskElapseTimespan = System.DateTime.Now - currentTaskStartTime; if (taskElapseTimespan.TotalMinutes > taskTimeOutMinutes) { currentTaskStartTime = System.DateTime.Now; if (currentTask.TaskStatus == EnumTaskStatus.执行中.ToString()) { currentTask.TaskStatus = EnumTaskStatus.超时.ToString(); ctlTaskBll.Update(currentTask); } //任务超时,错误码2202 int errCode = 2202; string reStr = ""; if (!ECAMWCS.GetErrorContent(errCode, ref reStr)) { reStr = devName + "控制任务ID:" + currentTask.ControlTaskID + "任务超时"; AddLog(reStr, EnumLogType.错误); } else { reStr = (devName + "控制任务ID:" + currentTask.ControlTaskID + " 执行任务超时"); OnErrorHappen(errCode, reStr, false); } } return(true); }