Updated serial code in AVR bootloader host application to allow Windows COM ports from COM1 to COM99.
This commit is contained in:
@@ -222,16 +222,15 @@ void JobInfo::parseCommandline( int argc, char *argv[] )
|
|||||||
|
|
||||||
|
|
||||||
case 'c' : // Specify COM port.
|
case 'c' : // Specify COM port.
|
||||||
if( strlen( param ) != 6 )
|
if (( strlen( param ) < 6 ) || (strlen( param ) > 7) ||
|
||||||
throw new ErrorMsg( "COM port parameter syntax is -cCOMx!" );
|
(param[2] != 'C' || param[3] != 'O' || param[4] != 'M' ) ||
|
||||||
|
(param[5] < '1' || param[5] > '9')) {
|
||||||
if( param[2] != 'C' || param[3] != 'O' || param[4] != 'M' )
|
throw new ErrorMsg( "COM port parameter syntax is -cCOM1 to -cCOM99" );
|
||||||
throw new ErrorMsg( "COM port parameter syntax is -cCOMx!" );
|
}
|
||||||
|
|
||||||
if( param[5] < '1' || param[5] > '8' )
|
|
||||||
throw new ErrorMsg( "Use COM1 to COM8!" );
|
|
||||||
|
|
||||||
comPort = param[5] - '0'; // Convert COM port digit to number.
|
comPort = param[5] - '0'; // Convert COM port digit to number.
|
||||||
|
if (param[6] != 0) {
|
||||||
|
comPort = (comPort * 10) + param[6] - '0';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -697,7 +696,7 @@ void JobInfo::help()
|
|||||||
<< " default is the entire FLASH. Byte addresses in hex." << endl
|
<< " default is the entire FLASH. Byte addresses in hex." << endl
|
||||||
<< "ae EEPROM address range. Specifies the address range of operations." << endl
|
<< "ae EEPROM address range. Specifies the address range of operations." << endl
|
||||||
<< " The default is the entire EEPROM. Byte addresses in hex." << 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
|
<< " omitted the program will scan the COM ports for a programmer." << endl
|
||||||
<< "b Get revisions; hardware revision (h) and software revision (s)." << endl
|
<< "b Get revisions; hardware revision (h) and software revision (s)." << endl
|
||||||
<< "g Silent operation." << endl
|
<< "g Silent operation." << endl
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ SerialPort::SerialPort( long _portNumber, long _timeout )
|
|||||||
if( _timeout < 0 )
|
if( _timeout < 0 )
|
||||||
throw new ErrorMsg( "Negative COM-port timeout not allowed!" );
|
throw new ErrorMsg( "Negative COM-port timeout not allowed!" );
|
||||||
|
|
||||||
if( _portNumber < 1 || _portNumber > 8 )
|
if( _portNumber < 1 || _portNumber > 99 )
|
||||||
throw new ErrorMsg( "Only COM1 to COM8 is supported!" );
|
throw new ErrorMsg( "Only COM1 to COM99 is supported!" );
|
||||||
|
|
||||||
/* Initialize internal parameters */
|
/* Initialize internal parameters */
|
||||||
portNumber = _portNumber;
|
portNumber = _portNumber;
|
||||||
@@ -48,7 +48,9 @@ SerialPort::~SerialPort()
|
|||||||
/* Open the communication channel */
|
/* Open the communication channel */
|
||||||
void SerialPort::openChannel()
|
void SerialPort::openChannel()
|
||||||
{
|
{
|
||||||
char comName[] = "COMx";
|
/* CreateFile expects a constant char, or char from the heap */
|
||||||
|
static char comName[64] = "COM1";
|
||||||
|
|
||||||
COMMTIMEOUTS comTimeouts;
|
COMMTIMEOUTS comTimeouts;
|
||||||
|
|
||||||
/* Check if channel already open */
|
/* Check if channel already open */
|
||||||
@@ -56,7 +58,14 @@ void SerialPort::openChannel()
|
|||||||
throw new ErrorMsg( "Channel already open! Cannot open port twice." );
|
throw new ErrorMsg( "Channel already open! Cannot open port twice." );
|
||||||
|
|
||||||
/* Generate COM filename and attempt open */
|
/* 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,
|
serialHandle = CreateFile( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user