A continuación coloco algunos ejemplos de trama:
05 00 01 FB ( F2 3D) los últimos dos seria el checksum
04 00 01 (DB 4B)
esos ejemplos están en el manual y probando el lector con esos comandos funciona perfectamente el problema es que hay otros comandos a los cuales habría que agregarle el checksum y no se como obtenerlo.
Buscando encontré a alguien que había hecho algo parecido pero en C# y la verdad no estoy muy familiarizado con C# [URL="http://stackoverflow.com/questions/30496223/c-sharp-crc-16-ccitt-0x8408-polynomial-help-needed"]http://stackoverflow.com/questions/30496223/c-sharp-crc-16-ccitt-0x8408-polynomial-help-needed[/URL]
Código:
private ushort CCITT_CRC16(string strInput) { ushort data; ushort crc = 0xFFFF; byte[] bytes = GetBytesFromHexString(strInput); for (int j = 0; j < bytes.Length; j++) { crc = (ushort)(crc ^ bytes[j]); for (int i = 0; i < 8; i++) { if ((crc & 0x0001) == 1) crc = (ushort)((crc >> 1) ^ 0x8408); else crc >>= 1; } } crc = (ushort)~crc; data = crc; crc = (ushort)((crc << 8) ^ (data >> 8 & 0xFF)); return crc; }
he intentado realizar una traducción a VB
Código:
Private Sub crc16calc_Click(sender As Object, e As EventArgs) Handles crc16calc.Click Dim data As UShort = 0 Dim crc As UShort = &HFFFF Dim pru() As Byte = {&H5, &H0, &H4, &HFB, &H4A, &H43} For j As UInteger = 0 To j < pru.Length crc = CUShort(crc ^ pru(j)) For i As UInteger = 0 To i < 8 If ((crc & &H1) = 1) Then crc = CUShort((crc >> 1) ^ &H8408) Else crc >>= 1 End If Next Next crc = CUShort(Not crc) data = crc crc = CUShort((crc << 8) ^ (data >> 8 & &HFF)) MsgBox(crc) End Sub
sin embargo el primer error es un desbordamiento (La operación aritmética ha provocado un desbordamiento.) en "crc = CUShort(crc ^ pru(j))". Agradecería su ayuda.