public MainWindow() { InitializeComponent(); this.DataContext = this; this.Colors = typeof(Colors) .GetProperties() .Where(prop => typeof(Color).IsAssignableFrom(prop.PropertyType)) .Select(prop => new KeyValuePair <String, Color>(prop.Name, (Color)prop.GetValue(null))) .ToList(); var theme = ThemeManager.DetectAppStyle(Application.Current); ThemeManager.ChangeAppStyle(this, theme.Item2, theme.Item1); connectBackgroundWorker.DoWork += ConnectBackgroundWorker_DoWork; connectBackgroundWorker.RunWorkerCompleted += ConnectBackgroundWorker_RunWorkerCompleted; connectBackgroundWorker.ProgressChanged += ConnectBackgroundWorker_ProgressChanged; m_ReadTag = new Symbol.RFID3.TagData(); m_UpdateStatusHandler = new UpdateStatus(myUpdateStatus); m_UpdateReadHandler = new UpdateRead(myUpdateRead); m_TagTable = new Hashtable(); m_IsConnected = false; m_TagTotalCount = 0; }
/// <summary> /// RSSI ANT 解析 返回Object[] /// </summary> private void RSSI_ANT_TagAnalysis() { //是否已经开启读取 if (m_IsReading) { object[] objTag = new object[3]; //Thread.Sleep(500); Symbol.RFID3.TagData[] tagDataArray = m_RFIDReader.Actions.GetReadTags(100); if (tagDataArray != null) { //解析标签 if (tagDataArray.Length > 0) { for (int tagi = 0; tagi < tagDataArray.Length; tagi++) { Symbol.RFID3.TagData tag = tagDataArray[tagi]; objTag[0] = tag.TagID; objTag[1] = tag.PeakRSSI; objTag[2] = tag.AntennaID; GetRFIDTagObj(objTag); } } } } }
//Timer run to get the tag data(Antenna no, tagid,....) private void tmrPortEntryArea_Tick(object sender, EventArgs e) { string WBNO; try { if (PortEntry_readerAPI.IsConnected) { lblReaderStatus_PortEntry_Text.Text = "# Connected"; } //else //lblReaderStatus_PortEntry_Text.Text = "# Not Connected"; } catch (Exception) { lblReaderStatus_PortEntry_Text.Text = "# Not Connected"; } try { Symbol.RFID3.TagData[] tagData = PortEntry_readerAPI.Actions.GetReadTags(1); if (tagData != null) { string newtag, dstr; AutoResetEvent AccessComplete; AccessComplete = new AutoResetEvent(false); int nIndex = 0; //for (int nIndex = 0; nIndex < tagData.Length; nIndex++) //{ if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { Symbol.RFID3.TagData tag = tagData[nIndex]; if (Class_ProperityLayer.DupTagNo1 == tagData[nIndex].TagID.Replace(" ", "").Substring(0, 5)) { PortEntry_readerAPI.Actions.PurgeTags(); return; } else { string tagIDPortEntry = tag.TagID; string tagAntennaID = tag.AntennaID.ToString(); Class_ProperityLayer.AntNo1 = tag.AntennaID; string tagID = tag.TagID; // getting tagid here 113370000000000000000000 string tagno = tagData[nIndex].TagID; string RSSI = tag.PeakRSSI.ToString(); string Tagno = tagno.Replace(" ", "").Substring(0, 5); Class_ProperityLayer.DupTagNo1 = Tagno;//get the tagnum to restreict duplicate values Class_ProperityLayer.PTAGNO1 = Tagno; string Ant = tag.AntennaID.ToString(); string LOC = ConfigurationManager.AppSettings["loc"]; //string Reader = ConfigurationManager.AppSettings["fixreaderip"]; string Reader = MyDataCollection.ReaderIP; CatchData(string.Format("{0},{1},{2},{3},{4}", "DATA LOG", Tagno, Ant, RSSI, DateTime.Now)); if (int.Parse(Ant) >= 1 && int.Parse(Ant) <= 2) { //tagdate = DateTime.Now; fixant = 1; WBNO = ConfigurationManager.AppSettings["WBIN"]; Class_ProperityLayer.PWBNO1 = WBNO; PFlag = 1; FunctionPortEntryIn(tagIDPortEntry, tagAntennaID); } else { fixant = 2; WBNO = ConfigurationManager.AppSettings["WBOUT"]; Class_ProperityLayer.PWBNO1 = WBNO; PFlag = 2; FunctionPortEntryOut(tagIDPortEntry, tagAntennaID); } } } //} } } catch (Exception) { //btnPortEntryAreaReaderDisconnect_Click(sender, e); //tmrPortEntryArea.Enabled = false; } }
private void myUpdateRead(Events.ReadEventData eventData) { Symbol.RFID3.TagData[] tagData = m_ReaderAPI.Actions.GetReadTags(1000); if (tagData != null) { for (int nIndex = 0; nIndex < tagData.Length; nIndex++) { if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { Symbol.RFID3.TagData tag = tagData[nIndex]; string tagID = tag.TagID; bool isFound = false; //lock (m_TagTable.SyncRoot) //{ // isFound = m_TagTable.ContainsKey(tagID); // if (!isFound && this.memBank_CB.SelectedIndex >= 1) // { // tagID = tag.TagID + tag.MemoryBank.ToString() + tag.MemoryBankDataOffset.ToString(); // isFound = m_TagTable.ContainsKey(tagID); // } //} if (isFound) { uint count = 0; ListViewItem item = (ListViewItem)m_TagTable[tagID]; try { count = uint.Parse(item.SubItems[3].Text) + tagData[nIndex].TagSeenCount; m_TagTotalCount += tagData[nIndex].TagSeenCount; } catch (FormatException fe) { functionCallStatusLabel.Text = fe.Message; break; } item.SubItems[1].Text = tag.TagID.ToString(); item.SubItems[2].Text = System.DateTime.Now.ToString(); } else { ListViewItem item = new ListViewItem(tag.TagID); // 1 - tag event ListViewItem.ListViewSubItem subItem; subItem = new ListViewItem.ListViewSubItem(item, System.DateTime.Now.ToString()); item.SubItems.Add(subItem); // 2 - antenna ID //if (memBank_CB.SelectedIndex >= 1) //{ // // 7 - Memory bank data // subItem = new ListViewItem.ListViewSubItem(item, tag.MemoryBankData); // item.SubItems.Add(subItem); // string memoryBank = tag.MemoryBank.ToString(); // int index = memoryBank.LastIndexOf('_'); // if (index != -1) // { // memoryBank = memoryBank.Substring(index + 1); // } // // 8 - Memory Bank // subItem = new ListViewItem.ListViewSubItem(item, memoryBank); // item.SubItems.Add(subItem); // // 9 - memory bank offset // subItem = new ListViewItem.ListViewSubItem(item, tag.MemoryBankDataOffset.ToString()); // item.SubItems.Add(subItem); //} //else //{ // subItem = new ListViewItem.ListViewSubItem(item, ""); // item.SubItems.Add(subItem); // subItem = new ListViewItem.ListViewSubItem(item, ""); // item.SubItems.Add(subItem); // subItem = new ListViewItem.ListViewSubItem(item, ""); // item.SubItems.Add(subItem); //} inventoryList.BeginUpdate(); inventoryList.Items.Add(item); inventoryList.EndUpdate(); lock (m_TagTable.SyncRoot) { m_TagTable.Add(tagID, item); } } } } } }
private void myUpdateRead(Events.ReadEventData eventData) { int index = 0; ListViewItem item; Symbol.RFID3.TagData[] tagData = m_ReaderAPI.Actions.GetReadTags(1000); if (tagData != null) { for (int nIndex = 0; nIndex < tagData.Length; nIndex++) { if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { Symbol.RFID3.TagData tag = tagData[nIndex]; string tagID = tag.TagID; bool isFound = false; sbLog.AppendLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff") + "|" + tag.TagID + "|" + tag.AntennaID + "|" + tag.PeakRSSI); lock (m_TagTable.SyncRoot) { isFound = m_TagTable.ContainsKey(tagID); if (!isFound) { tagID += ((uint)tag.MemoryBank + tag.MemoryBankDataOffset); isFound = m_TagTable.ContainsKey(tagID); } } if (isFound) { uint count = 0; item = (ListViewItem)m_TagTable[tagID]; try { count = uint.Parse(item.SubItems[2].Text) + tagData[nIndex].TagSeenCount; m_TagTotalCount += tagData[nIndex].TagSeenCount; } catch (FormatException fe) { functionCallStatusLabel.Text = fe.Message; break; } item.SubItems[1].Text = tag.AntennaID.ToString(); item.SubItems[2].Text = count.ToString(); item.SubItems[3].Text = tag.PeakRSSI.ToString(); string memoryBank = tag.MemoryBank.ToString(); index = memoryBank.LastIndexOf('_'); if (index != -1) { memoryBank = memoryBank.Substring(index + 1); } if (tag.MemoryBankData.Length > 0 && !memoryBank.Equals(item.SubItems[5].Text)) { item.SubItems[5].Text = tag.MemoryBankData; item.SubItems[6].Text = memoryBank; item.SubItems[7].Text = tag.MemoryBankDataOffset.ToString(); lock (m_TagTable.SyncRoot) { m_TagTable.Remove(tagID); m_TagTable.Add(tag.TagID + tag.MemoryBank.ToString() + tag.MemoryBankDataOffset.ToString(), item); } } } else { item = new ListViewItem(tag.TagID); ListViewItem.ListViewSubItem subItem; subItem = new ListViewItem.ListViewSubItem(item, tag.AntennaID.ToString()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, tag.TagSeenCount.ToString()); m_TagTotalCount += tag.TagSeenCount; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, tag.PeakRSSI.ToString()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, tag.PC.ToString("X")); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, ""); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, ""); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(item, ""); item.SubItems.Add(subItem); inventoryList.BeginUpdate(); inventoryList.Items.Add(item); inventoryList.EndUpdate(); lock (m_TagTable.SyncRoot) { m_TagTable.Add(tagID, item); } } } } totalTagValueLabel.Text = m_TagTable.Count + "(" + m_TagTotalCount + ")"; } }
//Timer run to get the tag data(Antenna no, tagid,....) private void tmrParkingArea_Tick(object sender, EventArgs e) { string WBNO; try { if (Parking_readerAPI.IsConnected) { lblReaderStatus_Parking_Text.Text = "# Connected"; } { //Parking_readerAPI.Config.GPO[1].PortState = GPOs.GPO_PORT_STATE.TRUE; } //else //lblReaderStatus_Parking_Text.Text = "# Not Connected"; } catch (Exception ex) { lblReaderStatus_Parking_Text.Text = "# Not Connected"; // Parking_readerAPI.Config.GPO[1].PortState = GPOs.GPO_PORT_STATE.FALSE; } try { Symbol.RFID3.TagData[] tagData = Parking_readerAPI.Actions.GetReadTags(1); if (tagData != null) { string newtag, dstr; AutoResetEvent AccessComplete; AccessComplete = new AutoResetEvent(false); int nIndex = 0; //for (int nIndex = 0; nIndex < tagData.Length; nIndex++) //{ if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { Symbol.RFID3.TagData tag = tagData[nIndex]; if (Class_ProperityLayer.DupTagNo1 == tagData[nIndex].TagID.Replace(" ", "").Substring(0, 5)) { this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Duplicate Tag Found."); Parking_readerAPI.Actions.PurgeTags(); return; } else { string tagIDParking = tag.TagID; string tagAntennaID = tag.AntennaID.ToString(); Class_ProperityLayer.AntNo1 = tag.AntennaID; string tagID = tag.TagID; // getting tagid here 113370000000000000000000 string tagno = tagData[nIndex].TagID; string RSSI = tag.PeakRSSI.ToString(); string Tagno = tagno.Replace(" ", "").Substring(0, 5); this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Tagno + " Tag captured successfully"); Class_ProperityLayer.DupTagNo1 = Tagno; //get the tagnum to restreict duplicate values Class_ProperityLayer.PTAGNO1 = Tagno; string Ant = tag.AntennaID.ToString(); string LOC = ConfigurationManager.AppSettings["loc"]; //string Reader = ConfigurationManager.AppSettings["fixreaderip"]; string Reader = MyDataCollection.ReaderIP; CatchData(string.Format("{0},{1},{2},{3},{4}", "DATA LOG", Tagno, Ant, RSSI, DateTime.Now)); if (int.Parse(Ant) >= 1 && int.Parse(Ant) <= 2) { //tagdate = DateTime.Now; fixant = 1; Class_ProperityLayer.PWBNO1 = ConfigurationManager.AppSettings["AntennaLoc1"]; PFlag = 1; //this.dataGridViewTagDetails.Rows.Add(fixant, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Class_ProperityLayer.PTAGNO1 + " has read captured successfully"); FunctionAntennaSet1(tagIDParking, tagAntennaID); } else { fixant = 2; Class_ProperityLayer.PWBNO1 = ConfigurationManager.AppSettings["AntennaLoc2"]; PFlag = 2; FunctionParkingOut(tagIDParking, tagAntennaID); } } } //} } } catch (Exception) { //btnParkingAreaReaderDisconnect_Click(sender, e); //tmrParkingArea.Enabled = false; } }
//Timer run to get the tag data(Antenna no, tagid,....) private void tmrParkingArea_Tick(object sender, EventArgs e) { string WBNO; try { if (Parking_readerAPI.IsConnected) { lblReaderStatus_Parking_Text.Text = "# Connected"; } else { lblReaderStatus_Parking_Text.Text = "# Not Connected"; } } catch (Exception) { lblReaderStatus_Parking_Text.Text = "# Not Connected"; } try { Symbol.RFID3.TagData[] tagData = Parking_readerAPI.Actions.GetReadTags(1); if (tagData != null) { string newtag, dstr; AutoResetEvent AccessComplete; AccessComplete = new AutoResetEvent(false); for (int nIndex = 0; nIndex < tagData.Length; nIndex++) { if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { Symbol.RFID3.TagData tag = tagData[nIndex]; string tagIDParking = tag.TagID; string tagAntennaID = tag.AntennaID.ToString(); string tagID = tag.TagID; // getting tagid here 113370000000000000000000 string tagno = tagData[nIndex].TagID; string RSSI = tag.PeakRSSI.ToString(); string Tagno = tagno.Replace(" ", "").Substring(0, 5); Class_ProperityLayer.PTAGNO1 = Tagno; string Ant = tag.AntennaID.ToString(); string LOC = ConfigurationManager.AppSettings["loc"]; //string Reader = ConfigurationManager.AppSettings["fixreaderip"]; string Reader = MyDataCollection.ReaderIP; if (int.Parse(Ant) >= 1 && int.Parse(Ant) <= 2) { WBNO = ConfigurationManager.AppSettings["WBIN"]; Class_ProperityLayer.PWBNO1 = WBNO; PFlag = 1; FunctionParkingIn(tagIDParking, tagAntennaID); } else { WBNO = ConfigurationManager.AppSettings["WBOUT"]; Class_ProperityLayer.PWBNO1 = WBNO; PFlag = 2; FunctionParkingOut(tagIDParking, tagAntennaID); } } } } } catch (Exception) { } }
//Timer run to get the tag data(Antenna no, tagid,....) private void timerReader_Tick(object sender, EventArgs e) { string WBNO; try { if (Parking_readerAPI.IsConnected) { lblReaderStatusText.Text = "# Connected"; } lblErrorMessageText.Text = "-"; //else //lblReaderStatus_Parking_Text.Text = "# Not Connected"; } catch (Exception ex) { lblReaderStatusText.Text = "# Not Connected"; lblErrorMessageText.Text = ex.ToString(); } try { Symbol.RFID3.TagData[] tagData = Parking_readerAPI.Actions.GetReadTags(1); if (tagData != null) { string newtag, dstr; AutoResetEvent AccessComplete; AccessComplete = new AutoResetEvent(false); int nIndex = 0; //for (int nIndex = 0; nIndex < tagData.Length; nIndex++) //{ if (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_NONE || (tagData[nIndex].OpCode == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ && tagData[nIndex].OpStatus == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)) { if (this.dataGridViewTagDetails.Rows.Count > 3) { this.dataGridViewTagDetails.Rows.Clear(); } Symbol.RFID3.TagData tag = tagData[nIndex]; if (Class_ProperityLayer.DupTagNo1 == tagData[nIndex].TagID.Replace(" ", "").Substring(0, 5)) { this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Duplicate Tag Found."); Parking_readerAPI.Actions.PurgeTags(); return; } else { string tagIDParking = tag.TagID; string tagAntennaID = tag.AntennaID.ToString(); //Class_ProperityLayer.AntNo1 = tag.AntennaID; string tagID = tag.TagID; // getting tagid here 113370000000000000000000 string tagno = tagData[nIndex].TagID; string RSSI = tag.PeakRSSI.ToString(); string Tagno = tagno.Replace(" ", "").Substring(0, 5); //Class_ProperityLayer.DupTagNo1 = Tagno;//get the tagnum to restreict duplicate values //Class_ProperityLayer.PTAGNO1 = Tagno; string Ant = tag.AntennaID.ToString(); //string LOC = ConfigurationManager.AppSettings["loc"]; //string Reader = ConfigurationManager.AppSettings["fixreaderip"]; //string Reader = MyDataCollection.ReaderIP; CatchData(string.Format("{0},{1},{2},{3},{4}", "DATA LOG", Tagno, Ant, RSSI, DateTime.Now)); if (int.Parse(Ant) >= 1 && int.Parse(Ant) <= 2) { if (classGlobalVariables.AntenaSet1OldTag != Tagno) { //fixant = 1; //WBNO = ConfigurationManager.AppSettings["WBIN"]; //Class_ProperityLayer.PWBNO1 = WBNO; //PFlag = 1; Parking_readerAPI.Config.GPO[classGlobalVariables.AntenaSet1Loc_Camara_GPIO_PortNo].PortState = GPOs.GPO_PORT_STATE.TRUE; Parking_readerAPI.Config.GPO[classGlobalVariables.AntenaSet1Loc_Camara_GPIO_PortNo].PortState = GPOs.GPO_PORT_STATE.FALSE; string newImagePath = classFTPOperstaions.GetDirectoryListing(classGlobalVariables.AntenaSet1Loc_CamaraFTP_Path, classGlobalVariables.AntenaSet1Loc_SaveImage_Path); pictureBoxImgatLoc1.ImageLocation = newImagePath; pictureBoxImgatLoc1.SizeMode = PictureBoxSizeMode.StretchImage; string SaveTransactionStatus = classSaveTransactionDetails.SaveTransaction(Tagno, Ant, classGlobalVariables.AntenaSet1Loc, classGlobalVariables.RaederIP, newImagePath); classGlobalVariables.AntenaSet1OldTag = Tagno; this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Tagno + " Tag captured successfully"); } else { this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Tagno + " Duplicate Tag found."); } } else if (int.Parse(Ant) >= 3 && int.Parse(Ant) <= 4) { if (classGlobalVariables.AntenaSet2OldTag != Tagno) { //fixant = 2; //WBNO = ConfigurationManager.AppSettings["WBOUT"]; //Class_ProperityLayer.PWBNO1 = WBNO; //PFlag = 2; Parking_readerAPI.Config.GPO[classGlobalVariables.AntenaSet2Loc_Camara_GPIO_PortNo].PortState = GPOs.GPO_PORT_STATE.TRUE; Parking_readerAPI.Config.GPO[classGlobalVariables.AntenaSet2Loc_Camara_GPIO_PortNo].PortState = GPOs.GPO_PORT_STATE.FALSE; string newImagePath = classFTPOperstaions.GetDirectoryListing(classGlobalVariables.AntenaSet2Loc_CamaraFTP_Path, classGlobalVariables.AntenaSet2Loc_SaveImage_Path); pictureBoxImgatLoc2.ImageLocation = newImagePath; pictureBoxImgatLoc2.SizeMode = PictureBoxSizeMode.StretchImage; string SaveTransactionStatus = classSaveTransactionDetails.SaveTransaction(Tagno, Ant, classGlobalVariables.AntenaSet2Loc, classGlobalVariables.RaederIP, newImagePath); classGlobalVariables.AntenaSet2OldTag = Tagno; this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Tagno + " Tag captured successfully"); } else { this.dataGridViewTagDetails.Rows.Add(tag.AntennaID, tag.TagID.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Tagno + " Duplicate Tag found."); } } } } } } catch (Exception) { //btnParkingAreaReaderDisconnect_Click(sender, e); //tmrParkingArea.Enabled = false; } }