728x90
반응형
#include <Windows.h>
#include <stdio.h>
#define CRC_POLYNOM 0x8408
#define CRC_PRESET 0xFFFF
unsigned short CRC16(void *, unsigned int);
int main()
{
int iCnt;
u_char caString[255] =
{
0x05, 0x00, 0x65,
0x00, 0x3F,
0x00, 0x20,
0x00, 0x0A,
0x00, 0x00,
};
DWORD dwCnt;
DCB sPState;
HANDLE hComm = CreateFile("COM7", GENERIC_READ | GENERIC_WRITE,
0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (INVALID_HANDLE_VALUE == hComm)
{
printf("포트 열 수 없음\n");
return 0;
}
if (0 == SetupComm(hComm, 4096, 4096))
{
printf("버퍼 설정 에러\n");
CloseHandle(hComm);
return 0;
}
if (0 == PurgeComm(hComm, PURGE_TXABORT | PURGE_TXCLEAR))
{
printf("버퍼 초기화 에러\n");
CloseHandle(hComm);
return 0;
}
sPState.DCBlength = sizeof(sPState);
if (0 == GetCommState(hComm, &sPState))
{
printf("시리얼 상태 읽기 에러\n");
CloseHandle(hComm);
return 0;
}
sPState.BaudRate = CBR_38400;
sPState.ByteSize = 8;
sPState.Parity = EVENPARITY;
sPState.StopBits = ONESTOPBIT;
if (0 == SetCommState(hComm, &sPState))
{
printf("시리얼 상태 설정 에러\n");
CloseHandle(hComm);
return 0;
}
*((unsigned short *)(caString + caString[0] - 2)) = CRC16(caString, (caString[0] - 2));
WriteFile(hComm, caString, caString[0], &dwCnt, 0);
ReadFile(hComm, caString, 1, &dwCnt, 0);
ReadFile(hComm, caString + 1, (caString[0] - 1), &dwCnt, 0);
for (iCnt = 0; iCnt<caString[0]; ++iCnt)
{
printf("0x%02X, ", caString[iCnt]);
}
putchar('\n');
printf("SW-REV : %02X%02X\n", caString[4], caString[5]);
printf("D-REV : %02X\n", caString[6]);
printf("HW-Type : %02X\n", caString[7]);
printf("SW-Type : ");
switch (caString[8])
{
case 30:
printf("ID ISC.M01\n");
break;
case 31:
printf("ID ISC.M02\n");
break;
case 71:
printf("ID ISC.PRH100–U (USB-Version)\n");
break;
case 72:
printf("ID ISC.PRH100\n");
break;
case 73:
printf("ID ISC.MR100–U (USB-Version)\n");
break;
case 74:
printf("ID ISC.MR100 / .PR100\n");
break;
case 75:
printf("ID ISC.MR200-A / -E\n");
break;
case 40:
printf("ID ISC.LR100\n");
break;
case 41:
printf("ID ISC.LR200\n");
break;
case 91:
printf("ID ISC.LRU1000\n");
break;
case 80:
printf("ID CPR.M02\n");
break;
case 81:
printf("ID CPR.02\n");
break;
case 84:
printf("ID CPR.M03 (586/#)\n");
break;
}
printf("TR-Type : ");
if (caString[10] & 0x80)
{
printf("I-Code UID, ");
}
if (caString[10] & 0x40)
{
printf("I-Code EPC, ");
}
if (caString[10] & 0x08)
{
printf("ISO 15693, ");
}
if (caString[10] & 0x02)
{
printf("Tag-it HF, ");
}
if (caString[10] & 0x01)
{
printf("I-Code 1, ");
}
//printf("수신한 바이트는 [%d]입니다.\n", (dwCnt+1));
CloseHandle(hComm);
return 0;
}
unsigned short CRC16(void *vpData, unsigned int uiLen)
{
unsigned int i;
unsigned int j;
unsigned char *DATA = vpData;
unsigned short crc = CRC_PRESET;
for (i = 0; i < uiLen; i++)
{
crc ^= DATA[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x0001)
{
crc = (crc » 1) ^ CRC_POLYNOM;
}
else
{
crc = (crc » 1);
}
}
}
return crc;
}
아직 리더기를 못받아서 기다리는 중입니다
728x90
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
2015-12-10 Dos RFID 개인 업무일지 - 천정호 (3) | 2015.12.10 |
---|---|
20151210 수업 / RFID_3-남수진 (3) | 2015.12.10 |
20151210-김재홍-Serial_4일차-RFID_도스 (2) | 2015.12.10 |
20151210-엄민웅 5챕터. Protocols for Reader Control ~ 6챕터. Protocols for ISO15693 Host Commands (3) | 2015.12.10 |
20151209 22번 우대희 일일업무일지 (3) | 2015.12.10 |
20151209_박서연_일일업무보고서_RFID(2) (6) | 2015.12.10 |
20151209 김태현 개인업무일지 RFID 도스 시리얼 (5) | 2015.12.10 |
2015.12.09_Dos Serial RFID_이량경 (5) | 2015.12.10 |