Updated serial code in AVR bootloader host application to allow Windows COM ports from COM1 to COM99.

This commit is contained in:
skarg
2009-05-27 19:36:59 +00:00
parent 911d841496
commit c13ece98e9
2 changed files with 22 additions and 14 deletions
@@ -222,16 +222,15 @@ void JobInfo::parseCommandline( int argc, char *argv[] )
case 'c' : // Specify COM port.
if( strlen( param ) != 6 )
throw new ErrorMsg( "COM port parameter syntax is -cCOMx!" );
if( param[2] != 'C' || param[3] != 'O' || param[4] != 'M' )
throw new ErrorMsg( "COM port parameter syntax is -cCOMx!" );
if( param[5] < '1' || param[5] > '8' )
throw new ErrorMsg( "Use COM1 to COM8!" );
if (( strlen( param ) < 6 ) || (strlen( param ) > 7) ||
(param[2] != 'C' || param[3] != 'O' || param[4] != 'M' ) ||
(param[5] < '1' || param[5] > '9')) {
throw new ErrorMsg( "COM port parameter syntax is -cCOM1 to -cCOM99" );
}
comPort = param[5] - '0'; // Convert COM port digit to number.
if (param[6] != 0) {
comPort = (comPort * 10) + param[6] - '0';
}
break;
@@ -697,7 +696,7 @@ void JobInfo::help()
<< " default is the entire FLASH. Byte addresses in hex." << endl
<< "ae EEPROM address range. Specifies the address range of operations." << endl
<< " The default is the entire EEPROM. Byte addresses in hex." << endl
<< "c Select communication port; 'COM1' to 'COM8'. If this parameter is" << endl
<< "c Select communication port; 'COM1' to 'COM99'. If this parameter is" << endl
<< " omitted the program will scan the COM ports for a programmer." << endl
<< "b Get revisions; hardware revision (h) and software revision (s)." << endl
<< "g Silent operation." << endl
@@ -28,8 +28,8 @@ SerialPort::SerialPort( long _portNumber, long _timeout )
if( _timeout < 0 )
throw new ErrorMsg( "Negative COM-port timeout not allowed!" );
if( _portNumber < 1 || _portNumber > 8 )
throw new ErrorMsg( "Only COM1 to COM8 is supported!" );
if( _portNumber < 1 || _portNumber > 99 )
throw new ErrorMsg( "Only COM1 to COM99 is supported!" );
/* Initialize internal parameters */
portNumber = _portNumber;
@@ -48,7 +48,9 @@ SerialPort::~SerialPort()
/* Open the communication channel */
void SerialPort::openChannel()
{
char comName[] = "COMx";
/* CreateFile expects a constant char, or char from the heap */
static char comName[64] = "COM1";
COMMTIMEOUTS comTimeouts;
/* Check if channel already open */
@@ -56,7 +58,14 @@ void SerialPort::openChannel()
throw new ErrorMsg( "Channel already open! Cannot open port twice." );
/* Generate COM filename and attempt open */
comName[3] = '0' + portNumber;
if (portNumber < 10) {
comName[3] = '0' + portNumber;
} else if (portNumber < 100) {
/* For COM ports greater than 9 you have to use a special syntax
for CreateFile. The syntax also works for COM ports 1-9. */
/* http://support.microsoft.com/kb/115831 */
sprintf(comName, "\\\\.\\COM%ld", portNumber);
}
serialHandle = CreateFile( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );