首页上一页 1 下一页尾页 1 条记录 1/1页
如何使用C#调用读卡器的接口实现读卡,写卡功能
发表在C#图书答疑
2016-01-20
是否精华
是
否
版块置顶:
是
否
int rf_init(int port,long baud);
功 能:初始化串口
参 数:port:串口号,取值为0~3
baud:为通讯波特率9600~115200
返 回:成功则返回串口标识符>0,失败返回负值,见错误代码表
例:int icdev;
icdev=rf_init(0,9600);//初始化串口1,波特率9600
如果是WIN32程序则icdev为设备句柄,见下例:
HANDLE icdev;
icdev=rf_init(0,115200);
if(icdev<0)
MessageBox(“rf_init error”);
-------------------------------------------------
public unsafe class IC
{
//对设备进行初始化
[DllImport("mwrf32.dll", EntryPoint = "rf_init", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int rf_init(int port, int baud);
//使设备发出蜂鸣声
[DllImport("mwrf32.dll", EntryPoint = "dv_beep", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int dv_beep(int icdev, int time);
}
private void button1_Click(object sender, EventArgs e)
{
int icdev;
icdev = IC.rf_init(1,9600);//初始化串口1,波特率9600
int beep = IC.dv_beep(icdev, 20);
}
功 能:初始化串口
参 数:port:串口号,取值为0~3
baud:为通讯波特率9600~115200
返 回:成功则返回串口标识符>0,失败返回负值,见错误代码表
例:int icdev;
icdev=rf_init(0,9600);//初始化串口1,波特率9600
如果是WIN32程序则icdev为设备句柄,见下例:
HANDLE icdev;
icdev=rf_init(0,115200);
if(icdev<0)
MessageBox(“rf_init error”);
-------------------------------------------------
public unsafe class IC
{
//对设备进行初始化
[DllImport("mwrf32.dll", EntryPoint = "rf_init", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int rf_init(int port, int baud);
//使设备发出蜂鸣声
[DllImport("mwrf32.dll", EntryPoint = "dv_beep", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int dv_beep(int icdev, int time);
}
private void button1_Click(object sender, EventArgs e)
{
int icdev;
icdev = IC.rf_init(1,9600);//初始化串口1,波特率9600
int beep = IC.dv_beep(icdev, 20);
}