请问谁有ISO/IEC 14443 标准中定义的 CRC-B 校验的VB的源码

pqs1114_163 2017-04-14 12:11:21
我想向高通芯片的手机 写入一个HEX数据,通过“串监控”发现PC向手机写入了这个了指令27 97 07 56 34 12 10 00 00 A1 00 00 CC 9D 7E ,通过对比,“27 97 07 56 34 12 10 00 00 A1 00 00” CC 9D ”应该是这个的效验码,“7E”是固定的。这是IEC 14443 标准中定义的 CRC-B校验方式,请问谁有VB或VB.NET的源码,或者告诉我怎么在VB.NET调用DLL,在VB调用我有,但是VB.NET用这个调用提示:“crc_16”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。”
VB调用源码是这样的
Option Explicit
Private Declare Function crc_16 Lib "crc16.dll" (ByVal mode As Byte, ByRef data As Byte, ByVal length As Long) As Integer
Dim crc As Integer
Dim data() As Byte
Private Sub Command1_Click()
Dim n As Long, i As Long, m As Byte
n = Len(Text1) \ 2
ReDim data(n - 1)
For i = 0 To n - 1
data(i) = Val("&H" & Mid(Text1, i * 2 + 1, 2))
Next i
crc = crc_16(2, data(0), n)
Label1 = Right("000" & Hex(crc), 4)
End Sub

我在VB.net怎么调用?
...全文
1413 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
泡泡龙 2017-05-22
  • 打赏
  • 举报
回复
估计是vb.net里面dllimport参数写错了
赵4老师 2017-04-14
  • 打赏
  • 举报
回复
仅供参考:
/***** crc16.c *****/
#include <stdio.h>

#define CRC16_DNP   0x3D65u     // DNP, IEC 870, M-BUS, wM-BUS, ...
#define CRC16_CCITT 0x1021u     // X.25, V.41, HDLC FCS, Bluetooth, ...

//Other polynoms not tested
#define CRC16_IBM   0x8005u     // ModBus, USB, Bisync, CRC-16, CRC-16-ANSI, ...
#define CRC16_T10_DIF   0x8BB7u     // SCSI DIF
#define CRC16_DECT  0x0589u     // Cordeless Telephones
#define CRC16_ARINC 0xA02Bu     // ACARS Aplications

#define POLYNOM     CRC16_DNP   // Define the used polynom from one of the aboves

// Calculates the new crc16 with the newByte. Variable crcValue is the actual or initial value (0).
unsigned short crc16(unsigned short crcValue, unsigned char newByte) {
    int i;

    for (i = 0; i < 8; i++) {
        if (((crcValue & 0x8000u) >> 8) ^ (newByte & 0x80u)){
            crcValue = (crcValue << 1)  ^ POLYNOM;
        } else {
            crcValue = (crcValue << 1);
        }
        newByte <<= 1;
    }
    return crcValue;
}

unsigned short exampleOfUseCRC16(unsigned char *Data, int len){

    unsigned short crc;
    int aux = 0;

    crc = 0x0000u; //Initialization of crc to 0x0000 for DNP
    //crc = 0xFFFFu; //Initialization of crc to 0xFFFF for CCITT

    while (aux < len){
        crc = crc16(crc,Data[aux]);
        aux++;
    }

    return (~crc); //The crc value for DNP it is obtained by NOT operation

    //return crc; //The crc value for CCITT
}

int main() {
    unsigned char d[10]={0,1,2,3,4,5,6,7,8,9};

    printf("0x%04hX\n",exampleOfUseCRC16(d,10));//0x1078
    return 0;
}
Tiger_Zhao 2017-04-14
  • 打赏
  • 举报
回复
把VB.Net的代码也贴出来。
又:用编辑框上工具条的代码格式。
舉杯邀明月 2017-04-14
  • 打赏
  • 举报
回复
你在VB.NET是“导入函数”时,是不是应该给它指明是“StdCall”的?

863

社区成员

发帖
与我相关
我的任务
社区描述
VB COM/DCOM/COM+
c++ 技术论坛(原bbs)
社区管理员
  • COM/DCOM/COM+社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧