/***Serial통신_4일차-RFID_도스용시리얼통신프로그램***/
#include <windows.h>
#include <stdio.h>
#define CRC_PRESET 0xFFFF
#define CRC_POLYNOM 0x8408
#define I_Code_1 0
#define Tag_it_HF 1
#define ISO_15693 3
#define I_Code_EPC 6
#define I_Code_UID 7
unsigned short CRC16(void *, unsigned int);
int main()
{
u_char caString[255] = {
0X05, 0X00, 0X65, 0X00,
0X30, 0X00, 0X00, 0X00,
0X0A, 0X00, 0X00 /*0X46, 0X41*/ };
DWORD dwCount;
DCB sPState;
int iCnt;
int sw_Type;
// RFID_STRU *rfidInfo;
// unsigned int crc = CRC_PRESET;
HANDLE hComm
= CreateFile(TEXT("COM3")
, 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], &dwCount, 0);
// ReadFile(hComm, caString, 1, &dwCount, 0);
// ReadFile(hComm, caString + 1, caString[0]-1, &dwCount, 0);
// for(iCnt = 0; iCnt<caString[0]; ++iCnt)
{
ReadFile(hComm, caString, 1, &dwCount, 0);
ReadFile(hComm, caString + 1, caString[0] - 1, &dwCount, 0);
// printf("0x%02x, ", iCnt, caString[iCnt]);
}
if (0 != caString[3]) /* STATUS가 0이 아니면 (error) */
{
printf("Geting Software Version is Fail!\n");
}
else
{
printf("Firmware REV.: %02X%02X \n", caString[4], caString[5]);
printf("D-REV: %02X \n", caString[6]);
printf("H/W Type: %02X \n", caString[7]);
// printf("S/W Type: %02X", caString[8]);
sw_Type = (int)caString[8];
switch (sw_Type)
{
case 30:
printf("S/W TYPE: ID ISC.M01 \n");
break;
case 31:
printf("S/W TYPE: ID ISC.M02 \n");
break;
case 71:
printf("S/W TYPE: ID ISC.PRH100?U (USB-Version) \n");
break;
case 72:
printf("S/W TYPE: ID ISC.PRH100 \n");
break;
case 73:
printf("S/W TYPE: ID ISC.MR100?U (USB-Version) \n");
break;
case 74:
printf("S/W TYPE: ID ISC.MR100/.PR100 \n");
case 75:
printf("S/W TYPE: ID ISC.MR200-A/-E \n");
break;
case 40:
printf("S/W TYPE: ID ISC.LR100 \n");
break;
case 41:
printf("S/W TYPE: ID ISC.LR200 \n");
case 91:
printf("S/W TYPE: ID ISC.LRU1000 \n");
break;
case 80:
printf("S/W TYPE: ID CPR.M02 \n");
break;
case 81:
printf("S/W TYPE: ID CPR.02 \n");
break;
case 84:
printf("S/W TYPE: ID CPR.M03 (586/#) \n");
break;
default:
printf("\n\n");
break;
}
printf("\nTransponder Type\n");
printf("\tI-Code 1 : [%s]\n", (caString[10] & I_Code_1) ? "Yes" : "No");
printf("\tTag-it HF : [%s]\n", (caString[10] & Tag_it_HF) ? "Yes" : "No");
printf("\tISO 15693 : [%s]\n", (caString[10] & ISO_15693) ? "Yes" : "No");
printf("\tI-Code EPC : [%s]\n", (caString[10] & I_Code_EPC) ? "Yes" : "No");
printf("\tI_Code_UID : [%s]\n", (caString[10] & I_Code_UID) ? "Yes" : "No");
}
getchar();
CloseHandle(hComm);
return 0;
}
unsigned short CRC16(void *vpData, unsigned int uiLen)
{
unsigned short crc = CRC_PRESET;
unsigned int i, j;
unsigned char *DATA = vpData;
for (i = 0; i < uiLen; i++) /* cnt = number of protocol bytes without CRC */
{
crc ^= DATA[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x0001)
{
crc = (crc >> 1) ^ CRC_POLYNOM;
}
else
{
crc = (crc >> 1);
}
}
}
return crc;
}
#include <windows.h>
#include <stdio.h>
#define CRC_PRESET 0xFFFF
#define CRC_POLYNOM 0x8408
#define I_Code_1 0
#define Tag_it_HF 1
#define ISO_15693 3
#define I_Code_EPC 6
#define I_Code_UID 7
unsigned short CRC16(void *, unsigned int);
int main()
{
u_char caString[255] = {
0X07, 0X00, 0XB0, 0X01,
0X00, 0X00, 0X00, 0X00,
0X0A, 0X00, 0X00 /*0X46, 0X41*/ };
DWORD dwCount;
DCB sPState;
int iCnt;
int sw_Type;
// RFID_STRU *rfidInfo;
// unsigned int crc = CRC_PRESET;
HANDLE hComm
= CreateFile(TEXT("COM3")
, 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], &dwCount, 0);
// ReadFile(hComm, caString, 1, &dwCount, 0);
// ReadFile(hComm, caString + 1, caString[0]-1, &dwCount, 0);
// for(iCnt = 0; iCnt<caString[0]; ++iCnt)
{
ReadFile(hComm, caString, 1, &dwCount, 0);
ReadFile(hComm, caString + 1, caString[0] - 1, &dwCount, 0);
// printf("0x%02x, ", iCnt, caString[iCnt]);
}
if (0 != caString[3]) /* STATUS가 0이 아니면 (error) */
{
printf("Geting Software Version is Fail!\n");
}
else
{
printf("Firmware REV.: %02X%02X \n", caString[4], caString[5]);
printf("D-REV: %02X \n", caString[6]);
printf("H/W Type: %02X \n", caString[7]);
// printf("S/W Type: %02X", caString[8]);
}
getchar();
CloseHandle(hComm);
return 0;
}
unsigned short CRC16(void *vpData, unsigned int uiLen)
{
unsigned short crc = CRC_PRESET;
unsigned int i, j;
unsigned char *DATA = vpData;
for (i = 0; i < uiLen; i++) /* cnt = number of protocol bytes without CRC */
{
crc ^= DATA[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x0001)
{
crc = (crc >> 1) ^ CRC_POLYNOM;
}
else
{
crc = (crc >> 1);
}
}
}
return crc;
}
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
20151210_[안향진]_RFID_3 (3) | 2015.12.11 |
---|---|
20151210 - 홍준모 RFID 시리얼 통신 Dos 용 마무리, 내일 window 용 할 것 (3) | 2015.12.10 |
2015-12-10 Dos RFID 개인 업무일지 - 천정호 (3) | 2015.12.10 |
20151210 수업 / RFID_3-남수진 (3) | 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 |
20151209 22번 우대희 일일업무일지 (3) | 2015.12.10 |
20151209_박서연_일일업무보고서_RFID(2) (6) | 2015.12.10 |