728x90
반응형
<헤더> #ifndef __WS_RFID_LIB__ #define __WS_RFID_LIB__ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <termios.h> #define SPEED B38400 #define SPORT "/dev/ttyS0" #define CRC_POLYNOM 0x8408 #define CRC_PRESET 0xFFFF #define SENDBSIZE 128 #define RECVBSIZE 128 #define INVENT_STD 0x0010 #define INVENT_EP8 0x0020 #define INVENT_E12 0x0040 #define INVENT_UID 0x0080 #define TRTYPE_ICODE_UID 0x8000 #define TRTYPE_ICODE_EPC 0x4000 #define TRTYPE_ICODE_156 0x0800 #define TRTYPE_ICODE_HF 0x0200 #define TRTYPE_ICODE_ICO 0x0100 #define MAXPORT 4 #define MAXONCEREAD 4 #pragma pack(1) typedef struct WS_RFID WS_RFID; typedef struct RFID_MANAGER RFID_MANAGER; typedef struct COMMON COMMON; typedef struct INVEN_COMMON INVEN_COMMON; typedef struct IDD IDD; typedef union INVENT_PTR INVENT_PTR; #pragma pack(4) struct WS_RFID { int iDev; struct termios stOldtio; unsigned char ucaSendTo[SENDBSIZE]; unsigned char ucaRecvFr[RECVBSIZE]; }; /* struct RFID_MANAGER { WS_RFID stCOM; int (port_cal)(int, struct termios *); int (close)(int, struct termios *); int (recv)(int, void *, int); int (send)(int, void *); int (open)(); };*/ struct COMMON { unsigned char ucLen; unsigned char ucComAdr; unsigned char ucCtl; }; struct INVEN_COMMON //Reply Inventory Common { unsigned char ucStatus; //[4] unsigned char ucDataSet; //[5] unsigned char ucTr_Type; //[6] }; struct IDD { unsigned char ucData[12]; //[0]~[11] unsigned short usCrc; //[12][13] unsigned char ucUid[5]; //[14]~[18] }; typedef struct ISO15693_reader_control_Baud_Rate_Detect { COMMON stCOM; unsigned char ucOpt; unsigned short usCrc; }baud_detect; typedef struct ISO15693_host_command_req_inven { COMMON stCOM; unsigned char ucOpt; unsigned char ucMode; unsigned short usCrc; }req_inven; typedef struct ISO15693_host_command_reply_inven_standard { COMMON stCOM; //[1]~[3] INVEN_COMMON stICOM; //[4]~[6] unsigned char ucDSFID; //[7] unsigned char ucUID[8]; //[8]~[15] //8Bytes unsigned short usCrc; //[16][17] }reply_inven_std; typedef struct ISO15693_host_command_reply_inven_icode_epc8 { COMMON stCOM; //[1]~[3] INVEN_COMMON stICOM; //[4]~[6] unsigned char ucEPC[8]; //[7]~[14] //8Bytes unsigned short usCrc; //[15][16] }reply_inven_icode_epc8; typedef struct ISO15693_host_command_reply_inven_icode_epc12 { COMMON stCOM; //[1]~[3] INVEN_COMMON stICOM; //[4]~[6] unsigned char ucEPC[12]; //[7]~[18] //12Bytes unsigned short usCrc; //[19][20] }reply_inven_icode_epc12; typedef struct ISO15693_host_command_reply_inven_icode_uid { COMMON stCOM; //[1]~[3] INVEN_COMMON stICOM; //[4]~[6] IDD stIDD; //[7]~[25] //19Bytes unsigned short usCrc; //[26][27] }reply_inven_icode_uid; union INVENT_PTR { reply_inven_std *stSTD; reply_inven_icode_epc8 *stEPC8; reply_inven_icode_epc12 *stEPC12; reply_inven_icode_uid *stUID; }; unsigned short RFID_CRC(void *); #endif // __WS_RFID_LIB__ |
<코드 설정>
0D 00 71 00 30 00 00 00 0A 00 00 46 41
38400
8bit
짝수패리티
정지비트 1
흐름제어 없음
<메인> #include "WS_RFID_LIB.h" unsigned short RFID_CRC16(void * vpData, unsigned int uiLen); unsigned char ucaBeep[] = {0x0d, 0x00, 0x71, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x46, 0x41}; int main1(void) { unsigned short usCRC = RFID_CRC16(ucaBeep, ucaBeep[0] - 2); printf(" [ %x ] \n" ,usCRC); return 0; } int main(void) { char cBuff[255]; int iDev = 0; int iRet = 0; struct termios stOldState; struct termios stNewState; iDev = open(SPORT,O_RDWR | O_NOCTTY); if( 0 > iDev) { perror(SPORT); exit(-100); } tcgetattr(iDev, &stOldState); bzero(&stNewState,sizeof(stNewState)); stNewState.c_cflag = SPEED|CRTSCTS|CS8|CLOCAL|PARENB; stNewState.c_cflag = IGNPAR|ICRNL; stNewState.c_cflag = 0; stNewState.c_cflag = 0; bzero(stNewState.c_cc,NCCS); stNewState.c_cc[VTIME]= 0; stNewState.c_cc[VMIN] = 1; tcflush(iDev,TCIFLUSH); tcsetattr(iDev,TCIFLUSH,&stOldState); //iRet = read(iDev,cBuff,255); //cBuff[iRet] = 0; //printf(" [%s] : [%d]\n",cBuff,iRet); getchar(); iRet = write(iDev , ucaBeep , ucaBeep[0]); ucaBeep[iRet] = 0; tcsetattr(iDev,TCSANOW,&stOldState); close(iDev); } unsigned short RFID_CRC16(void * vpData, unsigned int uiLen) { unsigned short crc = CRC_PRESET; unsigned int i; unsigned int j; unsigned char * DATA = vpData; 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; } |
컴포트 2개만들어서 버추얼시리얼 + 컴포트 마스터 = 데이터 확인 할수있음.
COM1은 윈도우 COM1과 동일시한다.파일이다.
728x90
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
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 |
20151209_박서연_일일업무보고서_RFID(2) (6) | 2015.12.10 |
20151209 김태현 개인업무일지 RFID 도스 시리얼 (5) | 2015.12.10 |
2015.12.09_Dos Serial RFID_이량경 (5) | 2015.12.10 |
20151209 임현수 업무일지 RFID 도스 시리얼 (5) | 2015.12.10 |