1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| //ouverture et configuration du port :
handle = open(m_comname.c_str(), O_RDWR | O_NOCTTY);
if (handle < 0) {
return OC_CREATE_HANDLE_ERR;
}
struct termios newtio;
bzero(&newtio, sizeof (newtio));
newtio.c_cflag = m_baudrate | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 1; /*0.1sec timeout between each char*/
newtio.c_cc[VMIN] = 188; /* blocking read until 188 chars received (max length of a reading) or until timeout exceed*/
newtio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
newtio.c_oflag &= ~OPOST;
newtio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
newtio.c_cflag &= ~(CSIZE | PARENB);
newtio.c_cflag |= CS8;
tcflush(handle, TCIOFLUSH);
tcsetattr(handle, TCSANOW, &newtio);
//Lecture ecriture :
tcflush(handle, TCIOFLUSH);
bStatus = write(handle, pSendBuf, sendLength);
if ((bStatus == 0) || (bStatus == -1)) {
return TRANSMIT_ERR_WRITE;
}
bStatus = read(handle, pRecvBuf, 255);
if (bStatus < 0) {
return TRANSMIT_ERR_WRITE;
}
recvLength = bStatus; |
Partager