Example #1
0
        void ReaderIsOnlineEventNotify(AW_API_NET.rfTagEvent_t tagEvent)
        {
            //lock(myLock)
            {
                //if polling rdr is switched on
                readerStatStruct readerObj = new readerStatStruct(tagEvent.reader);
                if (GetRdrFromList(tagEvent.reader, ref readerObj))
                {
                    if (readerObj.GetStatus() == 0)
                    {
                        Byte[] ip  = new Byte[20];
                        char[] cIP = new char[20];

                        string ipStr = readerObj.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     = readerObj.rdrID;
                        readerEvent.host       = readerObj.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 (ReaderOnlineEventHandler != null)
                        {
                            ReaderOnlineEventHandler(readerEvent);
                        }

                        //if ip exits in the rdrStatusList remove it and replace it otherwise add it.
                        readerStatStruct rdrStat = new readerStatStruct(tagEvent.reader);
                        rdrStat.hostID = tagEvent.host;
                        //need to fix api to send valid ip with enable rdr
                        //rdrStat.SetIP(GetStringIP(readerEvent.ip));
                        rdrStat.SetIP(readerObj.GetIP());
                        rdrStat.SetStatus(1);                         //online
                        rdrStat.SetCounter(0);
                        rdrStat.online = true;
                        rdrStat.SetProcessing(false);
                        rdrStat.SetStartTimeSec(DateTime.Now);

                        rdrStatusList.Remove(readerObj);

                        rdrStatusList.Add(rdrStat);                          //polling rdr list

                        if (GetAllRdrsStat())
                        {
                            if (AllReadersOnlineEventHandler != null)
                            {
                                AllReadersOnlineEventHandler(true);
                            }
                        }
                        else
                        {
                            if (AllReadersOnlineEventHandler != null)
                            {
                                AllReadersOnlineEventHandler(false);
                            }
                        }
                    }
                }
            }            //lock
        }
Example #2
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
        }