Exemplo n.º 1
0
 public void SetRdrPolling(string ip, bool b)
 {
     //lock(myLock)
     {
         readerStatStruct rdrStatObj = new readerStatStruct(0);
         if (GetRdrFromList(ip, ref rdrStatObj))
         {
             readerStatStruct rdrStatObj1 = new readerStatStruct(0);
             rdrStatObj1.rdrID  = rdrStatObj.rdrID;
             rdrStatObj1.hostID = rdrStatObj.hostID;
             rdrStatObj1.SetCounter(rdrStatObj.GetCounter());
             rdrStatObj1.SetPollReader(false);
             rdrStatObj1.online = rdrStatObj.online;
             rdrStatObj1.SetProcessing(rdrStatObj.GetProcessing());
             rdrStatObj1.SetStatus(rdrStatObj.GetStatus());
             rdrStatObj1.SetStartTimeSec(rdrStatObj.GetStartTimeSec());
             rdrStatObj1.SetIP(rdrStatObj.GetIP());
             rdrStatusList.Remove(rdrStatObj);
             rdrStatusList.Add(rdrStatObj1);
         }
     }            //lock
 }
Exemplo n.º 2
0
        void ErrorEventNotify(AW_API_NET.rfReaderEvent_t readerEvent)
        {
            //lock(myLock)
            {
                if (readerEvent.eventType == AW_API_NET.APIConsts.RF_READER_ENABLE)
                {
                    //if NOT_RESPONDING .....
                    //if RESDER BUSY .....
                    if (readerEvent.errorStatus == AW_API_NET.APIConsts.RF_E_NO_RESPONSE)
                    {
                        //find the status of that rdr from reader array
                        //readerStatStruct readerObj = new readerStatStruct(readerEvent.reader);
                        if (ProcessRdrError(readerEvent, AW_API_NET.APIConsts.RF_E_NO_RESPONSE))
                        {
                            //int ret = communication.EnableReader(rdrStat.rdrID, rdrStat.hostID);
                            //if (ret < 0) //some error took place will not go to the error notification process it here
                            //{

                            Console.WriteLine("NetRdrConn   OnErrorNotify Counter = MAX for NO_RESPONSE Notification. Rdr=" + Convert.ToString(readerEvent.reader));

                            // 1 - send offline event to the app
                            // 2 - closesocket(ip)
                            // 3 - send scanNetwork(ip)

                            //if (ReaderOfflineEventHandler != null)
                            //ReaderOfflineEventHandler(readerEvent);

                            string ip;
                            if ((ip = GetStringIP(readerEvent.ip)) == "")
                            {
                                Console.WriteLine("NetRdrConn  Invalid ip address");
                                return;
                            }

                            readerStatStruct readerObj = new readerStatStruct(readerEvent.reader);
                            if (GetRdrFromList(ip, ref readerObj))
                            {
                                DateTime timeNow;
                                int      tSecNow;
                                int      sTime;
                                if (readerObj.GetProcessing() || !readerObj.online)
                                {
                                    timeNow = DateTime.Now;
                                    tSecNow = timeNow.Hour * 3600 + timeNow.Minute * 60 + timeNow.Second;
                                    Console.WriteLine("NetRdrConn  OnErrorNotify startTime= " + DateTime.Now.ToString());
                                    sTime = readerObj.GetStartTimeSec() + 3;

                                    /*if (sTime < tSecNow)
                                     * {
                                     *      Console.WriteLine("NetRdrConn  OnErrorNotify Time NOT EXPIRED. startTime=" + Convert.ToString(sTime) + " TimeNow=" + Convert.ToString(tSecNow));
                                     *      return;
                                     * }
                                     * else*/
                                    {
                                        //Console.WriteLine("NetRdrConn  OnErrorNotify Time EXPIRED. startTime=" + Convert.ToString(sTime) + " TimeNow=" + Convert.ToString(tSecNow));

                                        readerStatStruct newRdrObj = new readerStatStruct(readerEvent.reader);
                                        newRdrObj.SetIP(ip);
                                        newRdrObj.hostID = readerObj.hostID;
                                        newRdrObj.online = false;
                                        newRdrObj.SetStatus(0);
                                        newRdrObj.SetCounter(0);
                                        newRdrObj.SetProcessing(true);
                                        newRdrObj.SetStartTimeSec(DateTime.Now);
                                        rdrStatusList.Remove(readerObj);
                                        rdrStatusList.Add(newRdrObj);
                                    }
                                }                                 //if (readerObj.GetProcessing() || !readerObj.online)

                                /*else
                                 * {
                                 *      Console.WriteLine("NetRdrConn  OnErrorNotify - First Time reader #" + Convert.ToString(readerEvent.reader) + "offline");
                                 *      readerStatStruct newRdrObj = new readerStatStruct(readerEvent.reader);
                                 *      newRdrObj.SetIP(ip);
                                 *      newRdrObj.hostID = readerEvent.host;
                                 *      newRdrObj.online = false;
                                 *      newRdrObj.SetStatus(0);
                                 *      newRdrObj.SetCounter(0);
                                 *      newRdrObj.SetProcessing(true);
                                 *      newRdrObj.SetStartTimeSec(DateTime.Now);
                                 *      rdrStatusList.Remove(readerObj);
                                 *      rdrStatusList.Add(newRdrObj);
                                 * }*/
                            }                            //if (GetRdrFromList(ip
                            else
                            {
                                Console.WriteLine("NetRdrConn  Could not find reader in rdrStatusList");
                            }

                            Console.WriteLine("NetRdrConn  OnPollRdr Send OFFLINE Event for rdr=" + Convert.ToString(readerEvent.reader));
                            if (ReaderOfflineEventHandler != null)
                            {
                                ReaderOfflineEventHandler(readerEvent);
                            }

                            Console.WriteLine("NetRdrConn  SocketDisconnection() called for ip = " + ip);
                            int ret = communication.SocketDisconnection(readerEvent.ip);

                            Thread.Sleep(300);

                            Console.WriteLine("NetRdrConn  ScanNetwork() called for ip = " + ip);
                            ret = communication.ScanNetwork(readerEvent.ip);
                        }                        //ProcessRdrError
                                                 //else
                                                 //{
                        //if (ReaderOfflineEventHandler != null)
                        //ReaderOfflineEventHandler(readerEvent);
                        //}
                    }            //NO_RESPONSE
                }                //ENABLE_READER
            }

            //need to set an event in NetRdrReconnClass to process reconn to socket
            //check to see if this event already setup for the module
            //call the event with ip included
        }
Exemplo n.º 3
0
        private void OnPollEnableReaderTimerEvent(object source, ElapsedEventArgs e)
        {
            //lock(myLock)
            {
                //need to have instances of communicationClass in order to call EnableReader
                //otherwise need to have the function as static to work
                //CommunicationClass commObj = new CommunicationClass(0);

                //if there is no reader in the list do not process
                //the list gets populated when a net rdr gets powered up

                if (rdrStatusList.Count == 0)
                {
                    return;
                }

                if (!trunOnRdrPolling)
                {
                    pollReaderTimer.Enabled = false;
                }
                else if (trunOnRdrPolling)
                {
                    if (rdrIndexPoll >= rdrStatusList.Count)
                    {
                        rdrIndexPoll = 0;
                    }

                    readerStatStruct rdrStat = new readerStatStruct(0);                     //create an readerStatStruct object with temp rdr id
                    rdrStat = (readerStatStruct)rdrStatusList[rdrIndexPoll];

                    Byte[] ip  = new Byte[20];
                    char[] cIP = new char[20];

                    string ipStr = rdrStat.GetIP();
                    if (ipStr.Length == 0)
                    {
                        Console.WriteLine("NetRdrConn  ERROR bad ip = ");
                        rdrIndexPoll += 1;
                        return;
                    }
                    cIP = ipStr.ToCharArray(0, ipStr.Length);
                    for (int i = 0; i < ipStr.Length; i++)
                    {
                        ip[i] = Convert.ToByte(cIP[i]);
                    }


                    AW_API_NET.rfReaderEvent_t readerEvent = new rfReaderEvent_t();
                    readerEvent.ip = new Byte[20];
                    for (int i = 0; i < 20; i++)
                    {
                        readerEvent.ip[i] = 0x00;
                    }
                    readerEvent.reader     = rdrStat.rdrID;
                    readerEvent.host       = rdrStat.hostID;
                    readerEvent.fGenerator = 0;
                    readerEvent.eventType  = AW_API_NET.APIConsts.RF_READER_ENABLE;
                    int n = 0;
                    for (n = 0; n < readerEvent.ip.Length; n++)
                    {
                        readerEvent.ip[n] = ip[n];
                    }

                    if ((rdrStat.rdrID > 0) && rdrStat.GetPollReader())
                    {
                        //if return value is -185 (rdr not found) should remove rdr from rdrStatusList
                        int ret = communication.EnableReader(rdrStat.rdrID, rdrStat.hostID);
                        if (ret < 0)                         //some error took place will not go to the error notification process it here
                        {
                            Console.WriteLine("NetRdrConn - OnPollEnableReader - ERROR in Enable Reader Call err = " + Convert.ToString(ret) + "  rdr = " + Convert.ToString(rdrStat.rdrID));


                            // 1 - send offline event to the app
                            // 2 - closesocket(ip)
                            // 3 - send scanNetwork(ip)

                            //if (ReaderOfflineEventHandler != null)
                            //ReaderOfflineEventHandler(readerEvent);

                            //check to see if the counter has reached its MAX
                            if (ProcessRdrError(readerEvent, AW_API_NET.APIConsts.RF_E_NO_RESPONSE))
                            {
                                Console.WriteLine("NetRdrConn - OnPollEnableReader - ProcessRdrError()");
                                readerStatStruct readerObj = new readerStatStruct(readerEvent.reader);
                                if (GetRdrFromList(ipStr, ref readerObj))
                                {
                                    DateTime timeNow;
                                    int      tSecNow;
                                    int      sTime;
                                    if (readerObj.GetProcessing() || !readerObj.online)
                                    {
                                        timeNow = DateTime.Now;
                                        tSecNow = timeNow.Hour * 3600 + timeNow.Minute * 60 + timeNow.Second;
                                        Console.WriteLine("NetRdrConn  OnErrorNotify startTime=" + DateTime.Now.ToString());
                                        sTime = readerObj.GetStartTimeSec() + 3;

                                        /*if (sTime < tSecNow)
                                         * {
                                         *      rdrIndexPoll += 1;
                                         *      Console.WriteLine("NetRdrConn  OnPollEnable Time NOT EXPIRED. startTime=" + Convert.ToString(sTime) + " TimeNow=" + Convert.ToString(tSecNow));
                                         *      return;
                                         * }
                                         * else  //time not expired*/
                                        {
                                            //Console.WriteLine("NetRdrConn  OnPollEnable Time EXPIRED. Send close and scan startTime=" + Convert.ToString(sTime) + " TimeNow=" + Convert.ToString(tSecNow));
                                            readerStatStruct newRdrObj = new readerStatStruct(readerEvent.reader);
                                            newRdrObj.SetIP(ipStr);
                                            newRdrObj.hostID = readerObj.hostID;
                                            newRdrObj.online = false;
                                            newRdrObj.SetStatus(readerObj.GetStatus());
                                            newRdrObj.SetCounter(0);
                                            newRdrObj.SetProcessing(true);
                                            newRdrObj.SetStartTimeSec(DateTime.Now);                                             //new time
                                            rdrStatusList.Remove(readerObj);
                                            rdrStatusList.Add(newRdrObj);
                                        }
                                    }                                    //reader offline

                                    /*else  //this the first time reader is offline
                                     * {
                                     *      Console.WriteLine("NetRdrConn  OnPollEnableReader - First Time reader #" + Convert.ToString(readerEvent.reader) + " Offline. set rdrObj");
                                     *      readerStatStruct newRdrObj = new readerStatStruct(readerEvent.reader);
                                     *      newRdrObj.SetIP(ipStr);
                                     *      newRdrObj.hostID = readerObj.hostID;
                                     *      newRdrObj.online = false;
                                     *      newRdrObj.SetStatus(readerObj.GetStatus());
                                     *      newRdrObj.SetCounter(readerObj.GetCounter());
                                     *      newRdrObj.SetProcessing(true);
                                     *      newRdrObj.SetStartTimeSec(DateTime.Now);
                                     *      rdrStatusList.Remove(readerObj);
                                     *      rdrStatusList.Add(newRdrObj);
                                     *
                                     * }*/
                                }
                                else
                                {
                                    Console.WriteLine("NetRdrConn  Could not find reader in rdrStatusList");
                                }                                //GetRdrFromList

                                Console.WriteLine("NetRdrConn  OnPollRdr Send OFFLINE Event for rdr=" + Convert.ToString(readerEvent.reader));
                                if (ReaderOfflineEventHandler != null)
                                {
                                    ReaderOfflineEventHandler(readerEvent);
                                }

                                if (UpdateRdrOfflineListEventHandler != null)
                                {
                                    UpdateRdrOfflineListEventHandler(readerEvent.reader);
                                }


                                //Console.WriteLine("NetRdrConn   Counter = MAX sending closesock and scan for (ret < 0)");
                                Console.WriteLine("NetRdrConn  SocketDisconnection() called for ip = " + ipStr);
                                ret = communication.SocketDisconnection(ip);

                                Thread.Sleep(300);

                                Console.WriteLine("NetRdrConn  ScanNetwork() called for ip = " + ipStr);
                                ret = communication.ScanNetwork(ip);
                            }                            //ProcessRdrError
                                                         //else
                                                         //{
                            //if (ReaderOfflineEventHandler != null)
                            //ReaderOfflineEventHandler(readerEvent);
                            //}
                        }                         // ret < 0

                        rdrIndexPoll += 1;
                    }                     //rdrStat.GetPollReader())
                    else
                    {
                        rdrIndexPoll += 1;
                    }
                }
            }            //lock
        }