2012-09-27 2 views
3

시리얼 포트에서 100 보레이트를 읽을 수 있는지 알고 싶습니다. termio.h에 따라 100을 보레이트로 설정하지 않아도됩니다. 나는 리눅스에서 일하고있다. 상대방의 통신 장치가 100 보오 (baud) 속도로 데이터를 전송하고 있으며 고정되어 있습니다. 내 보오율이 110으로 설정되었는지 알고 싶습니다. 수신 한 데이터가 정확하다는 것을 보증합니까? 아니면 이것에 대한 해결책이 있습니까?시리얼 포트를 100 보레이트로 처리하기

친절하게 안내합니다.

+2

하면 다른 쪽 끝은 실제로 110 개 보드에 전송하지 않도록 있습니까? 100 baud는 기본적으로 들리지 않습니다. –

답변

6

당신은 실제로 행운아입니다. 100 보오는 일반 16450 호환 직렬 포트 (모든 것이 거의 무엇인지)를 가진 제수 (1,152)를 계산할 수있을만큼 충분히 낮으며 리눅스 supports custom divisorsspd_cust 매개 변수는 setserial입니다.

+0

감사합니다. 리눅스의 시리얼 속도를 알고 계신가요? 고마워 .. 내가 이것을 확인했다. http://www.connecttech.com/KnowledgeDatabase/kdb309.htm –

+1

포함 된 직렬 포트가있는 거의 모든 PC에는 [16550A 호환 포트 (1.8432MHz 클록 포함)] (http : //www.lammertbies.nl/comm/info/serial-uart.html). 이것은 1,152를위한 정확한 제수를 만듭니다. –

+0

감사합니다. 100 보오까지 커스터마이징에 성공한 것 같습니다. 100 개가 설정되었음을 프로그래밍 방식으로 어떻게 확인할 수 있는지 알려주십시오. cfgetospeed()를 사용하여 매번 15를 출력합니다 (전송 속도 설정과 상관없이). –

0

Hmmm .... 110 bps는 일반적으로 2 개의 정지 비트 (다른 ​​모든 속도는 하나의 정지 비트 사용)가 있으므로 1 문자 전송시 7 비트 데이터에 대해 10 비트가 필요하다는 점에서 직렬 포트 속도 중 고유합니다. 8 비트 데이터의 경우 11 비트.

통신 프로토콜이 십초 당 문자와 ​​하나의 정지 비트 및 8 비트 데이터를 가정하여 보오 CPS를 변환 할 수있는 1950 년대 프로토콜의 무지한 사람으로 전달 된 경우, 100 보드는 결과라고 결론을 내릴 것입니다.

true 100 baud에 대한 사용자 정의 설정이 작동하지 않으면 표준 110 보오드를 설정하십시오.

related answer에서 발췌 :

#include <errno.h> 
#include <termios.h> 
#include <unistd.h> 

int 
set_interface_attribs (int fd, int speed, int parity) 
{ 
     struct termios tty; 
     memset (&tty, 0, sizeof tty); 
     if (tcgetattr (fd, &tty) != 0) 
     { 
       error_message ("error %d from tcgetattr", errno); 
       return -1; 
     } 

     cfsetospeed (&tty, speed); 
     cfsetispeed (&tty, speed); 

     tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;  // 8-bit chars 
     if (speed == B110) 
      tty.c_cflag |= CSTOPB;  // 2 stop bits for 110 

     // disable IGNBRK for mismatched speed tests; otherwise receive break 
     // as \000 chars 
     tty.c_iflag &= ~IGNBRK;   // ignore break signal 
     tty.c_lflag = 0;    // no signaling chars, no echo, 
             // no canonical processing 
     tty.c_oflag = 0;    // no remapping, no delays 
     tty.c_cc[VMIN] = 0;   // read doesn't block 
     tty.c_cc[VTIME] = 5;   // 0.5 seconds read timeout 

     tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl 

     tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, 
             // enable reading 
     tty.c_cflag &= ~(PARENB | PARODD);  // shut off parity 
     tty.c_cflag |= parity; 
     tty.c_cflag &= ~CSTOPB; 
     tty.c_cflag &= ~CRTSCTS; 

     if (tcsetattr (fd, TCSANOW, &tty) != 0) 
     { 
       error_message ("error %d from tcsetattr", errno); 
       return -1; 
     } 
     return 0; 
} 

void 
set_blocking (int fd, int should_block) 
{ 
     struct termios tty; 
     memset (&tty, 0, sizeof tty); 
     if (tcgetattr (fd, &tty) != 0) 
     { 
       error_message ("error %d from tggetattr", errno); 
       return; 
     } 

     tty.c_cc[VMIN] = should_block ? 1 : 0; 
     tty.c_cc[VTIME] = 5;   // 0.5 seconds read timeout 

     if (tcsetattr (fd, TCSANOW, &tty) != 0) 
       error_message ("error %d setting term attributes", errno); 
} 


... 
char *portname = "/dev/ttyUSB1" 
... 
int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); 
if (fd < 0) 
{ 
     error_message ("error %d opening %s: %s", errno, portname, strerror (errno)); 
     return; 
} 

set_interface_attribs (fd, B110, 0); // set speed to 115,200 bps, 8n2 (no parity) 
관련 문제