From c13ece98e9a035c6462d403904c617109996f17b Mon Sep 17 00:00:00 2001 From: skarg Date: Wed, 27 May 2009 19:36:59 +0000 Subject: [PATCH] Updated serial code in AVR bootloader host application to allow Windows COM ports from COM1 to COM99. --- .../ports/bdk-atxx4-mstp/avrosp/JobInfo.cpp | 19 +++++++++---------- .../bdk-atxx4-mstp/avrosp/SerialPort.cpp | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/JobInfo.cpp b/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/JobInfo.cpp index 58feff69..df2d2ee4 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/JobInfo.cpp +++ b/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/JobInfo.cpp @@ -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 diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/SerialPort.cpp b/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/SerialPort.cpp index f8de7470..2579f393 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/SerialPort.cpp +++ b/bacnet-stack/ports/bdk-atxx4-mstp/avrosp/SerialPort.cpp @@ -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 );