Dos_RFID.c
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#pragma comment(lib, "Ws2_32.lib")
#define CRC_PRESET 0xFFFF
#define CRC_POLYNOM 0x8408
unsigned short RFID_CRC(void *, unsigned int);
int main() {
// u_char caString[255] = { 0x0D, 0x00, 0x71, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00 };
u_char caString[255] = { 0x07, 0x00, 0xB0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00 };
// RX-BUF 추출
// u_char caString[255] = { 0x05, 0x00, 0x66, 0x00 };
u_char caData[100] = { 0, };
DCB sPState;
DWORD dwCount;
unsigned int uiCount;
HANDLE hComm
= CreateFile("COM6",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hComm == INVALID_HANDLE_VALUE) {
printf("Port Open Error\n");
return 0;
}
if (SetupComm(hComm, 4096, 4096) == 0) {
printf("Buffer Setting Error\n");
CloseHandle(hComm);
return 0;
}
if (PurgeComm(hComm, PURGE_TXABORT | PURGE_TXCLEAR) == 0) {
printf("Buffer Error");
CloseHandle(hComm);
return 0;
}
sPState.DCBlength = sizeof(sPState);
// sPState에 기존의 내용을 읽어온다.
if (GetCommState(hComm, &sPState) == 0) {
printf("Serial Read Error\n");
CloseHandle(hComm);
return 0;
}
// 필요한 부분만 수정
sPState.BaudRate = CBR_38400;
sPState.ByteSize = 8;
sPState.Parity = EVENPARITY;
sPState.StopBits = ONESTOPBIT;
// 필요한 부분을 수정하였으면 설정을 한다.
if (SetCommState(hComm, &sPState) == 0) {
printf("Serial State Setting Error\n");
CloseHandle(hComm);
return 0;
}
// 46 41을 넣는 방식
*((unsigned short *)(caString + caString[0] - 2)) = RFID_CRC(caString, caString[0] - 2);
WriteFile(hComm, caString, caString[0], &dwCount, 0);
// 세 번째 인자는 읽을 크기를 적는다.
ReadFile(hComm, caString, 1, &dwCount, 0);
ReadFile(hComm, caString + 1, caString[0] - 1, &dwCount, 0);
/*
if (WriteFile(hComm, caString, caString[0], &dwWritten, 0) == 0) {
printf("Write Error\n");
}
else {
printf("Write Success\n");
}
*/
system("cls");
if (caString[0] > 6) {
printf("[ Card UID ]\n");
}
else {
printf("[ No Card ]\n");
}
for (uiCount = 0; uiCount < caString[0]; uiCount++) {
printf("[0x%02X] ", caString[uiCount]);
}
printf("\n");
/*
printf("SW-REV : %d %d\n", caString[4], caString[5]);
printf("D-REV : %d\n", caString[6]);
printf("HW-Type : %d\n", caString[7]);
switch (caString[8]) {
case 30:
strcpy(caData, "ID ISC.M01");
break;
case 31:
strcpy(caData, "ID ISC.M02");
break;
case 71:
strcpy(caData, "ID ISC.PRH100-U (USB-Version)");
break;
case 72:
strcpy(caData, "ID ISC.PRH100");
break;
case 73:
strcpy(caData, "ID ISC.MR100-U (USB-Version)");
break;
case 74:
strcpy(caData, "ID ISC.MR100 / .PR100");
break;
case 75:
strcpy(caData, "ID ISC.MR200-A / -E");
break;
case 40:
strcpy(caData, "ID ISC.LR100");
break;
case 41:
strcpy(caData, "ID ISC.LR200");
break;
case 91:
strcpy(caData, "ID ISC.LRU1000");
break;
case 80:
strcpy(caData, "ID CPR.M02");
break;
case 81:
strcpy(caData, "ID CPR.02");
break;
case 84:
strcpy(caData, "ID CPR.M03 (586/#)");
break;
default:
strcpy(caData, "Data Error");
break;
}
printf("SW-TYPE : [ %s ]\n", caData);
memset(caData, 0, sizeof(caData));
if ((caString[10] & 0x80) == 1) {
strcpy(caData, "I-Code-UID");
}
if ((caString[10] & 0x40) == 1) {
strcpy(caData, "I-Code-EPC");
}
if ((caString[10] & 0x08) == 1) {
strcpy(caData, "ISO 15693");
}
if ((caString[10] & 0x02) == 1) {
strcpy(caData, "Tag-IT HF");
}
if ((caString[10] & 0x01) == 1) {
strcpy(caData, "I-Code 1");
}
printf("TR-TYPE : [ %s ]\n", caData);
*/
CloseHandle(hComm);
return 0;
}
unsigned short RFID_CRC(void *vpData, unsigned int uiLen) {
int i, 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;
}
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
2015.12.10_시리얼 포로토콜#3_이량경 (2) | 2015.12.11 |
---|---|
20151210 임현수 업무일지 RFID 도스 시리얼 실습 (2) | 2015.12.11 |
20151210_[안향진]_RFID_3 (3) | 2015.12.11 |
20151210 - 홍준모 RFID 시리얼 통신 Dos 용 마무리, 내일 window 용 할 것 (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 |
20151210 22번 우대희 업무일지 (3) | 2015.12.10 |