예제 #1
0
        //#region Constructors
        //public MernokRFID()
        //{
        //}

        //#endregion


        #region Functions

        public static bool IsOpen()
        {
            List <string> ports = PortFromVIDPID.ComPortNames(VID, PID);

            if (ports.Count < 1)
            {
                return(false);
            }
            else
            {
                if (porterror == false)
                {
                    return(SP.IsOpen);
                }
                else
                {
                    porterror = false;
                    return(false);
                }
            }
        }
예제 #2
0
        public static bool OpenRFID(Mode RFID_Mode)
        {
            List <string> ports = PortFromVIDPID.ComPortNames(VID, PID);

            if (ports.Count < 1)
            {
                return(false);               // no ports with the details specified, so fail
            }
            else
            {
                #region previous code
                //    foreach (string s in ports)
                //    {
                //        try
                //        {
                //            if (SP.IsOpen) SP.Close();

                //            SP.PortName = s;
                //            if (SP.IsOpen != true)
                //            {
                //                SP.Open();
                //                Thread.Sleep(10);
                //                if (SP.IsOpen)
                //                {
                //                    if (MernokRFID_interface.Mifair_ICode_Mode(RFID_Mode))
                //                    {
                //                        byte[] retdata;
                //                        byte[] command = new byte[] { 80, 0, 0 };                       //Send polling interval to 0: P', 0, 0                                                     // Tag answer OK
                //                        if (MernokRFID.SendRec(out retdata, command))
                //                            return true;
                //                    }

                //                    SP.Close();
                //                    return false;
                //                }
                //                else
                //                {
                //                    return false;
                //                }
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            //                       MessageBox.Show("Failed To Open Comms with RWD module");
                //            Console.WriteLine(ex.HelpLink);
                //            //                        return false;
                //        }
                //    }
                //}
                #endregion

                for (int i = ports.Count; i > 0; i--)
                {
                    try
                    {
                        if (SP.IsOpen)
                        {
                            SP.Close();
                        }

                        SP.PortName = ports[i - 1];
                        if (SP.IsOpen != true)
                        {
                            SP.Open();
                            Thread.Sleep(10);
                            if (SP.IsOpen)
                            {
                                if (MernokRFID_interface.Mifair_ICode_Mode(RFID_Mode))
                                {
                                    byte[] retdata;
                                    byte[] command = new byte[] { 80, 0, 0 };                       //Send polling interval to 0: P', 0, 0                                                     // Tag answer OK
                                    if (MernokRFID.SendRec(out retdata, command))
                                    {
                                        return(true);
                                    }
                                }

                                SP.Close();
                                return(false);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //                       MessageBox.Show("Failed To Open Comms with RWD module");
                        Console.WriteLine(ex.HelpLink);
                        //                        return false;
                    }
                }
            }

            return(false);
        }