Esempio n. 1
0
        public void initReaderList()
        {
            //  List<RFIDReader> rfidreaderlist = new List<RFIDReader>();
              //  //连接数据库,获取所有reader的基本信息
              ////  RFIDReaderList createrredaerlist = new RFIDReaderList();
              //  XMLReaderConvertor xmlreaderlist = new XMLReaderConvertor();
              //  rfidreaderlist = xmlreaderlist.getRFIDReaderList();

            //rfidreaderlist的个数
            int count = rfidreaderlist.Count;
            if (count <= 0 && rfidreaderlist == null)
            {
                throw new Exception("从数据库中获取数据失败");
            }
            else
            {
                //根据不同类型的Reader,ReaderFactory实例化不通过的Reader
                ReaderFactory readerFact = new ReaderFactory();
                for (int i = 0; i < count; i++)
                {
                    //实例化reader
                    RFIDInterface reader = readerFact.MakeReader(rfidreaderlist[i].RFidreaderType);
                    //打开reader
                    //reader.ip = rfidreaderlist[i].RFidreaderIP;  //2014.2.17:设置IP
                    //System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
                    //stopwatch.Start();
                    reader.Open(rfidreaderlist[i].RFidreaderIP);
                    //stopwatch.Stop();

                    reconnectThread.AlertState.Add(rfidreaderlist[i].RFidreaderIP,false);  //2014.2.24,对话框状态

                    this.readerListBox.Items.Add(Convert.ToString(rfidreaderlist[i].RFidreaderID+" " + rfidreaderlist[i].RFidreaderIP +" "+ rfidreaderlist[i].RFidreaderType));

                    this.Xtreaderlist.Add(new XtiveReaderInitClass(reader, false));

                    //TimeSpan timespan = stopwatch.Elapsed;
                    //System.Console.WriteLine(rfidreaderlist[i].RFidreaderIP+" "+timespan.TotalMilliseconds);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 打开RFID读写器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenReader_Click(object sender, EventArgs e)
        {
            openState = (openState ^ true);
            this.btnOpenReader.Text = openState ? "Close Reader" : "Open Reader";
            if (openState)
            {
                try
                {
                    int count = rfidWriterList.Count;
                    if (count <= 0 && rfidWriterList == null)
                    {
                        throw new Exception("从数据库中获取数据失败");
                    }
                    else
                    {
                        //根据不同类型的Reader,ReaderFactory实例化不通过的Reader
                        ReaderFactory readerFact = new ReaderFactory();

                        reader = readerFact.MakeReader(rfidWriterList[0].RFidreaderType);
                        reader.Open(rfidWriterList[0].RFidreaderIP);

                        this.readerLB.Items.Add(Convert.ToString(rfidWriterList[0].RFidreaderID + " " + rfidWriterList[0].RFidreaderIP + " " + rfidWriterList[0].RFidreaderType));
                    }

                    //Reader打开之前不可用
                    this.btnWrite.Enabled = true;
                    this.btnReadM4.Enabled = true;
                    this.lockBTN.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("打开读写器失败:" + ex.Message);
                }
            }
            else
            {
                this.readerLB.Items.Clear();
                this.reader.CleanBuffer();
                this.reader.Close();

                //Reader关闭之后不可用
                this.btnWrite.Enabled = false;
                this.btnReadM4.Enabled = false;
                this.lockBTN.Enabled = false;
            }
        }