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);就提示“未将对象引用设置到对象的实例”,望各位能指点一下,谢谢
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);就提示“未将对象引用设置到对象的实例”,望各位能指点一下,谢谢
解决方案 »
- C# winform ShowWindowAsync无法激活问题
- .net做的小程序别人是不是必须装完整的.NET3.5
- 如何判断 ftp 服务器中一个文件是否存在, C# + socket 实现.
- 各位大哥帮帮忙,小妹在线等,附件下载的问题
- DataGridViewComboBoxColumn绑定数据
- 如何用代码模拟在某个窗口中按F1键?
- 实现代码的在线修改
- C#中调用Excel的问题:接口 Excel._Application 的 QueryInterface 失败。
- 各位高手。。。。
- 高手菜鸟们请进!有兴趣留下大家的联系方式吗?有空可以交流交流!
- 虚心请教!~
- 问一个关于正则表达式匹配的问题
改成
if(Read_Event != null)
{
Read_Event(this);
}你的调用过程里要挂上这个事件
//加上
rd.Read_Event_Handler += new EventHandler(你的事件处理);
rd.ReadText = data.ToString();
this.ComSound(10);
this.ComClose();