modified Windows serial port for COM ports greater than 10
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 13 May 2018 08:00:59 +0000 (08:00 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 13 May 2018 08:00:59 +0000 (08:00 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3603 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/USER_MANUAL.txt
freedv-dev/src/dlg_options.cpp
freedv-dev/src/dlg_ptt.cpp
freedv-dev/src/serialport.cpp

index ca8caa10ed45b29c0f2471182dd4e7be191e3d17..870bdef87cbab0f75eb05f377b719019658765a3 100644 (file)
@@ -33,6 +33,14 @@ used by FreeDV in the PTT Dialog.
 If you are really stuck, download Hamlib and test your radio's PTT
 using the command line rigctl program.
 
+Changing COM Port On Windows
+----------------------------
+
+If you change the COM port of a USB-Serial device in Device Manager,
+please unplug and plug back in the USB device.  Windows/FreeDV won't
+recognise the device on the new COM Port until it has been
+unplugged/plugged.
+
 Voice Keyer 
 -----------
 
index 8958d4e8eb9698f8e26f494109f94ac6d5d7ec9e..d7d01d2fcf96431d1e64230728e3dd6e73c6d712 100644 (file)
@@ -87,21 +87,6 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c
 
     bSizer30->Add(staticBoxSizer28a,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3);
 
-#ifdef __WXMSW__
-    //------------------------------
-    // debug console, for WIndows build make console pop up for debug messages
-    //------------------------------
-
-    wxStaticBoxSizer* sbSizer_console;
-    wxStaticBox *sb_console = new wxStaticBox(this, wxID_ANY, _("Debug"));
-    sbSizer_console = new wxStaticBoxSizer(sb_console, wxHORIZONTAL);
-
-    m_ckboxDebugConsole = new wxCheckBox(this, wxID_ANY, _("Show Console"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
-    sbSizer_console->Add(m_ckboxDebugConsole, 0, wxALIGN_LEFT, 0);
-
-    bSizer30->Add(sbSizer_console,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3);
-#endif
-
     //------------------------------
     // FreeDV 700 Options
     //------------------------------
@@ -262,12 +247,27 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c
     bSizer30->Add(sbSizer_udp,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3);
 #endif
 
+#ifdef __WXMSW__
+    //------------------------------
+    // debug console, for WIndows build make console pop up for debug messages
+    //------------------------------
+
+    wxStaticBoxSizer* sbSizer_console;
+    wxStaticBox *sb_console = new wxStaticBox(this, wxID_ANY, _("Debug: Windows"));
+    sbSizer_console = new wxStaticBoxSizer(sb_console, wxHORIZONTAL);
+
+    m_ckboxDebugConsole = new wxCheckBox(this, wxID_ANY, _("Show Console"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE);
+    sbSizer_console->Add(m_ckboxDebugConsole, 0, wxALIGN_LEFT, 0);
+
+    bSizer30->Add(sbSizer_console,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3);
+#endif
+
     //----------------------------------------------------------
     // FIFO and PortAudio under/overflow counters used for debug
     //----------------------------------------------------------
 
     wxStaticBoxSizer* sbSizer_fifo;
-    wxStaticBox* sb_fifo = new wxStaticBox(this, wxID_ANY, _("FIFO and PortAudio Debug Counters"));
+    wxStaticBox* sb_fifo = new wxStaticBox(this, wxID_ANY, _("Debug: FIFO and PortAudio Under/Over Flow Counters"));
     sbSizer_fifo = new wxStaticBoxSizer(sb_fifo, wxVERTICAL);
 
     m_BtnFifoReset = new wxButton(this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, 0);
index 69177ebd71de32762b17b3dcdb376cb1d723023c..093ac34b82ea5d6197aa82fb069d0da1ed56ef0f 100644 (file)
@@ -514,7 +514,9 @@ void ComPortsDlg::OnTest(wxCommandEvent& event) {
 #if defined(__WXGTK__) || defined(__WXOSX__)
         ctrlport = m_cbCtlDevicePath->GetValue();
 #endif
-        fprintf(stderr, "opening serial port %s\n", ctrlport.c_str());
+        fprintf(stderr, "opening serial port: ");
+       fputs(ctrlport.c_str(), stderr);            // don't escape crazy Microsoft bakslash-ified comm port names
+       fprintf(stderr,"\n");
 
         bool success = serialport->openport(ctrlport.c_str(),
                                             m_rbUseRTS->GetValue(),
index 38de5feff2553453516248b40a3290b52b5ad4cb..f30c1c86ff64abadb0a7b17cf9e5b9eac57e9988 100644 (file)
@@ -21,8 +21,8 @@ Serialport::~Serialport() {
 
 bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useDTR, bool DTRPos)
 {
-    fprintf(stderr, "starting openport(), name: %s useRTS: %d RTSPos: %d useDTR: %d DTRPos: %d\n",
-            name, useRTS, RTSPos, useDTR, DTRPos);
+    fprintf(stderr, "starting openport(), name: %s strlen(name): %d useRTS: %d RTSPos: %d useDTR: %d DTRPos: %d\n",
+            name, (int)strlen(name), useRTS, RTSPos, useDTR, DTRPos);
 
     if (com_handle != COM_HANDLE_INVALID) {
         closeport();
@@ -37,37 +37,62 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD
     
 #ifdef _WIN32
     {
-        COMMCONFIG CC;
-        DWORD CCsize=sizeof(CC);
         COMMTIMEOUTS timeouts;
         DCB    dcb;
         TCHAR  lpszFunction[100];
        
-        if(GetDefaultCommConfigA(name, &CC, &CCsize)) {
-                    
+        // As per:
+        //   [1] https://support.microsoft.com/en-us/help/115831/howto-specify-serial-ports-larger-than-com9
+        //   [2] Hamlib lib/termios.c, win32_serial_open()
+
+       /*  
+            To test change of COM port for USB serial device on Windows
+
+            1/ Run->devmgmnt.msc
+            2/ Change COM port Ports (COM & LPT) -> Serial Device -> Properties Tab -> Advanced
+            3/ Unplug USB serial devce and plug in again.  This is really important.  FreeDV won't recognise
+               new COM port number until this is done.
+            4/ Test PTT on FreeDV Tools->PTT
+       */
+
+        TCHAR  nameWithStrangePrefix[100];
+        StringCchPrintf(nameWithStrangePrefix, 100, "\\\\.\\%s", name);
+        fputs("nameWithStrangePrefix: ", stderr);
+       fputs(nameWithStrangePrefix, stderr);
+       fprintf(stderr,"\n");
+
+#ifdef NOT_USED
+
+        COMMCONFIG CC;
+        DWORD CCsize=sizeof(CC);
+       memset(&CC, 0, CCsize);
+       CC.dwSize = CCsize;
+
+       /* Commented out by David May 13 2018, as it was failing after
+           "name" changed to "nameWithStrangePrefix" that is reqd for
+           support of COM ports above 9.  I am not sure if this is
+           needed as I can't see anything similar in Hamlib */
+       
+        if(GetDefaultCommConfigA(nameWithStrangePrefix, &CC, &CCsize)) {
+           fprintf(stderr, "GetDefaultCommConfigA OK\n");         
             CC.dcb.fOutxCtsFlow                = FALSE;
             CC.dcb.fOutxDsrFlow                = FALSE;
             CC.dcb.fDtrControl         = DTR_CONTROL_DISABLE;
             CC.dcb.fDsrSensitivity     = FALSE;
             CC.dcb.fRtsControl         = RTS_CONTROL_DISABLE;
-            if (!SetDefaultCommConfigA(name, &CC, CCsize)) {
+            if (!SetDefaultCommConfigA(nameWithStrangePrefix, &CC, CCsize)) {
                StringCchPrintf(lpszFunction, 100, "%s", "SetDefaultCommConfigA");
                 goto error;
             }
-            
+            fprintf(stderr, "SetDefaultCommConfigA OK\n");
         } else {
             StringCchPrintf(lpszFunction, 100, "%s", "GetDefaultCommConfigA");
              goto error;
         }
-
-        // As per:
-        //   https://support.microsoft.com/en-us/help/115831/howto-specify-serial-ports-larger-than-com9
-        
-        TCHAR  nameWithStrangePrefix[100];
-        StringCchPrintf(nameWithStrangePrefix, 100, "\\\\\\\\.\\\\%s", name);
-        fprintf(stderr, "nameWithStrangePrefix: %s\n");
-        if((com_handle=CreateFileA(name
-                                   ,fdwAccess                  /* Access */
+#endif
+       
+        if((com_handle=CreateFileA(nameWithStrangePrefix
+                                   ,GENERIC_READ | GENERIC_WRITE/* Access */
                                    ,0                          /* Share mode */
                                    ,NULL                       /* Security attributes */
                                    ,OPEN_EXISTING              /* Create access */
@@ -76,15 +101,21 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD
                                    ))==INVALID_HANDLE_VALUE) {
            StringCchPrintf(lpszFunction, 100, "%s", "CreateFileA");
            goto error;
-        }
-
+       }
+        fprintf(stderr, "CreateFileA OK\n");
+       
         if(GetCommTimeouts(com_handle, &timeouts)) {
+           fprintf(stderr, "GetCommTimeouts OK\n");
             timeouts.ReadIntervalTimeout=MAXDWORD;
             timeouts.ReadTotalTimeoutMultiplier=0;
             timeouts.ReadTotalTimeoutConstant=0;               // No-wait read timeout
             timeouts.WriteTotalTimeoutMultiplier=0;
             timeouts.WriteTotalTimeoutConstant=5000;   // 5 seconds
-            SetCommTimeouts(com_handle,&timeouts);
+           if (!SetCommTimeouts(com_handle,&timeouts)) {
+             StringCchPrintf(lpszFunction, 100, "%s", "SetCommTimeouts");
+              goto error;            
+           }
+           fprintf(stderr, "SetCommTimeouts OK\n");
         } else {
            StringCchPrintf(lpszFunction, 100, "%s", "GetCommTimeouts");
             goto error;
@@ -92,6 +123,8 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD
 
         /* Force N-8-1 mode: */
         if(GetCommState(com_handle, &dcb)==TRUE) {
+           fprintf(stderr, "GetCommState OK\n");
+           
             dcb.ByteSize               = 8;
             dcb.Parity                 = NOPARITY;
             dcb.StopBits               = ONESTOPBIT;
@@ -110,11 +143,12 @@ bool Serialport::openport(const char name[], bool useRTS, bool RTSPos, bool useD
                StringCchPrintf(lpszFunction, 100, "%s", "SetCommState");
                 goto error;           
             }
+           fprintf(stderr, "SetCommState OK\n");
         } else {
            StringCchPrintf(lpszFunction, 100, "%s", "GetCommState");
             goto error;           
         }
-
+       
        return true;
        
     error: