当前位置: 首页 > news >正文

有密钥保护的物流跟踪、图书馆管理ISO15693标签ICODE SLIX2读写C#源码

本示例使用的发卡器:https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.3edc645eNmdutm&ft=t&id=615391857885

一、卡密钥认证

private void button22_Click(object sender, EventArgs e)
{byte passwordid;            //密钥类型byte[] uidbuf = new byte[8];     //卡UIDbyte[] authkeybuf = new byte[4]; //认证密钥if (checkhexstr(textBox4.Text, 8, uidbuf, 0) == false){MessageBox.Show("需要操作的卡片UID错误,可先执行寻卡操作获取UID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}if (checkhexstr(textBox6.Text, 4, authkeybuf, 0) == false){MessageBox.Show("卡片认证密钥输入错误,请输入8位16进制卡认证密钥!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox6.Select();return;}switch (comboBox2.SelectedIndex) {case 4:passwordid = 0x10;break;case 3:passwordid = 0x08;break;case 2:passwordid = 0x04;break;case 1:passwordid = 0x02;break;default:passwordid = 0x01;break;}byte ctrlword = 0x04;byte status = iso15693authkey(ctrlword, uidbuf, passwordid, authkeybuf);if (status == 0){pcdbeep(50);MessageBox.Show("UID:" + textBox4.Text + " 密钥认证成功!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }
}

二、更改卡密钥

private void button23_Click(object sender, EventArgs e)
{byte passwordid;  //密钥类型byte[] uidbuf = new byte[8];     //卡UIDbyte[] newkeybuf = new byte[4];  //认证密钥if (checkhexstr(textBox4.Text, 8, uidbuf, 0) == false){MessageBox.Show("需要操作的卡片UID错误,可先执行寻卡操作获取UID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}if (checkhexstr(textBox10.Text, 4, newkeybuf, 0) == false){MessageBox.Show("卡片新密钥输入错误,请输入8位16进制卡新密钥!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);textBox10.Select();return;}switch (comboBox2.SelectedIndex){case 4:passwordid = 0x10;break;case 3:passwordid = 0x08;break;case 2:passwordid = 0x04;break;case 1:passwordid = 0x02;break;default:passwordid = 0x01;break;}byte ctrlword = 0x04;byte status = iso15693writekey(ctrlword, uidbuf, passwordid, newkeybuf);switch (status){case 0:pcdbeep(50);MessageBox.Show("UID:" + textBox4.Text + " 更改卡密钥成功!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);break;case 47:MessageBox.Show("异常代码:47,上一条指令必须是认证密码指令......!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);break;default:MessageErrInf(status);break;}            
}

三、设置块密钥保护认证方式

private void button27_Click(object sender, EventArgs e)
{byte[] uidbuf = new byte[8];     //卡UIDif (checkhexstr(textBox4.Text, 8, uidbuf, 0) == false){MessageBox.Show("需要操作的卡片UID错误,可先执行寻卡操作获取UID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}byte blockpoint = (byte)HLblockpoint.Value;     //高、低区分割块地址byte extprotectstatus = (byte)(comboBox3.SelectedIndex + comboBox4.SelectedIndex * 16); //高、低区密钥保护模式byte ctrlword = 0x04;byte status = iso15693protectblock(ctrlword, uidbuf, blockpoint, extprotectstatus);switch (status){case 0:pcdbeep(50);MessageBox.Show("UID:" + textBox4.Text + " 块密码保护设定成功!" , "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);break;case 47:MessageBox.Show("异常代码:47,必须都认证读取密码和写入密码成功后再进行块密码保护设定!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);break;default:MessageErrInf(status);break;} 
}

四、读取卡内数据

private void button7_Click(object sender, EventArgs e)
{//读卡块内数据            		textBox5.Text = "22";  //操作多张卡标志用byte ctrlword = System.Convert.ToByte(textBox5.Text, 16);//以十六进制方式转成数值byte startblock = (byte)ctstartblock.Value;byte blocknum = (byte)ctblocknum.Value;byte[] uidbuf = new byte[8];byte[] revbuf = new byte[255];//卡数据缓冲byte[] revlen = new byte[1];            if (checkhexstr(textBox4.Text, 8, uidbuf, 0) == false){MessageBox.Show("需要操作的卡片UID错误,可先执行寻卡操作获取UID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}int j = 0;string carddatahex = "";byte status = 8;while (j<blocknum){status = iso15693readblock(ctrlword, System.Convert.ToByte(startblock + j), 1, uidbuf, revlen, revbuf);if (status == 0){for (int i = 0; i < revlen[0]; i++){carddatahex += revbuf[i].ToString("X02")+ " ";}j++;}else { j = blocknum; }}if (status==0) {richTextBox1.Text = carddatahex;pcdbeep(50);}else if (status==46 ){MessageBox.Show("请先认证相应的密码!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);            }else{  MessageErrInf(status);}
}

五、写数据

private void button8_Click(object sender, EventArgs e)
{//块写内数据byte status;//存放返回值byte ctrlword;byte startblock;byte blocknum;byte[] uidbuf = new byte[8];byte[] writebuf = new byte[1024];//卡数据缓冲byte[] mypiccdata = new byte[32];byte eachblocksize;int revlen ;int i,j,p;//控制字指定,控制字的含义请查看本公司网站提供的动态库说明switch (comboBox1.SelectedIndex){case 2:eachblocksize = 32;break;case 1:eachblocksize = 8;break;default:eachblocksize = 4;break;}textBox5.Text = "22";  //操作多张卡标志用ctrlword = System.Convert.ToByte(textBox5.Text, 16);//以十六进制方式转成数值startblock =(byte)ctstartblock.Value ;blocknum  =(byte)ctblocknum .Value ;revlen = Convert.ToInt16(blocknum * eachblocksize);if (checkhexstr(textBox4.Text, 8, uidbuf, 0) == false){MessageBox.Show("需要操作的卡片UID错误,可先执行寻卡操作获取UID!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}if (checkhexstr(richTextBox1.Text, revlen, writebuf, 0) == false){MessageBox.Show("需要写入的数据输入错误,可先执行读卡操作!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}j = 0;status = 8;while (j < blocknum){for (p = 0; p < eachblocksize - 1; p++) {mypiccdata[p]=writebuf[j*eachblocksize+p]; }status = iso15693writeblock(ctrlword,  System.Convert.ToByte(startblock + j), 1, uidbuf, eachblocksize, mypiccdata);if (status == 0){j++;}else { j = blocknum; }}switch (status){case 0:pcdbeep(50);MessageBox.Show("UID:" + textBox4.Text + "写卡成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);break;case 46:MessageBox.Show("请先认证相应的密码!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Stop);break;default:MessageErrInf(status);break;}
}

六、修改SLIX1830标签UID

private void button21_Click(object sender, EventArgs e)
{byte[] olduidbuf = new byte[8];  //旧uid缓冲byte[] newuidbuf = new byte[8];  //新UID缓冲           //控制字指定,控制字的含义请查看本公司网站提供的动态库说明byte ctrlword = 0;byte afi = System.Convert.ToByte(textBox1.Text, 16);//以十六进制方式转成数值for (int i = 0; i < 8; i++){olduidbuf[i] = 0;}if (checkhexstr(textBox4.Text, 8, newuidbuf, 0) == false){MessageBox.Show("需要写入的卡片UID错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}byte status = iso15693writeuid(ctrlword, afi, olduidbuf, newuidbuf);if (status == 0){pcdbeep(50);MessageBox.Show("UID:" + textBox4.Text + " 写入卡内成功!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { MessageErrInf(status); }
}

http://www.dtcms.com/a/320376.html

相关文章:

  • 跨学科视域下的深层语义分析与人类底层逻辑一致性探索
  • 计数组合学7.15(Schur 函数的经典定义 )
  • 多模态融合(Multimodal Fusion)
  • 神策埋点是什么
  • C语言:单链表学习
  • 城市道路场景下漏检率↓76%:陌讯多模态融合算法在井盖缺失识别中的实践
  • Nestjs框架: 管道机制(Pipe)从校验到转换的全流程解析
  • ROS Launch 文件中的替换参数详解
  • 1.电动汽车动力电池系统技术介绍与分类
  • 在线文档自动化工具有什么
  • 周志华院士西瓜书实战(三)聚类+邻居+PCA+特征选择+半监督学习
  • 【Canvas与徽章】北极星蓝盘玻璃光徽章
  • NumPy库向量的常见运算
  • C++面试9——多继承陷阱与适用场景
  • 【新闻资讯】Anthropic CEO 达里奥·阿莫迪万字访谈:在技术加速与风险防控间的坚守
  • vLLM:彻底改变大型语言模型推理延迟和吞吐量
  • RabbitMQ面试精讲 Day 14:Federation插件与数据同步
  • YOLOv8面试知识
  • Linux系统编程--基础开发工具
  • 容器之王--Docker的部署及基本操作演练
  • 前端学习 7:EDA 工具
  • Springboot 使用 JPA 分页查询
  • 前端开发工具大全
  • 车辆特征与车牌识别准确率↑29%:陌讯多模态融合算法实战解析
  • 知识蒸馏 - 基于KL散度的知识蒸馏 KL散度的方向
  • 适配器模式及优化
  • 在NVIDIA Orin上用TensorRT对YOLO12进行多路加速并行推理时内存泄漏 (中)
  • linux系统编程
  • 使用winsw把SpringBoot项目注册成window服务
  • javaweb开发之会话_过滤器_监听器