using System;
using System.Text;
using System.Threading;
using COMRD800Lib;namespace XZK
{
/// <summary>
/// Reader_Carder 的摘要说明。
/// </summary>
/// 
public delegate void Read_Event_Handler(object sender); 
public class Reader_Carder
{
RD800Class  rd = new RD800Class();
 
/// <summary>
/// 返回卡序列号
/// </summary> public Reader_Carder()
{
ReadCarder();
}
#region 初始化串口 public bool ComOpen()
{
if(rd.dc_init(100,115200)>0)
{
return true;
}
else
{
return false;
}
} #endregion #region 关闭串口 public bool ComClose()
{
if(rd.dc_exit() == 0)
{
return true;
}
else
{
return false;
}
}
#endregion #region 蜂鸣
public bool ComSound(int times)
{
if(rd.dc_beep(Convert.ToInt16(times)) >= 0)
{
return true;
}
else
{
return false;
}
}
#endregion  #region 读卡
/// <summary>
/// 读卡
/// </summary>
/// <returns>卡序列号</returns>
private void ReadCarder()
{
this.ComClose();
if(this.ComOpen())
{
while(true)
{
object data = null;
if(this.rd.dc_card(100,ref data) == 0)
{
Read rd = new Read();
rd.ReadText = data.ToString();
this.ComSound(10);
this.ComClose();
return;
}
}
}
}
#endregion
}
public class Read
{
public event Read_Event_Handler Read_Event = null;
private string _ReadText = "";
public string ReadText
{
set
{
_ReadText = value;
Read_Event(this);
}
}
public Read()
{
Reader_Carder rc = new Reader_Carder();
}
}
}
--------------------------------
上面是代码,我对这不熟悉,程序只要一运行到Read_Event(this);就提示“未将对象引用设置到对象的实例”,望各位能指点一下,谢谢

解决方案 »

  1.   

    我是通过事例化Read类来启动整个处理过程的
      

  2.   

    Read_Event
    改成
    if(Read_Event != null)
    {
    Read_Event(this);
    }你的调用过程里要挂上这个事件
      

  3.   

    Read rd = new Read();
    //加上
    rd.Read_Event_Handler += new EventHandler(你的事件处理);
    rd.ReadText = data.ToString();
    this.ComSound(10);
    this.ComClose();
      

  4.   

    public event Read_Event_Handler Read_Event = null;//你的Read_Event 变量没有实例化,当然就没有Read_Event(this);的调用了。
      

  5.   

    楼上正解委托没有实例化,也就是没有注册事件,也就是为null当然不能操作了