private void button1_Click(object sender, System.EventArgs e)//轻松读卡
{
byte status;//存放返回值
byte myareano;//区号
byte authmode;//密码类型,用A密码或B密码
byte myctrlword;//控制字
byte[] mypicckey = new byte[6];//密码
byte[] mypiccserial = new byte[4];//卡序列号
byte[] mypiccdata = new byte[48]; //卡数据缓冲
//控制字指定,控制字的含义请查看本公司网站提供的动态库说明
myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY;
//指定区号
myareano = 8;//指定为第8区
//批定密码模式
authmode = 1;//大于0表示用A密码认证,推荐用A密码认证
//指定密码
mypicckey[0] = 0xff;
mypicckey[1] = 0xff;
mypicckey[2] = 0xff;
mypicckey[3] = 0xff;
mypicckey[4] = 0xff;
mypicckey[5] = 0xff;
status = piccreadex(myctrlword, mypiccserial, myareano, authmode, mypicckey, mypiccdata);
//在下面设定断点,然后查看mypiccserial、mypiccdata,
//调用完 piccreadex函数可读出卡序列号到 mypiccserial,读出卡数据到mypiccdata,
//开发人员根据自己的需要处理mypiccserial、mypiccdata 中的数据了。
//处理返回函数
switch (status)
{
case 0:
MessageBox.Show("操作成功,数据已返回在mypiccdata数组中");
break;
//......
case 8:
MessageBox.Show("请将卡放在感应区");
}
//返回解释
/*
REQUEST 8//寻卡错误
READSERIAL 9//读序列吗错误
SELECTCARD 10//选卡错误
LOADKEY 11//装载密码错误
AUTHKEY 12//密码认证错误
READ 13//读卡错误
WRITE 14//写卡错误
NONEDLL 21//没有动态库
DRIVERORDLL 22//动态库或驱动程序异常
DRIVERNULL 23//驱动程序错误或尚未安装
TIMEOUT 24//操作超时,一般是动态库没有反映
TXSIZE 25//发送字数不够
TXCRC 26//发送的CRC错
RXSIZE 27//接收的字数不够
RXCRC 28//接收的CRC错
*/
}
private void button3_Click(object sender, System.EventArgs e)//让设备发出声音
pcdbeep(50);
private void button2_Click(object sender, System.EventArgs e)//轻松写卡
byte i;
//指定卡数据
for (i = 0; i < 48; i++)
mypiccdata[i] = i;
status = piccwriteex(myctrlword, mypiccserial, myareano, authmode, mypicckey, mypiccdata);
MessageBox.Show("操作成功,mypiccdata数组中的数据已写入卡中");
private void button4_Click(object sender, System.EventArgs e)//修改单区密码
byte[] piccoldkey = new byte[6];//旧密码
byte[] piccnewkey = new byte[6]; //新密码.
myctrlword = 0;
//指定旧密码
piccoldkey[0] = 0xff;
piccoldkey[1] = 0xff;
piccoldkey[2] = 0xff;
piccoldkey[3] = 0xff;
piccoldkey[4] = 0xff;
piccoldkey[5] = 0xff;
//指定新密码,注意:指定新密码时一定要记住,否则有可能找不回密码,导致该卡报废。
piccnewkey[0] = 0xff;
piccnewkey[1] = 0xff;
piccnewkey[2] = 0xff;
piccnewkey[3] = 0xff;
piccnewkey[4] = 0xff;
piccnewkey[5] = 0xff;
status = piccchangesinglekey(myctrlword, mypiccserial, myareano, authmode, piccoldkey, piccnewkey);
MessageBox.Show("操作成功,密码已被修改!");