Corrected small bug in GetCommState16. Parity check can be disabled

even when a parity bit is used. SetCommState16() can override baudrate
setting in wine.conf.
This commit is contained in:
Rein Klazes 1999-03-23 13:44:51 +00:00 committed by Alexandre Julliard
parent 0092390cd6
commit 58a38b89d9
1 changed files with 53 additions and 43 deletions

View File

@ -364,6 +364,16 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
COM[port].eventmask = 0; COM[port].eventmask = 0;
/* save terminal state */ /* save terminal state */
tcgetattr(fd,&m_stat[port]); tcgetattr(fd,&m_stat[port]);
/* set default parameters */
if(COM[port].baudrate>-1){
DCB16 dcb;
GetCommState16(port, &dcb);
dcb.BaudRate=COM[port].baudrate;
/* more defaults:
* databits, parity, stopbits
*/
SetCommState16( &dcb);
}
#if 0 #if 0
/* allocate buffers */ /* allocate buffers */
/* ... */ /* ... */
@ -738,8 +748,6 @@ INT16 WINAPI SetCommState16(LPDCB16 lpdcb)
port.c_lflag &= ~(ICANON|ECHO|ISIG); port.c_lflag &= ~(ICANON|ECHO|ISIG);
port.c_lflag |= NOFLSH; port.c_lflag |= NOFLSH;
if (ptr->baudrate > 0)
lpdcb->BaudRate = ptr->baudrate;
TRACE(comm,"baudrate %d\n",lpdcb->BaudRate); TRACE(comm,"baudrate %d\n",lpdcb->BaudRate);
#ifdef CBAUD #ifdef CBAUD
port.c_cflag &= ~CBAUD; port.c_cflag &= ~CBAUD;
@ -858,25 +866,25 @@ INT16 WINAPI SetCommState16(LPDCB16 lpdcb)
return -1; return -1;
} }
TRACE(comm,"parity %d\n",lpdcb->Parity); TRACE(comm,"fParity %d Parity %d\n",lpdcb->fParity, lpdcb->Parity);
port.c_cflag &= ~(PARENB | PARODD); port.c_cflag &= ~(PARENB | PARODD);
if (lpdcb->fParity) if (lpdcb->fParity)
switch (lpdcb->Parity) { port.c_iflag |= INPCK;
case NOPARITY: else
port.c_iflag &= ~INPCK; port.c_iflag &= ~INPCK;
break; switch (lpdcb->Parity) {
case ODDPARITY: case NOPARITY:
port.c_cflag |= (PARENB | PARODD); break;
port.c_iflag |= INPCK; case ODDPARITY:
break; port.c_cflag |= (PARENB | PARODD);
case EVENPARITY: break;
port.c_cflag |= PARENB; case EVENPARITY:
port.c_iflag |= INPCK; port.c_cflag |= PARENB;
break; break;
default: default:
ptr->commerror = IE_BYTESIZE; ptr->commerror = IE_BYTESIZE;
return -1; return -1;
} }
TRACE(comm,"stopbits %d\n",lpdcb->StopBits); TRACE(comm,"stopbits %d\n",lpdcb->StopBits);
@ -927,7 +935,7 @@ INT16 WINAPI GetCommState16(INT16 cid, LPDCB16 lpdcb)
struct termios port; struct termios port;
TRACE(comm,"cid %d, ptr %p\n", cid, lpdcb); TRACE(comm,"cid %d, ptr %p\n", cid, lpdcb);
if ((ptr = GetDeviceStruct(lpdcb->Id)) == NULL) { if ((ptr = GetDeviceStruct(cid)) == NULL) {
return -1; return -1;
} }
if (tcgetattr(ptr->fd, &port) == -1) { if (tcgetattr(ptr->fd, &port) == -1) {
@ -995,17 +1003,18 @@ INT16 WINAPI GetCommState16(INT16 cid, LPDCB16 lpdcb)
break; break;
} }
if(port.c_iflag & INPCK)
lpdcb->fParity = TRUE;
else
lpdcb->fParity = FALSE;
switch (port.c_cflag & (PARENB | PARODD)) { switch (port.c_cflag & (PARENB | PARODD)) {
case 0: case 0:
lpdcb->fParity = FALSE;
lpdcb->Parity = NOPARITY; lpdcb->Parity = NOPARITY;
break; break;
case PARENB: case PARENB:
lpdcb->fParity = TRUE;
lpdcb->Parity = EVENPARITY; lpdcb->Parity = EVENPARITY;
break; break;
case (PARENB | PARODD): case (PARENB | PARODD):
lpdcb->fParity = TRUE;
lpdcb->Parity = ODDPARITY; lpdcb->Parity = ODDPARITY;
break; break;
} }
@ -1768,25 +1777,25 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
return FALSE; return FALSE;
} }
TRACE(comm,"parity %d\n",lpdcb->Parity); TRACE(comm,"fParity %d Parity %d\n",lpdcb->fParity, lpdcb->Parity);
port.c_cflag &= ~(PARENB | PARODD); port.c_cflag &= ~(PARENB | PARODD);
if (lpdcb->fParity) if (lpdcb->fParity)
switch (lpdcb->Parity) { port.c_iflag |= INPCK;
case NOPARITY: else
port.c_iflag &= ~INPCK; port.c_iflag &= ~INPCK;
break; switch (lpdcb->Parity) {
case ODDPARITY: case NOPARITY:
port.c_cflag |= (PARENB | PARODD); break;
port.c_iflag |= INPCK; case ODDPARITY:
break; port.c_cflag |= (PARENB | PARODD);
case EVENPARITY: break;
port.c_cflag |= PARENB; case EVENPARITY:
port.c_iflag |= INPCK; port.c_cflag |= PARENB;
break; break;
default: default:
commerror = IE_BYTESIZE; commerror = IE_BYTESIZE;
return FALSE; return FALSE;
} }
TRACE(comm,"stopbits %d\n",lpdcb->StopBits); TRACE(comm,"stopbits %d\n",lpdcb->StopBits);
@ -1902,17 +1911,18 @@ BOOL WINAPI GetCommState(INT handle, LPDCB lpdcb)
break; break;
} }
if(port.c_iflag & INPCK)
lpdcb->fParity = TRUE;
else
lpdcb->fParity = FALSE;
switch (port.c_cflag & (PARENB | PARODD)) { switch (port.c_cflag & (PARENB | PARODD)) {
case 0: case 0:
lpdcb->fParity = FALSE;
lpdcb->Parity = NOPARITY; lpdcb->Parity = NOPARITY;
break; break;
case PARENB: case PARENB:
lpdcb->fParity = TRUE;
lpdcb->Parity = EVENPARITY; lpdcb->Parity = EVENPARITY;
break; break;
case (PARENB | PARODD): case (PARENB | PARODD):
lpdcb->fParity = TRUE;
lpdcb->Parity = ODDPARITY; lpdcb->Parity = ODDPARITY;
break; break;
} }