Article View: borland.public.cppbuilder.nativeapi
Article #6187Please help, Parity does Not Working Again........
From: Ramy
Date: Wed, 01 Jun 2005 16:05
Date: Wed, 01 Jun 2005 16:05
145 lines
8281 bytes
8281 bytes
Hi, i don't know what's happened but suddenly it's stoped working,
few hours ago i checked it and it wokred just fine, the parity
flag 'fParity' was '1' ( = Enabled ) and i saw on the scope
device the parity bit, but suddenly it stoped working, here is
my code, near it's bottom you can see the line "k = k;" , just
after i sucessfuly read the state of the port, when the
program reach to the breakpoint that i put on this line, i can
see in the watch that 'my_DCB.fParity' value is zero ( 0 =
Disabled )although that as you can see at the beginning of the
function i set "my_DCB.fParity = 1;", so how come it's suddenly
changing to '0' ??
Here is my code, thanks!
Ramy
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Initialize communication port for transmit and recieve data
int InitCommunication( void )
{
COMMTIMEOUTS read_timeout; // timeout structure
char com_params[60];
char ComName[30];
HANDLE ComHndl = NULL;
DCB my_DCB; // device control block structure
int fSuccess;
if ( SystemInfo.ErrorInfo.Status != NO_ERRORS ) // If Error -> Exit
return 0;
if ( SystemInfo.ComInfo.ComHandle ) // If Port already open
{
CloseHandle( SystemInfo.ComInfo.ComHandle ); // Close Port
SystemInfo.ComInfo.ComHandle = NULL; // Reset Port Handle
}
my_DCB.DCBlength= sizeof( my_DCB ); // Sizeof(DCB)
my_DCB.BaudRate = SystemInfo.ComInfo.BaudRate; // Current baud rate
my_DCB.fBinary = true; // Binary mode, no EOF check
my_DCB.ByteSize = 8; // Number of bits/byte, 4-8
my_DCB.Parity = (char)SystemInfo.ComInfo.Parity; // 0-4=no, odd, even, mark, space
my_DCB.fParity = 1; // 1 = Enable Parity Checking
my_DCB.StopBits = 1; // 0, 1, 2 = 1, 1.5, 2
my_DCB.fOutxCtsFlow = 0; // CTS output flow control
my_DCB.fOutxDsrFlow = 0; // DSR output flow control
my_DCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type
my_DCB.fDsrSensitivity = 0; // DSR sensitivity
my_DCB.fTXContinueOnXoff = 0; // XOFF continues Tx
my_DCB.fOutX = 0; // XON/XOFF out flow control
my_DCB.fInX = 0; // XON/XOFF in flow control
my_DCB.fErrorChar = 0; // Enable error replacement
my_DCB.fNull = false; // Enable null stripping
my_DCB.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control
my_DCB.fAbortOnError = 0; // Abort reads/writes on error
my_DCB.XonLim = 50; // Transmit XON threshold
my_DCB.XoffLim = 50; // Transmit XOFF threshold
my_DCB.XonChar = 0; // Tx and Rx XON character
my_DCB.XoffChar = 0; // Tx and Rx XOFF character
my_DCB.ErrorChar = 0; // Error replacement character
my_DCB.EofChar = 0; // End of input character
my_DCB.EvtChar = 0; // Received event character
read_timeout.ReadIntervalTimeout = 0; // Read Interval Timeout
read_timeout.ReadTotalTimeoutMultiplier = 0; // Read Total Timeout Multiplier
read_timeout.ReadTotalTimeoutConstant = SystemInfo.ComInfo.RxTimeout; // Read Total Timeout Constant
read_timeout.WriteTotalTimeoutMultiplier = 0; // Write Total Timeout Multiplier
read_timeout.WriteTotalTimeoutConstant = SystemInfo.ComInfo.TxTimeout; // Write Total Timeout Constant
strcpy( com_params, SystemInfo.ComInfo.ComPort ); // Prepare com_params
strcpy( ComName, SystemInfo.ComInfo.ComPort ); // Set ComName
switch ( SystemInfo.ComInfo.BaudRate )
{
case CBR_9600:
strcat( com_params, ":9600" ); // Prepare COM Parameters
break;
case CBR_14400:
strcat( com_params, ":14400" ); // Prepare COM Parameters
break;
case CBR_19200:
strcat( com_params, ":19200" ); // Prepare COM Parameters
break;
case CBR_38400:
strcat( com_params, ":38400" ); // Prepare COM Parameters
break;
case CBR_56000:
strcat( com_params, ":56000" ); // Prepare COM Parameters
break;
case CBR_57600:
strcat( com_params, ":57600" ); // Prepare COM Parameters
break;
case CBR_115200:
strcat( com_params, ":115200" ); // Prepare COM Parameters
break;
};
if ( my_DCB.fParity == 1 ) // If Parity Checking Enabled
{
switch( my_DCB.Parity ) // Switch By Parity Value
{
case SPACEPARITY:
strcat( com_params, ", S, 8, 1" ); // Set Parity to '1'
break;
case MARKPARITY:
strcat( com_params, ", M, 8, 1" ); // Set Parity to '0'
break;
}
}
ComHndl = CreateFile( ComName, GENERIC_WRITE + GENERIC_READ, 0, NULL, // Open the asked Com Port
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if ( ComHndl == INVALID_HANDLE_VALUE ) // Check COM Handle
return FAIL;
if ( !BuildCommDCB( com_params, &my_DCB ) ) // Fills DCB Structure with Com Values
return FAIL;
if ( !SetCommState( ComHndl, &my_DCB ) ) // Configures Com Port
return FAIL;
if ( !SetCommTimeouts( ComHndl, &read_timeout ) ) // Set Tx & Rx Timeouts
return FAIL;
SystemInfo.ComInfo.ComHandle = ComHndl; // Set Communication Handle
fSuccess = GetCommState( ComHndl, &my_DCB );
if ( fSuccess )
{
int k = 0;
k = k;
}
return PASS; // COM Init was successful
}
Technical Details
Message-ID:
<429ddcd0$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,499887f6c1e08a34,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Ramy" <Ramy@NoMail.com> Sender: "Ramy" <Ramy@NoMail.com> Reply-To: "Ramy" <Ramy@NoMail.com> Subject: Please help, Parity does Not Working Again........ Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 62.0.27.159 NNTP-Posting-Host: 207.105.83.66 Message-ID: <429ddcd0$1@newsgroups.borland.com> Date: 1 Jun 2005 09:05:36 -0700 X-Trace: newsgroups.borland.com 1117641936 207.105.83.66 (1 Jun 2005 09:05:36 -0700) Lines: 148 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail