public void DoWork(Transaction orgTxn, bool WaitForData = false) { Transaction Txn = null; Txn = orgTxn; if (Txn.CommandEncodeStr.Equals("GetMappingDummy")) { string mappingData = ""; if (Txn.NodeName.Equals("LOADPORT01")) { //mappingData = "1111111111111111111111111"; mappingData = SystemConfig.Get().FakeDataP1; } else if (Txn.NodeName.Equals("LOADPORT02")) { mappingData = SystemConfig.Get().FakeDataP2; } else if (Txn.NodeName.Equals("LOADPORT03")) { mappingData = SystemConfig.Get().FakeDataP3; } else if (Txn.NodeName.Equals("LOADPORT04")) { mappingData = SystemConfig.Get().FakeDataP4; } CommandReturnMessage cm = new CommandReturnMessage(); //cm.CommandType = Transaction.Command.LoadPortType.GetMapping; cm.Value = mappingData; //Txn.Method= Transaction.Command.LoadPortType.GetMapping; _ReportTarget.On_Command_Excuted(NodeManagement.Get(Txn.NodeName), Txn, cm); } //conn.WaitForData(WaitForData); // lock (TransactionList) List <CommandReturnMessage> msgList = _Decoder.GetMessage(Txn.CommandEncodeStr); if (!Txn.NodeType.Equals("OCR")) { if (msgList.Count != 0) { Txn.Type = msgList[0].Command; //Txn.CommandType = msgList[0].CommandType; } } else { Txn.Type = ""; //Txn.CommandType = ""; } string key = ""; if (Vendor.ToUpper().Equals("KAWASAKI")) { key = Txn.Seq; } if (DeviceType.ToUpper().Equals("SMARTTAG")) { key = "00"; } else if (Vendor.ToUpper().Equals("HST") || Vendor.ToUpper().Equals("COGNEX")) { key = "1" + Txn.Type; } else if (Vendor.ToUpper().Equals("SANWA") || Vendor.ToUpper().Equals("ATEL_NEW")) { key = Txn.AdrNo + Txn.Type; //支援同時多發命令 for (int seq = 0; seq <= 99; seq++) { string tmpKey = key + seq.ToString("00"); if (!TransactionList.ContainsKey(tmpKey)) { key = tmpKey; break; } if (seq == 99) { logger.Error("seq is run out!"); } } } else { if (Vendor.ToUpper().Equals("SANWA_MC")) { if (orgTxn.CommandEncodeStr.Contains("MCR:")) { Txn.CommandType = "CMD"; } if (Txn.Method == Transaction.Command.LoadPortType.Reset) { key = "0"; } else { key = Txn.AdrNo; } //} //else //{ // key = "0" + msgList[0].Command; //} } else { key = Txn.AdrNo + Txn.Type; } } if (TransactionList.TryAdd(key, Txn) || Txn.Method.Equals("Stop")) { Txn.SetTimeOutReport(this); Txn.SetTimeOutMonitor(true); //if (Vendor.ToUpper().Equals("ACDT")) //{ // byte[] byteAry = Encoding.UTF8.GetBytes(Txn.CommandEncodeStr); // logger.Debug(DeviceName + " Send:" + BitConverter.ToString(byteAry) + " Wafer:" + waferids); //} //else //{ if (Txn.CommandType.Equals("")) { Txn.CommandType = _Decoder.GetMessage(Txn.CommandEncodeStr)[0].CommandType; } //if (Txn.CommandType.Equals("GET") || Txn.CommandType.IndexOf("FS") != -1) //{ //} if (Txn.Method.Equals(Transaction.Command.LoadPortType.Reset)) { Txn.SetTimeOut(15000); } else { Txn.SetTimeOut(Txn.AckTimeOut); } try { //logger.Info(DeviceName + " Send:" + Txn.CommandEncodeStr.Replace("\r", "")); //if (!this.Vendor.ToUpper().Equals("MITSUBISHI_PLC")) //{ // _ReportTarget.On_Message_Log("CMD", DeviceName + " Send:" + Txn.CommandEncodeStr.Replace("\r", "")); //} //if (this.Vendor.Equals("SMARTTAG8200") || this.Vendor.Equals("SMARTTAG8400")) //{ // //if (Txn.Method == Transaction.Command.SmartTagType.GetLCDData) // //{ // // conn.WaitForData(true); // //} // ThreadPool.QueueUserWorkItem(new WaitCallback(conn.SendHexData), Txn.CommandEncodeStr); //} //else //{ // ThreadPool.QueueUserWorkItem(new WaitCallback(conn.Send), Txn.CommandEncodeStr); //} if (Txn.NodeName.ToUpper().Equals("SMIF1")) { ch1Send = Txn.CommandEncodeStr; } else if (Txn.NodeName.ToUpper().Equals("SMIF2")) { ch2Send = Txn.CommandEncodeStr; } } catch (Exception eex) { logger.Error(eex.StackTrace); _ReportTarget.On_Message_Log("CMD", DeviceName + " Err:" + eex.StackTrace); Txn.SetTimeOutMonitor(false); Transaction tmp; TransactionList.TryRemove(key, out tmp); CommandReturnMessage rm = new CommandReturnMessage(); rm.Value = "ConnectionError"; _ReportTarget.On_Command_Error(NodeManagement.Get(Txn.NodeName), Txn, rm); } } else { Transaction workingTxn; TransactionList.TryRemove(key, out workingTxn); logger.Debug(DeviceName + "(DoWork " + IPAdress + ":" + Port.ToString() + ":" + Txn.CommandEncodeStr + ") Same type command " + workingTxn.CommandEncodeStr + " is already excuting."); _ReportTarget.On_Message_Log("CMD", DeviceName + "(DoWork " + IPAdress + ":" + Port.ToString() + ":" + Txn.CommandEncodeStr + ") Same type command " + workingTxn.CommandEncodeStr + " is already excuting."); Txn.SetTimeOutMonitor(false); CommandReturnMessage rm = new CommandReturnMessage(); rm.Value = "AlreadyExcuting"; _ReportTarget.On_Command_Error(NodeManagement.Get(Txn.NodeName), Txn, rm); } }