이 코드는 RFID 모듈 (EM-18)에서 데이터를 읽는데 큰 문제가 있습니다. 내 응용 프로그램이 실행 중이고 em 모듈에서 RFID 카드를 전달할 때 두 부분에서 데이터를 읽었습니다. 먼저 8 바이트의 카드 ID를 읽고 4 바이트를 보냅니다. 이렇게 :
[root@FriendlyARM /fgit]# ./RFIDMonitor -qws
enter the port name:
ttySAC3
open_port: succesfully open port
open_port: succesfully open port
RFID MONITORING => '010B7528'
RFID MONITORING => '297E'
RFID MONITORING => '010B7528'
RFID MONITORING => '297E'
나는 변화 VMIN
하고 VTime
있지만 그 결과는 변경되지 않았다.
이것은 내 코드입니다.
if(!fork())
{
while(1)
{
memset(buf2,'\0',MAXDATASIZE);
//------------------------------------------------
if ((numbytes = read(fd,buf2, MAXDATASIZE-1)) != -1)
{
buf2[numbytes] = '\0';
printf("RFID MONITORING => '%s'\n",buf2);
}
}
}
이것은 내 구성입니다.
int openport(void)
{
cout<<"enter the port name:\n";
string portname="";
cin>>portname;
portname="/dev/"+portname;
fd=open(portname.c_str(),O_RDWR|O_NOCTTY|O_NDELAY);
if (fd==-1)
{
//printf("open_port: unable to open port \n");
return -1;
}
else
{
//printf("open_port: succesfully open port \n");
fcntl(fd,F_SETFL,0);
return 1;
}
}
//-------------------------------------
void closeport(void)
{
close(fd);
}
//-------------------------------------
void configport(void)
{
struct termios tty;
struct termios tty_old;
memset (&tty, 0, sizeof tty);
/* Error Handling */
if ( tcgetattr ( fd, &tty ) != 0 ) {
std::cout << "Error " << errno << " from tcgetattr: " << strerror(errno) << std::endl;
}
/* Save old tty parameters */
tty_old = tty;
/* Set Baud Rate */
cfsetospeed (&tty, (speed_t)B9600);
cfsetispeed (&tty, (speed_t)B9600);
/* Setting other Port Stuff */
tty.c_cflag &= ~PARENB; // Make 8n1
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8;
tty.c_cflag &= ~CRTSCTS; // no flow control
tty.c_cc[VMIN] =1;// change to 0 and 5
tty.c_cc[VTIME] = 10;// change to 0 and 5
tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
/* Make raw */
cfmakeraw(&tty);
/* Flush Port, then applies attributes */
tcflush( fd, TCIFLUSH );
if ( tcsetattr ( fd, TCSANOW, &tty ) != 0) {
std::cout << "Error " << errno << " from tcsetattr" << std::endl;
}
}
이렇게 표시하고 싶습니다 (모든 데이터가 한 부분에 있음)
RFID MONITORING => '010B7528297E
나는 문제를 해결한다 (그냥 1 초 수면으로 추가)
int numbytes;
char buf2[MAXDATASIZE];
//*****************************
// SerialCodes
//*****************************]
fd=-1;
while(fd==-1)
{
int a=openport();
if(a==1)
{
pid_t pid;
if((pid=fork()))
{
qDebug()<<("%d",pid);
while(1)
{
//------------------------------------------------
if ((numbytes = read(fd,buf2, MAXDATASIZE-1)) == -1)
{
//qDebug()<<("Error in reading data");
}
else
{
buf2[numbytes] = '\0';
usleep(10000);
QString s1(buf2);
memset(buf2,'\0',MAXDATASIZE);
read(fd,buf2, MAXDATASIZE-1) ;
QString s2(buf2);
memset(buf2,'\0',MAXDATASIZE);
qDebug()<<("RFID MONITORING => '%s'\n",s1+s2);
kill(pid,SIGTERM);
break;
}
}
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다