Пример #1
0
        /// <summary>
        /// the message is about register for station client
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="pos"></param>
        public void AH_Register(Message msg, string pos)
        {
            if (pos == "r")
            {
                stationList[int.Parse(msg.stationId) - 1].stationNo      = int.Parse(msg.Info);
                stationList[int.Parse(msg.stationId) - 1].isAvaliable    = true;
                stationList[int.Parse(msg.stationId) - 1].errorInfo      = "";   // after
                stationList[int.Parse(msg.stationId) - 1].aTimer.Enabled = true; //timer可用
                //UpdateStation(msg.stationId, ClientStatusType.Idle);
                LogerHelper2.ToAutoTestLogFile(DateTime.Now.ToString() + ": Tester " + msg.stationId + " register to server");
            }
            else if (pos == "g")
            {
                gufList[int.Parse(msg.stationId) - 1].stationNo = int.Parse(msg.Info);

                if (gufList[int.Parse(msg.stationId) - 1].stationId == -1)
                {
                    // first time to register GUF
                    gufList[int.Parse(msg.stationId) - 1].gufStatus = 0; //0-OK
                    gufList[int.Parse(msg.stationId) - 1].stationId = int.Parse(msg.stationId);
                    UpdateStation(msg.stationId, ClientStatusType.Idle);
                }
                else
                {
                    //recover the GUF
                    int stid = int.Parse(msg.stationId);
                    //   if (gufList[stid - 1].gufStatus == 1 && (stationList[stid - 1].errorInfo.ToLower().Contains("heartbeat") && stationList[stid - 1].errorInfo.ToLower().Contains("guf"))) // exception
                    {
                        gufList[int.Parse(msg.stationId) - 1].gufStatus = 0; //0-OK
                        stationList[stid - 1].errorInfo = "";
                        ClientGUFStatus.UpdateStationsData(stid, 3, ClientStatusType.Pass);
                        ClientGUFStatus.UpdateStationsData(stid, 4, ClientStatusType.Unknown);
                        if (stationList[stid - 1].clientStatusType == ClientStatusType.Idle && stationList[stid - 1].isAvaliable == true)
                        {
                            QueryMessageListAndRunFirstMessage("DUTID");
                        }
                    }
                }
                LogerHelper2.ToAutoTestLogFile(DateTime.Now.ToString() + ": GUF " + msg.stationId + " register to server");
            }
            else if (pos == "x")
            {
                gufList[int.Parse(msg.stationId) - 1].stationNo          = int.Parse(msg.Info);
                gufList[int.Parse(msg.stationId) - 1].gufStatus          = 0;  //0-OK
                gufList[int.Parse(msg.stationId) - 1].stationId          = int.Parse(msg.stationId);
                stationList[int.Parse(msg.stationId) - 1].errorInfo      = ""; // after
                stationList[int.Parse(msg.stationId) - 1].stationNo      = int.Parse(msg.Info);
                stationList[int.Parse(msg.stationId) - 1].isAvaliable    = true;
                stationList[int.Parse(msg.stationId) - 1].aTimer.Enabled = true; //timer可用
                UpdateStation(msg.stationId, ClientStatusType.Idle);
                LogerHelper2.ToAutoTestLogFile(DateTime.Now.ToString() + ": Tester & GUF " + msg.stationId + " register to server");
            }
            //server.SendMsg(new Message(msg.stationId, msg.MsgId, MsgType.Ack, "ack ok"), stationList[int.Parse(msg.stationId) - 1].ahaddress);
        }
Пример #2
0
        /// <summary>
        /// the event of server receive message from PLC, different messagetype do different action
        /// </summary>
        /// <param name="sender">plc ip&port</param>
        /// <param name="msg">plc message</param>
        public void plcserver_MessageReceived(object sender, MainPLCMessage msg)
        {
            if (msg.InvalidMessage == true)
            {
                LogerHelper2.ToLog("error format PLC commond" + msg.Info, 3);
                return;
            }
            string msgTemp = null;

            try
            {
                msgTemp = string.Format("From PLC: MessageHead: {0}\t Info:{1}", msg.MsgHead.ToString(), msg.Info.ToString());
            }
            catch (Exception e)
            {
                LogerHelper2.ToLog(e.Message, 2);
            }

            //LogerHelper2.ToLog(msg.MsgType + " " + msg.MsgHead + " " + msg.StationId + " " + msg.Info, 0);

            if (msg.MsgType != PLCMsgType.Heartbead)
            {
                LogerHelper2.ToLog(msgTemp, 0);
            }
            else
            {
                LogerHelper2.ToLog(msgTemp, 4);
            }
            int    freeStationID;
            string MessageHead = msg.MsgHead;
            string MessageInfo = msg.Info;

            //LogerHelper2.ToLog(msg.MsgType + " " , 0);
            switch (msg.MsgType)
            {
            case PLCMsgType.ReportMsg:
                if (MessageHead == MainPLCMessage.DUTIdToServer)
                {
                    plcserver.NewSNFeedback();      //feedback plc F020

                    //check the dutid, if it same as the current test duts? ignore it if yes
                    if (!check_DUTID_Valid(msg.Info))
                    {
                        LogerHelper2.ToLog("Found new Dut Id <" + msg.Info + ">  is same as current testing Duts' Id, will ignore this new Dut Id ", 2);
                        LogerHelper2.ToAutoTestLogFile(DateTime.Now.ToString() + ": Dut ID: " + msg.Info + " duplicated with the current testing Duts' Id, will ignore it.");
                        return;
                    }

                    freeStationID = FetchFreeStation();
                    int loop = 0;
                    while (loop < stationList.Length)
                    {
                        newDutNm = msg.Info;
                        //newSerailNumber.Enqueue(msg.Info);  // when coming a new sn, add to qu
                        if (freeStationID >= 1 && freeStationID <= 6)
                        {
                            stationList[freeStationID - 1].clientStatusType = ClientStatusType.Wait;
                            //if (server.SendMsg(new Message(freeStationID.ToString(), 1, MsgType.QueryClientStatus, ""), stationList[freeStationID - 1].ahaddress))
                            //{
                            //    break;
                            //}

                            freeStationID = FetchFreeStation(freeStationID);
                        }
                        else
                        {
                            //idMessageQueue.sendMsg("DUTID", msg.Info, System.Messaging.MessagePriority.Normal);  // if there is no idle station, send the id message to messagequeue
                            //LogerHelper2.ToLog("NO freestation, add newdutid <" + msg.Info + ">  to queue. idqueue number is: " + idMessageQueue.messageNum, 2);
                            break;
                        }

                        loop++;
                    }
                    if (loop >= stationList.Length)
                    {
                        //idMessageQueue.sendMsg("DUTID", msg.Info, System.Messaging.MessagePriority.Normal);  // if there is no idle station, send the id message to messagequeue
                        //LogerHelper2.ToLog("NO freestation, add newdutid <" + msg.Info + ">  to queue. idqueue number is: " + idMessageQueue.messageNum, 2);
                    }
                }
                break;

            case PLCMsgType.Feedback:
                plcserver.stopPlcCommandTimer();
                System.Threading.Thread.Sleep(1000);     //sleep wait PLC ready

                if (MessageHead == MainPLCMessage.MoveDUTToStationACK)
                {
                    //PlCisbusy = false;
                    RobotPLCStatus.UpdateRobotPLCStatus("Idle");
                    server.SendMsg(new Message(msg.StationId.ToString(), 1, MsgType.NewDut, stationList[msg.StationId - 1].onTestingSerialNumber), stationList[msg.StationId - 1].ahaddress);    //dutid
                    UpdateStation(msg.StationId.ToString(), ClientStatusType.Run);
                    //PlcMessageQueue.DeleteMsg(msg.StationId.ToString());
                    PlCisbusy = false;
                }
                else if (MessageHead == MainPLCMessage.MoveDUTFromStationACK)
                {
                    isOutBufferFree = false;

                    // here add if to check whether the tester is set to offline?
                    if ((stationList[msg.StationId - 1].isForcedOffLine == true) || (stationList[msg.StationId - 1].DUTTestConsecutiveFailedTimes >= DUTReTest.alarmWhenDUTTestFailTimes))
                    {
                        stationList[msg.StationId - 1].isAvaliable     = false;
                        stationList[msg.StationId - 1].isForcedOffLine = false;
                        stationList[msg.StationId - 1].errorInfo       = "This station was forced offline by admin or DUT test consecutive failures";
                        UpdateStation((msg.StationId).ToString(), ClientStatusType.Error);

                        ClientGUFStatus.UpdateStationsData(msg.StationId, 2, ClientStatusType.Unknown);
                        ClientGUFStatus.UpdateStationsData(msg.StationId, 3, ClientStatusType.Unknown);
                    }
                    else
                    {
                        //PlCisbusy = false;
                        RobotPLCStatus.UpdateRobotPLCStatus("Idle");
                        stationList[msg.StationId - 1].isAvaliable           = true;
                        stationList[msg.StationId - 1].currentDUTtestedCount = 0;
                        stationList[msg.StationId - 1].onTestingSerialNumber = "";
                        UpdateStation((msg.StationId).ToString(), ClientStatusType.Idle);
                    }

                    PlCisbusy = false;
                }
                else if (MessageHead == MainPLCMessage.queryPLCStateACK)
                {
                    PlCisbusy = msg.PLCIsBusy;
                }

                if (PlCisbusy == false)
                {
                    QueryMessageListAndRunFirstMessage("DUTSTATUS");
                }
                break;

            case PLCMsgType.Heartbead:
                // RobotPLCStatus.UpdateRobotPLCStatus("Connected");
                plcserver.CheckHeartbeat();
                break;

            case PLCMsgType.Ack:
                plcserver.plcResendCommandTimer.Stop();
                plcserver.lastAction = string.Empty;
                break;

            default:
                break;
            }
        }