以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]还是关于读卡写卡的问题求助! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=30647) |
-- 作者:fjt4444 -- 发布时间:2013/4/1 15:16:00 -- [求助]还是关于读卡写卡的问题求助! 最近在做一个“车辆租赁管理系统”,遇到了一个超出了我能力范围的难题:写卡读卡。目标要求:通过“D8非接触式读写器”工具,1、对M1卡进行车辆信息录入(就两条信息,1,车牌号;2,租用开始时间);2、对M1卡上的车辆信息读取出来。目前我已经按照狐表帮助文档上那个“连接第三方设备”上的内容导入了相应的DLL文件,并写好了全局代码: Declare Function add_s Lib "dcrf32.dll" (ByVal i%) As Integer Declare Function dc_init Lib "dcrf32.dll" (ByVal port%, ByVal baud As Long) As Long
但由于我所使用的第三方设备没有狐表帮助文档上那个设备强大,我这边还需要自己定义一个write方法和一个read方法。可能是因为我智商不够用,或者是因为狐表对于第三方设备的例子和讲解太少的原因,我一直无法完成这个系统,对于一个购买了开发版的用户来说,我很悲剧,遇到问题问客服QQ,得到的答案还是帮助文档链接!所以特此发帖求助。究竟我该怎么写这个write和read方法,在哪里写?怎么调用?! |
-- 作者:fjt4444 -- 发布时间:2013/4/1 15:39:00 -- 不是这么简单的! 我用的这个第三方设备需要初始化、蜂鸣、核对密码等!以下是C#的代码: using System; /// <summary> } #region 对USB接口的使用(PHILIPH卡) [DllImport("dcrf32.dll")] [DllImport("dcrf32.dll")] [DllImport("dcrf32.dll")] [DllImport("dcrf32.dll")] #endregion public static bool WriteIn(string str) try ulong icCardNo = 0; byte[] hexkey = new byte[6] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
//核对密码 int address = 1; data32_hex = str; public static bool ReadCard(string str, out string CardNo) ulong icCardNo = 0; byte[] hexkey = new byte[6] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; st = dc_load_key(_icdev, 0, 1, hexkey); //核对密码 |
-- 作者:狐狸爸爸 -- 发布时间:2013/4/1 16:35:00 -- Imports System.Collections.Generic Imports System.Windows.Forms Imports System.Text Imports System.Runtime.InteropServices \'\'\' <summary> \'\'\' DUKa 的摘要说明 \'\'\' </summary> Public Class DUKa \' \' TODO: 在此处添加构造函数逻辑 \' Public Sub New() End Sub #Region "对USB接口的使用(PHILIPH卡)" <DllImport("dcrf32.dll")> _ Public Shared Function dc_init(ByVal port As Int32, ByVal baud As Long) As Integer End Function \'初试化 <DllImport("dcrf32.dll")> _ Public Shared Function dc_exit(ByVal icdev As Integer) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_reset(ByVal icdev As Integer, ByVal sec As UInteger) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_request(ByVal icdev As Integer, ByVal _Mode As Char, ByRef TagType As UInteger) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_card(ByVal icdev As Integer, ByVal _Mode As Char, ByRef Snr As ULong) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_halt(ByVal icdev As Integer) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_anticoll(ByVal icdev As Integer, ByVal _Bcnt As Char, ByRef IcCardNo As ULong) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_beep(ByVal icdev As Integer, ByVal _Msec As UInteger) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_authentication(ByVal icdev As Integer, ByVal _Mode As Integer, ByVal _SecNr As Integer) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_load_key(ByVal icdev As Integer, ByVal mode As Integer, ByVal secnr As Integer, <[In]()> ByVal nkey As Byte()) As Short End Function \'密码装载到读写模块中 <DllImport("dcrf32.dll")> _ Public Shared Function dc_load_key_hex(ByVal icdev As Integer, ByVal mode As Integer, ByVal secnr As Integer, ByVal nkey As String) As Short End Function \'密码装载到读写模块中 <DllImport("dcrf32.dll")> _ Public Shared Function dc_write(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As Byte()) As Short End Function \'向卡中写入数据 <DllImport("dcrf32.dll")> _ Public Shared Function dc_write(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As String) As Short End Function \'向卡中写入数据 <DllImport("dcrf32.dll")> _ Public Shared Function dc_write_hex(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As String) As Short End Function \'向卡中写入数据(转换为16进制) <DllImport("dcrf32.dll")> _ Public Shared Function dc_read(ByVal icdev As Integer, ByVal adr As Integer, <Out()> ByVal sdata As Byte()) As Short End Function <DllImport("dcrf32.dll")> _ Public Shared Function dc_read(ByVal icdev As Integer, ByVal adr As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal sdata As StringBuilder) As Short End Function \'从卡中读数据 <DllImport("dcrf32.dll")> _ Public Shared Function dc_read_hex(ByVal icdev As Integer, ByVal adr As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal sdata As StringBuilder) As Short End Function \'从卡中读数据(转换为16进制) <DllImport("dcrf32.dll")> _ Public Shared Function a_hex(ByVal oldValue As String, ByRef newValue As String, ByVal len As Int16) As Integer End Function \'普通字符转换成十六进制字符 <DllImport("dcrf32.dll")> _ Public Shared Sub hex_a(ByRef oldValue As String, ByRef newValue As String, ByVal len As Integer) End Sub \'十六进制字符转换成普通字符 #End Region Public Shared Function WriteIn(ByVal str As String) As Boolean Dim _icdev As Int32 = -1 Try If _icdev < 0 Then _icdev = dc_init(100, 115200) End If Dim st As Integer \'1.初始化 If _icdev > 0 Then Else dc_exit(_icdev) Return False End If \'蜂鸣 st = dc_beep(_icdev, 10) If st = 0 Then Else dc_exit(_icdev) Return False End If Dim icCardNo As ULong = 0 Dim tt As Char = ChrW(0) Dim ss As UInteger = 0 st = dc_reset(_icdev, ss) st = dc_card(_icdev, tt, icCardNo) If icCardNo <> 0 Then Else dc_exit(_icdev) Return False End If Dim hexkey As Byte() = New Byte(5) {&HFF, &HFF, &HFF, &HFF, &HFF, &HFF} st = dc_load_key(_icdev, 0, 1, hexkey) \'核对密码 Dim sector As Integer = 1 st = dc_authentication(_icdev, 0, sector) If st = 0 Then Else dc_exit(_icdev) Return False End If Dim address As Integer = 1 Dim data32 As Byte() data32 = New Byte(15) {&H6A, &HC2, &H92, &HFA, &HA1, &H31, _ &H5B, &H4D, &H6A, &HC2, &H92, &HFA, _ &HA1, &H31, &H5B, &H4D} \'= "12345678901234561234567890123456"; Dim data32_hex As String = "".PadLeft(32, " "c) address = sector * 4 + 2 \'写卡操作 data32_hex = str st = dc_write(_icdev, address, data32_hex) If st = 0 Then dc_exit(_icdev) Else dc_exit(_icdev) Return False End If dc_exit(_icdev) Return True Catch dc_exit(_icdev) Return False End Try End Function |
-- 作者:狐狸爸爸 -- 发布时间:2013/4/1 16:35:00 -- Public Shared Function ReadCard(ByVal str As String, ByRef CardNo As String) As Boolean CardNo = "" Dim _icdev As Int32 = -1 Try If _icdev < 0 Then _icdev = dc_init(100, 115200) End If Dim st As Integer \'1.初始化 If _icdev > 0 Then Else dc_exit(_icdev) Return False End If \'蜂鸣 st = dc_beep(_icdev, 10) If st = 0 Then Else dc_exit(_icdev) Return False End If Dim icCardNo As ULong = 0 Dim tt As Char = ChrW(0) Dim ss As UInteger = 0 st = dc_reset(_icdev, ss) st = dc_card(_icdev, tt, icCardNo) If icCardNo <> 0 Then Else dc_exit(_icdev) Return False End If Dim hexkey As Byte() = New Byte(5) {&HFF, &HFF, &HFF, &HFF, &HFF, &HFF} st = dc_load_key(_icdev, 0, 1, hexkey) \'核对密码 Dim sector As Integer = 1 st = dc_authentication(_icdev, 0, sector) If st = 0 Then Else dc_exit(_icdev) Return False End If Dim temp As New StringBuilder(64) Dim temp1 As New StringBuilder(64) Dim address As Integer = 1 Dim data32 As Byte() data32 = New Byte(15) {&H6A, &HC2, &H92, &HFA, &HA1, &H31, _ &H5B, &H4D, &H6A, &HC2, &H92, &HFA, _ &HA1, &H31, &H5B, &H4D} \'= "12345678901234561234567890123456"; Dim data32_hex As String = "".PadLeft(32, " "c) address = sector * 4 + 2 Dim databuff32 As String = String.Empty st = dc_read(_icdev, address, temp1) If st = 0 Then CardNo = temp1.ToString() End If dc_exit(_icdev) Return True Catch dc_exit(_icdev) Return False End Try End Function End Class |
-- 作者:狐狸爸爸 -- 发布时间:2013/4/1 16:36:00 -- 我帮你转换为vb.net的语法,你调整一下。 一个帖子发不下,分成两个了 |