-
大小: 15KB文件类型: .cs金币: 1下载: 0 次发布日期: 2021-06-01
- 语言: C#
- 标签: CRT_591_M001
资源简介
由于官方给出的案例写的比较模糊,自己对协议也研究了一两天,所以在此贡献c#版的操作类,方便需要的同学用到,在此我这边读写位数可以20位,我存的是单号:比如:20180518205402123456 这样位数,如果需要长度更长,需要更改,读写方法里面的长度
代码片段和文件信息
using System;
using System.Runtime.InteropServices;
namespace Common.ICCard4442
{
public class ICCard4442
{
//打开串口
[DllImport(“CRT_591_M001.dll“)]
public static extern UInt32 CRT591MROpen(string port);
//按指定的波特率打开串口
[DllImport(“CRT_591_M001.dll“)]
public static extern UInt32 CRT591MROpenWithBaut(string port UInt32 Baudrate);
//关闭串口
[DllImport(“CRT_591_M001.dll“)]
public static extern int CRT591MRClose(UInt32 ComHandle);
//int APIENTRY ExecuteCommand(HANDLE ComHandleBYTE TxAddrBYTE TxCmCodeBYTE TxPmCodeint TxDataLenBYTE TxData[]BYTE *RxReplyTypeBYTE *RxStCode0BYTE *RxStCode1BYTE *RxStCode2int *RxDataLenBYTE RxData[]);
[DllImport(“CRT_591_M001.dll“)]
public static extern int RS232_ExeCommand(UInt32 ComHandle byte TxAddr byte TxCmCode byte TxPmCode UInt16 TxDataLen byte[] TxData ref byte RxReplyType ref byte RxStCode0 ref byte RxStCode1 ref byte RxStCode2 ref UInt16 RxDataLen byte[] RxData);
}
public class ICCardHelper
{
private static UInt32 _hdle;
public static UInt32 Hdle
{
get
{
if (_hdle == 0)
{
_hdle = ICCard4442.CRT591MROpen(“COM1“);
return _hdle;
}
else
return _hdle;
}
set
{
value = _hdle;
}
}
private static byte _addr;
public static byte Addr
{
get
{
if (_addr == 0)
{
_addr = Convert.ToByte(0X00);
return _addr;
}
else
return _addr;
}
}
///
/// 验证密码
///
///
public static bool VerificationPassWord()
{
bool isSuccess = false;
byte Cm Pm;
UInt16 TxDataLen RxDataLen;
byte[] TxData = new byte[1024];
byte[] RxData = new byte[1024];
byte ReType = 0;
byte St0 St1 St2;
string PasswordStr = “FF FF FF“;
Cm = 0x53;
Pm = 0x33;
St0 = St1 = St2 = 0;
TxData[0] = 0x00;
TxData[1] = 0x20;
TxData[2] = 0x03;
TxData[3] = 0x01;
TxData[4] = 0x03; //length of Password 6 Bytes
TxData[5] = (byte)Convert.ToInt32(PasswordStr.Substring(0 2) 16);//0xff;
TxData[6] = (byte)Convert.ToInt32(PasswordStr.Substring(3 2) 16);//0xff;
TxData[7] = (byte)Convert.ToInt32(PasswordStr.Substring(6 2) 16);// 0xff;
//TxData[8] = (byte)Convert.ToInt32(PasswordStr.Substring(9 2) 16);// 0xff
评论
共有 条评论