如何在C#中的Eventhandler方法中访问类成员变量

时间:2017-08-30 06:31:21

标签: c# design-patterns rfid eventhandler

我正在使用香港RFID阅读器设备编写RFID阅读器应用程序。

供应商提供了与其设备进行通信(套接字通信)的Dll,并通过Eventhandler将RFID标签信息发送回应用程序。

然后,我需要将相同的RFID标签信息存储到数据库中以进行报告。

但是这里的阻塞点是我不知道如何访问EventHandler中的类成员变量。

 Class HKRFID
        {
           private HKRFID.Active.HKRAREM[] mHKRFIDClass;

           private Init()
           {        

             mHKRFIDClass = new HKRFID.Active.HKRAREM[5];   //total rfid reader     count is 5.
             mHKRFIDClass[i] = new HKRFID.Active.HKRAREM(_sProcDetails[i].IpAddress, HKRFID.Active.HKRAREM.ConnectionType.TCP);
             mHKRFIDClass[i].GetLibVersion();
             mHKRFIDClass[i].Connect();                             
             mHKRFIDClass[i].StartTagInventory();
          // Register receive tags event, reader_BulkReadReturn
          mHKRFIDClass[i].TagReturn += new EventHandler<HKRFID.Active.HKRAREM.TagReturnEventArgs>(reader_BulkReadReturn);
            }

        void reader_BulkReadReturn(object sender,HKRFID.Active.HKRAREM.TagReturnEventArgs e){                       
                        string tag_id = HKRFID.Utility.HexTools.ByteArrayToHexString(e.return_tag.tag_id);

              string tagID = tag_id.Replace("-", "");
              string sTagID = tagID.Trim().Substring(0, tagID.Length - 2);

//Here I need to know which RFID reader device reads this tag information.
e.G) IP address of this RFID reader device.

//FYI, I have all reader information in the mHKRFIDClass[] object.

             }
         }

由于Eventhandler方法来自Vendor Dll,我无法修改它。

所以请告诉我如何将收到的RFID标签信息与相应的阅读器进行匹配,或者告诉我比上述代码更好的代码设计模式。

提前致谢。

0 个答案:

没有答案