//
 //==========================================================================
 #include "dlg_comports.h"
-#include "fdmdv2_hdw_ports.h"
+#include "fdmdv2_main.h"
 
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
 // Class ComPortsDlg
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
 ComPortsDlg::ComPortsDlg(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style)
 {
-    this->SetSizeHints(wxDefaultSize, wxDefaultSize);
-    this->SetSizeHints(wxDefaultSize, wxDefaultSize);
-    wxStaticText* m_staticText8;
-    wxStaticText* m_staticText9;
-    wxStaticText* m_staticText91;
-    wxStaticText* m_staticText911;
-    wxStaticText* m_staticText912;
-    wxStaticText* m_staticText913;
-    wxStdDialogButtonSizer* m_sdbSizer5;
-
-    wxBoxSizer* bSizer30;
-    bSizer30 = new wxBoxSizer(wxVERTICAL);
-
-    wxGridSizer* gSizer3;
-    gSizer3 = new wxGridSizer(8, 2, 0, 0);
-
-    m_staticText8 = new wxStaticText(this, wxID_ANY, _("Available Ports:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText8->Wrap(-1);
-    gSizer3->Add(m_staticText8, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
-
-    m_listCtrlPorts = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
-    gSizer3->Add(m_listCtrlPorts, 2, wxALL|wxEXPAND, 2);
-
 /*
-    m_staticText9 = new wxStaticText(this, wxID_ANY, _("Use Port:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText9->Wrap(-1);
-    gSizer3->Add(m_staticText9, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
-
-    m_textRigCtrlPort = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
-    gSizer3->Add(m_textRigCtrlPort, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
+    if(!bBitmapLoaded) 
+    {
+        // We need to initialise the default bitmap handler
+        wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
+        wxC9ED9InitBitmapResources();
+        bBitmapLoaded = true;
+    }
+*/
+    wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
+    this->SetSizer(mainSizer);
+    
+/*    
+    wxStaticBoxSizer* staticBoxSizer28 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Audio Tone")), wxVERTICAL);
+    mainSizer->Add(staticBoxSizer28, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5);
+    m_ckPTTRtChan = new wxCheckBox(this, wxID_ANY, _("PTT tone on right audio channel"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_ckPTTRtChan->SetValue(false);
+    staticBoxSizer28->Add(m_ckPTTRtChan, 0, wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL, 5);
 */
 
-    m_staticText91 = new wxStaticText(this, wxID_ANY, _("Buad Rate:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText91->Wrap(-1);
-    gSizer3->Add(m_staticText91, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
-
-    m_listCtrlBaudrates = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
-    gSizer3->Add(m_listCtrlBaudrates, 2, wxALL|wxEXPAND, 2);
-
-    m_staticText911 = new wxStaticText(this, wxID_ANY, _("Data Bits:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText911->Wrap(-1);
-    gSizer3->Add(m_staticText911, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
-
-    m_textRigCtrlDatabits = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
-    gSizer3->Add(m_textRigCtrlDatabits, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
-
-    m_staticText912 = new wxStaticText(this, wxID_ANY, _("Stop Bits:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText912->Wrap(-1);
-    gSizer3->Add(m_staticText912, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
-
-    m_textRigCtrlStopbits = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
-    gSizer3->Add(m_textRigCtrlStopbits, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
- 
-    m_staticText913 = new wxStaticText(this, wxID_ANY, _("Parity:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
-    m_staticText913->Wrap(-1);
-    gSizer3->Add(m_staticText913, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 2);
+    wxStaticBoxSizer* staticBoxSizer17 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Hardware PTT Settings")), wxVERTICAL);
+    mainSizer->Add(staticBoxSizer17, 1, wxEXPAND, 5);
+    wxStaticBoxSizer* staticBoxSizer31 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("PTT Port")), wxVERTICAL);
+    staticBoxSizer17->Add(staticBoxSizer31, 1, wxEXPAND, 5);
 
-    m_textRigCtrlParity = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
-    gSizer3->Add(m_textRigCtrlParity, 1, wxALIGN_CENTER_VERTICAL|wxALL, 2);
+    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_ckUseSerialPTT->SetValue(false);
+    staticBoxSizer31->Add(m_ckUseSerialPTT, 0, wxALIGN_LEFT, 20);
 
-    bSizer30->Add(gSizer3, 1, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
+    wxArrayString m_listCtrlPortsArr;
+    m_listCtrlPorts = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(-1,45), m_listCtrlPortsArr, wxLB_SINGLE);
+    staticBoxSizer31->Add(m_listCtrlPorts, 1, wxALIGN_CENTER, 0);
 
-//    wxStaticBoxSizer* polaritySizer;
-//    polaritySizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("")), wxHORIZONTAL);
-//    gSizer3->Add(polaritySizer, 0, wxALIGN_CENTER|wxALL, 1);
+    wxBoxSizer* boxSizer19 = new wxBoxSizer(wxVERTICAL);
+    staticBoxSizer17->Add(boxSizer19, 1, wxEXPAND, 5);
+    wxStaticBoxSizer* staticBoxSizer16 = new wxStaticBoxSizer( new wxStaticBox(this, wxID_ANY, _("Signal polarity")), wxHORIZONTAL);
+    boxSizer19->Add(staticBoxSizer16, 1, wxEXPAND|wxALIGN_CENTER|wxALIGN_RIGHT, 5);
 
-    m_rbUseRTS = new wxRadioButton( this, wxID_ANY, wxT("Use RTS"), wxDefaultPosition, wxDefaultSize, 0 );
-    gSizer3->Add(m_rbUseRTS, 0, wxALIGN_CENTER|wxALL, 1);
+    wxGridSizer* gridSizer17 = new wxGridSizer(2, 2, 0, 0);
+    staticBoxSizer16->Add(gridSizer17, 1, wxEXPAND|wxALIGN_RIGHT, 5);
 
-    m_ckRTSPos = new wxCheckBox( this, wxID_ANY, wxT("RTS = +V"), wxDefaultPosition, wxDefaultSize, 0 );
-    gSizer3->Add(m_ckRTSPos, 0, wxALIGN_CENTER|wxALL, 1);
+/*
+    m_ckUseSerialPTT = new wxCheckBox(this, wxID_ANY, _("Use Serial Port PTT"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_ckUseSerialPTT->SetValue(false);
+    gridSizer17->Add(m_ckUseSerialPTT, 0, wxALIGN_CENTER, 10);
+    gridSizer17->Add(0, 0, 0, 0, 5);
+*/
+    m_rbUseDTR = new wxRadioButton(this, wxID_ANY, _("Use DTR"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_rbUseDTR->SetValue(1);
+    gridSizer17->Add(m_rbUseDTR, 0, wxALIGN_CENTER|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
 
-    m_rbUseDTR = new wxRadioButton( this, wxID_ANY, wxT("Use DTR"), wxDefaultPosition, wxDefaultSize, 0 );
-    gSizer3->Add(m_rbUseDTR, 0, wxALIGN_CENTER|wxALL, 1);
+    m_ckRTSPos = new wxCheckBox(this, wxID_ANY, _("DTR = +V"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_ckRTSPos->SetValue(false);
+    gridSizer17->Add(m_ckRTSPos, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
 
-    m_ckDTRPos = new wxCheckBox( this, wxID_ANY, wxT("DTR = +V"), wxDefaultPosition, wxDefaultSize, 0 );
-    gSizer3->Add(m_ckDTRPos, 0, wxALIGN_CENTER|wxALL, 1);
+    m_rbUseRTS = new wxRadioButton(this, wxID_ANY, _("Use RTS"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_rbUseRTS->SetToolTip(_("Toggle the RTS pin for PTT"));
+    m_rbUseRTS->SetValue(1);
+    gridSizer17->Add(m_rbUseRTS, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
 
+    m_ckDTRPos = new wxCheckBox(this, wxID_ANY, _("RTS = +V"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_ckDTRPos->SetValue(false);
+    m_ckDTRPos->SetToolTip(_("Set Polarity of the RTS line"));
+    gridSizer17->Add(m_ckDTRPos, 0, wxALIGN_CENTER|wxALIGN_RIGHT, 5);
 
-    m_sdbSizer5 = new wxStdDialogButtonSizer();
-    m_sdbSizer5OK = new wxButton(this, wxID_OK);
-    m_sdbSizer5->AddButton(m_sdbSizer5OK);
-    m_sdbSizer5Apply = new wxButton(this, wxID_APPLY);
-    m_sdbSizer5->AddButton(m_sdbSizer5Apply);
-    m_sdbSizer5Cancel = new wxButton(this, wxID_CANCEL);
-    m_sdbSizer5->AddButton(m_sdbSizer5Cancel);
-    m_sdbSizer5->Realize();
+    wxBoxSizer* boxSizer12 = new wxBoxSizer(wxHORIZONTAL);
+    mainSizer->Add(boxSizer12, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
 
-    bSizer30->Add(m_sdbSizer5, 0, wxEXPAND, 5);
+    m_buttonOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxSize(-1,-1), 0);
+    m_buttonOK->SetDefault();
 
-    this->SetSizer(bSizer30);
-    this->Layout();
+    boxSizer12->Add(m_buttonOK, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
+    m_buttonCancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(-1,-1), 0);
+    boxSizer12->Add(m_buttonCancel, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
 
-    this->Centre(wxBOTH);
-    this->Centre(wxBOTH);
+    m_buttonApply = new wxButton(this, wxID_APPLY, _("Apply"), wxDefaultPosition, wxSize(-1,-1), 0);
+    boxSizer12->Add(m_buttonApply, 0, wxLEFT|wxRIGHT|wxTOP|wxBOTTOM, 5);
 
-    // Connect Events
-    this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog));
-    m_sdbSizer5Apply->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
-    m_sdbSizer5Cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
-    m_sdbSizer5OK->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
-    m_listCtrlPorts->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(ComPortsDlg::OnPortItemSelected), NULL, this);
-    m_listCtrlBaudrates->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(ComPortsDlg::OnBaudrateItemSelected), NULL, this);
-/*
-    void    OnApply(wxCommandEvent& event);
-    void    OnRTSClick(wxCommandEvent& event);
-    void    OnRTSPosClick(wxCommandEvent& event);
-    void    OnDTRClick(wxCommandEvent& event);
-    void    OnDTRPosClick(wxCommandEvent& event);
-*/
+    SetSizeHints(450,300);
+    if ( GetSizer() ) 
+    {
+         GetSizer()->Fit(this);
+    }
+    Centre(wxBOTH);
+
+    // Connect events
+    this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog), NULL, this);
+//    m_ckPTTRtChan->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTAudioClick), NULL, this);
+    m_listCtrlPorts->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ComPortsDlg::PTTPortSlelcted), NULL, this);
+    m_ckUseSerialPTT->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTUseSerialClicked), NULL, this);
+    m_rbUseDTR->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseDTRCliched), NULL, this);
+    m_ckRTSPos->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::DTRVPlusClicked), NULL, this);
+    m_rbUseRTS->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseRTSClicked), NULL, this);
+    m_ckDTRPos->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::RTSVPlusClicked), NULL, this);
+    m_buttonOK->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
+    m_buttonCancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
+    m_buttonApply->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
 }
 
 //-------------------------------------------------------------------------
 ComPortsDlg::~ComPortsDlg()
 {
     // Disconnect Events
-    this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog));
-    m_listCtrlPorts->Disconnect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(ComPortsDlg::OnPortItemSelected), NULL, this);
-    m_listCtrlBaudrates->Disconnect(wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler(ComPortsDlg::OnBaudrateItemSelected), NULL, this);
-    m_sdbSizer5Apply->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
-    m_sdbSizer5Cancel->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
-    m_sdbSizer5OK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
+    this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(ComPortsDlg::OnInitDialog), NULL, this);
+//    m_ckPTTRtChan->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTAudioClick), NULL, this);
+    m_listCtrlPorts->Disconnect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(ComPortsDlg::PTTPortSlelcted), NULL, this);
+    m_ckUseSerialPTT->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::PTTUseSerialClicked), NULL, this);
+    m_rbUseDTR->Disconnect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseDTRCliched), NULL, this);
+    m_ckRTSPos->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::DTRVPlusClicked), NULL, this);
+    m_rbUseRTS->Disconnect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ComPortsDlg::UseRTSClicked), NULL, this);
+    m_ckDTRPos->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(ComPortsDlg::RTSVPlusClicked), NULL, this);
+    m_buttonOK->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnOK), NULL, this);
+    m_buttonCancel->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnCancel), NULL, this);
+    m_buttonApply->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ComPortsDlg::OnApply), NULL, this);
 }
 
 //-------------------------------------------------------------------------
     int i = 0;
     wxListItem inf;
     wxString buf;
-    long idx;
-    long baudrates[] = { 110, 300, 1200, 2400, 9600, 19200, 38400, 57600, 115200 };
     
     m_listCtrlPorts->Clear();
-    m_listCtrlBaudrates->Clear();
-    for(i = 0; i < 9; i++)
-    {
-        buf.Printf("%u", baudrates[i]);
-        m_listCtrlBaudrates->Append(buf);
-    }
-        
-#ifdef  __WXMSW__
-#define PREDICATE   
-    for(i = 1; i <= 32; i++)
-    {
-        buf.Printf("COM%u:", i);
-        idx = m_listCtrlPorts->Append(buf);
-    }
-    for(i = 33; i <= 128; i++)
-    {
-        buf.Printf("\\\\.\\com%u:", i);
-        idx = m_listCtrlPorts->Append(buf);
-    }
-
-#endif
+    std::vector<std::string>result;
+    wxArrayString aStr;
 
-#ifdef  __WXGTK__
-    for(i = 0; i < 32; i++)
-    {
-        buf.Printf("/dev/ttyS%u", i);
-        idx = m_listCtrlPorts->Append(buf);
-    }
-    for(i = 0; i < 32; i++)
+    ctb::GetAvailablePorts(result, false);
+    for(int i = 0; i < result.size(); i++) 
     {
-        buf.Printf("/dev/ttyUSB%u", i);
-        idx = m_listCtrlPorts->Append(buf);
+        aStr.Add(result[i], 1);
     }
-#endif
-
-#ifdef __WXOSX__
-#define MAXPORTS    20
-#endif
-
+    m_listCtrlPorts->Append(aStr);
 }
 
 //-------------------------------------------------------------------------
     
     if(inout == EXCHANGE_DATA_IN)
     {
+//        m_ckUsePTTRtChan->SetValue(wxGetApp().m_boolUseTonePTT);
+        m_ckUseSerialPTT->SetValue(wxGetApp().m_boolUseSerialPTT);
         str = wxGetApp().m_strRigCtrlPort;
         m_listCtrlPorts->SetStringSelection(str);
-
         str = wxGetApp().m_strRigCtrlBaud;
-        m_listCtrlBaudrates->SetStringSelection(str);
 
-        m_textRigCtrlDatabits->SetValue(wxGetApp().m_strRigCtrlDatabits);
-        m_textRigCtrlStopbits->SetValue(wxGetApp().m_strRigCtrlStopbits);
-        m_textRigCtrlParity->SetValue(wxGetApp().m_strRigCtrlParity);
+//        m_listCtrlBaudrates->SetStringSelection(str);
+//        m_textRigCtrlDatabits->SetValue(wxGetApp().m_strRigCtrlDatabits);
+//        m_textRigCtrlStopbits->SetValue(wxGetApp().m_strRigCtrlStopbits);
+//        m_textRigCtrlParity->SetValue(wxGetApp().m_strRigCtrlParity);
 
         m_rbUseRTS->SetValue(wxGetApp().m_boolUseRTS);
         m_ckRTSPos->SetValue(wxGetApp().m_boolRTSPos);
     }
     if(inout == EXCHANGE_DATA_OUT)
     {
+        wxGetApp().m_boolUseSerialPTT           = m_ckUseSerialPTT->IsChecked();
+//        wxGetApp().m_boolUseTonePTT             = m_ckUsePTTRtChan->IsChecked();
         wxGetApp().m_strRigCtrlPort             = m_listCtrlPorts->GetStringSelection();
-        wxGetApp().m_strRigCtrlBaud             = m_listCtrlBaudrates->GetStringSelection();
-
-        wxGetApp().m_strRigCtrlDatabits         = m_textRigCtrlDatabits->GetValue();
-        wxGetApp().m_strRigCtrlStopbits         = m_textRigCtrlStopbits->GetValue();
-        wxGetApp().m_strRigCtrlParity           = m_textRigCtrlParity->GetValue();
-
-        wxGetApp().m_boolUseRTS                  = m_rbUseRTS->GetValue();
-        wxGetApp().m_boolRTSPos                  = m_ckRTSPos->GetValue();
-        wxGetApp().m_boolUseDTR                  = m_rbUseDTR->GetValue();
-        wxGetApp().m_boolDTRPos                  = m_ckDTRPos->GetValue();
-
-        pConfig->Write(wxT("/Rig/Port"),        wxGetApp().m_strRigCtrlPort);
-        pConfig->Write(wxT("/Rig/Baud"),        wxGetApp().m_strRigCtrlBaud);
-        pConfig->Write(wxT("/Rig/DataBits"),    wxGetApp().m_strRigCtrlDatabits);
-        pConfig->Write(wxT("/Rig/StopBits"),    wxGetApp().m_strRigCtrlStopbits);
-        pConfig->Write(wxT("/Rig/Parity"),      wxGetApp().m_strRigCtrlParity);
+        wxGetApp().m_boolUseRTS                 = m_rbUseRTS->GetValue();
+        wxGetApp().m_boolRTSPos                 = m_ckRTSPos->IsChecked();
+        wxGetApp().m_boolUseDTR                 = m_rbUseDTR->GetValue();
+        wxGetApp().m_boolDTRPos                 = m_ckDTRPos->IsChecked();
+        
+        pConfig->Write(wxT("/Rig/UseRTS"),                  wxGetApp().m_boolUseRTS);
+        pConfig->Write(wxT("/Rig/RTSPolarity"),             wxGetApp().m_boolRTSPos);
+        pConfig->Write(wxT("/Rig/UseDTR"),                  wxGetApp().m_boolUseDTR);
+        pConfig->Write(wxT("/Rig/DTRPolarity"),             wxGetApp().m_boolDTRPos);
+        pConfig->Write(wxT("/Rig/UseTonePTT"),              wxGetApp().m_boolUseTonePTT);
+        pConfig->Write(wxT("/Rig/UseSerialPTT"),            wxGetApp().m_boolUseSerialPTT);
+
+//        wxGetApp().m_strRigCtrlBaud             = m_listCtrlBaudrates->GetStringSelection();
+//        wxGetApp().m_strRigCtrlDatabits         = m_textRigCtrlDatabits->GetValue();
+//        wxGetApp().m_strRigCtrlStopbits         = m_textRigCtrlStopbits->GetValue();
+//        wxGetApp().m_strRigCtrlParity           = m_textRigCtrlParity->GetValue();
+
+//        pConfig->Write(wxT("/Rig/Port"),        wxGetApp().m_strRigCtrlPort);
+//        pConfig->Write(wxT("/Rig/Baud"),        wxGetApp().m_strRigCtrlBaud);
+//        pConfig->Write(wxT("/Rig/DataBits"),    wxGetApp().m_strRigCtrlDatabits);
+//        pConfig->Write(wxT("/Rig/StopBits"),    wxGetApp().m_strRigCtrlStopbits);
+//        pConfig->Write(wxT("/Rig/Parity"),      wxGetApp().m_strRigCtrlParity);
         //m_textRigCtrlFlowControl
-
-        pConfig->Write(wxT("/Rig/UseRTS"),      wxGetApp().m_boolUseRTS);
-        pConfig->Write(wxT("/Rig/RTSPolarity"), wxGetApp().m_boolRTSPos);
-        pConfig->Write(wxT("/Rig/UseDTR"),      wxGetApp().m_boolUseDTR);
-        pConfig->Write(wxT("/Rig/DTRPolarity"), wxGetApp().m_boolDTRPos);
-
         pConfig->Flush();
     }
     delete wxConfigBase::Set((wxConfigBase *) NULL);
 }
 /*
-    void    OnApply(wxCommandEvent& event);
-    void    OnRTSClick(wxCommandEvent& event);
-    void    OnRTSPosClick(wxCommandEvent& event);
-    void    OnDTRClick(wxCommandEvent& event);
-    void    OnDTRPosClick(wxCommandEvent& event);
-*/
 //-------------------------------------------------------------------------
 // OnPortItemSelected()
 //-------------------------------------------------------------------------
 {
     // TODO: Implement OnListItemSelected
 }
+*/
 
 //-------------------------------------------------------------------------
-// OnBaudrateItemSelected()
+// DTRVPlusClicked()
 //-------------------------------------------------------------------------
-void ComPortsDlg::OnBaudrateItemSelected(wxListEvent& event)
+void ComPortsDlg::DTRVPlusClicked(wxCommandEvent& event)
 {
-    // TODO: Implement OnListItemSelected
+    wxMessageBox(wxT("DTRVPlusClicked"));
 }
 
 //-------------------------------------------------------------------------
-// OnCancel()
+// PTTAudioClick()
 //-------------------------------------------------------------------------
-void ComPortsDlg::OnCancel(wxCommandEvent& event)
+void ComPortsDlg::PTTAudioClick(wxCommandEvent& event)
 {
-    this->EndModal(wxID_CANCEL);
 }
 
 //-------------------------------------------------------------------------
-// OnOK()
+// PTTPortSlelcted()
 //-------------------------------------------------------------------------
-void ComPortsDlg::OnOK(wxCommandEvent& event)
+void ComPortsDlg::PTTPortSlelcted(wxCommandEvent& event)
 {
-    this->EndModal(wxID_OK);
+/*
+    wxMessageBox(wxT("PTTPortSlelcted"));
+    if(event.IsChecked())
+    {
+        m_ckPTTRtChan->SetValue(false);
+        m_ckPTTRtChan->Enable(false);
+    }
+    else
+    {
+        //m_ckPTTRtChan->SetValue(false);
+        m_ckPTTRtChan->Enable(true);
+    }
+*/
 }
 
 //-------------------------------------------------------------------------
-// OnApply()
+// PTTUseSerialClicked()
 //-------------------------------------------------------------------------
-void ComPortsDlg::OnApply(wxCommandEvent& event)
+void ComPortsDlg::PTTUseSerialClicked(wxCommandEvent& event)
 {
-    ExchangeData(EXCHANGE_DATA_OUT);
 }
 
 //-------------------------------------------------------------------------
-// OnClose()
+// RTSVPlusClicked()
 //-------------------------------------------------------------------------
-void ComPortsDlg::OnClose(wxCloseEvent& event)
+void ComPortsDlg::RTSVPlusClicked(wxCommandEvent& event)
 {
-    this->EndModal(wxID_OK);
 }
 
-/*
 //-------------------------------------------------------------------------
-// serial_parity_handler()
+// OnCancel()
 //-------------------------------------------------------------------------
-static void serial_parity_handler(union control *ctrl, void *dlg, void *data, int event)
+void ComPortsDlg::UseDTRCliched(wxCommandEvent& event)
 {
-    static const struct
-    {
-        const char *name;
-        int val;
-    }
-    parities[] =
-    {
-        {"None",  SER_PAR_NONE},
-        {"Odd",   SER_PAR_ODD},
-        {"Even",  SER_PAR_EVEN},
-        {"Mark",  SER_PAR_MARK},
-        {"Space", SER_PAR_SPACE},
-    };
-    int mask = ctrl->listbox.context.i;
-    int i, j;
-    Config *cfg = (Config *)data;
-
-    if (event == EVENT_REFRESH)
-    {
-        int oldparity = cfg->serparity; // preserve past reentrant calls
-        dlg_update_start(ctrl, dlg);
-        dlg_listbox_clear(ctrl, dlg);
-        for (i = 0; i < lenof(parities); i++)
-        {
-            if (mask & (1 << i))
-            dlg_listbox_addwithid(ctrl, dlg, parities[i].name, parities[i].val);
-        }
-        for (i = j = 0; i < lenof(parities); i++)
-        {
-            if (mask & (1 << i))
-            {
-                if (oldparity == parities[i].val)
-                {
-                    dlg_listbox_select(ctrl, dlg, j);
-                    break;
-                }
-                j++;
-            }
-        }
-        if (i == lenof(parities))
-        {
-            // an unsupported setting was chosen
-            dlg_listbox_select(ctrl, dlg, 0);
-            oldparity = SER_PAR_NONE;
-        }
-        dlg_update_done(ctrl, dlg);
-        cfg->serparity = oldparity;
-        // restore
-    }
-    else if (event == EVENT_SELCHANGE)
-    {
-        int i = dlg_listbox_index(ctrl, dlg);
-        if (i < 0)
-        {
-            i = SER_PAR_NONE;
-        }
-        else
-        {
-            i = dlg_listbox_getid(ctrl, dlg, i);
-        }
-        cfg->serparity = i;
-    }
 }
 
 //-------------------------------------------------------------------------
-// serial_flow_handler()
+// UseRTSClicked()
 //-------------------------------------------------------------------------
-static void serial_flow_handler(union control *ctrl, void *dlg,        void *data, int event)
+void ComPortsDlg::UseRTSClicked(wxCommandEvent& event)
 {
-    static const struct
-    {
-        const char *name;
-        int val;
-    } flows[] =
-    {
-        {"None", SER_FLOW_NONE},
-        {"XON/XOFF", SER_FLOW_XONXOFF},
-        {"RTS/CTS", SER_FLOW_RTSCTS},
-        {"DSR/DTR", SER_FLOW_DSRDTR},
-    };
-    int mask = ctrl->listbox.context.i;
-    int i, j;
-    Config *cfg = (Config *)data;
-
-    if (event == EVENT_REFRESH)
-    {
-        int oldflow = cfg->serflow;    // preserve past reentrant calls
-        dlg_update_start(ctrl, dlg);
-        dlg_listbox_clear(ctrl, dlg);
-        for (i = 0; i < lenof(flows); i++)
-        {
-            if (mask & (1 << i))
-            dlg_listbox_addwithid(ctrl, dlg, flows[i].name, flows[i].val);
-        }
-        for (i = j = 0; i < lenof(flows); i++)
-        {
-            if (mask & (1 << i))
-            {
-                if (oldflow == flows[i].val)
-                {
-                    dlg_listbox_select(ctrl, dlg, j);
-                    break;
-                }
-            j++;
-            }
-        }
-        if (i == lenof(flows))
-        {
-            // an unsupported setting was chosen
-            dlg_listbox_select(ctrl, dlg, 0);
-            oldflow = SER_FLOW_NONE;
-        }
-        dlg_update_done(ctrl, dlg);
-        cfg->serflow = oldflow;               // restore
-    }
-    else if (event == EVENT_SELCHANGE)
-    {
-        int i = dlg_listbox_index(ctrl, dlg);
-        if (i < 0)
-        {
-            i = SER_FLOW_NONE;
-        }
-        else
-        {
-            i = dlg_listbox_getid(ctrl, dlg, i);
-        }
-        cfg->serflow = i;
-    }
 }
 
 //-------------------------------------------------------------------------
-// ser_setup_config_box()
+// OnApply()
 //-------------------------------------------------------------------------
-void ser_setup_config_box(struct controlbox *b, int midsession, int parity_mask, int flow_mask)
+void ComPortsDlg::OnApply(wxCommandEvent& event)
 {
-    struct controlset *s;
-    union control *c;
+    ExchangeData(EXCHANGE_DATA_OUT);
+}
 
-    if (!midsession)
-    {
-        int i;
-        extern void config_protocolbuttons_handler(union control *, void *, void *, int);
-        //
-        // Add the serial back end to the protocols list at the
-        // top of the config box.
-        //
-        s = ctrl_getset(b, "Session", "hostport", "Specify the destination you want to connect to");
-        for (i = 0; i < s->ncontrols; i++)
-        {
-            c = s->ctrls[i];
-            if (c->generic.type == CTRL_RADIO && c->generic.handler == config_protocolbuttons_handler)
-            {
-                c->radio.nbuttons++;
-                c->radio.ncolumns++;
-                c->radio.buttons = sresize(c->radio.buttons, c->radio.nbuttons, char *);
-                c->radio.buttons[c->radio.nbuttons-1] = dupstr("Serial");
-                c->radio.buttondata = sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
-                c->radio.buttondata[c->radio.nbuttons-1] = I(PROT_SERIAL);
-                if (c->radio.shortcuts)
-                {
-                    c->radio.shortcuts = sresize(c->radio.shortcuts, c->radio.nbuttons, char);
-                    c->radio.shortcuts[c->radio.nbuttons-1] = 'r';
-                }
-            }
-        }
-    }
-    //
-    // Entirely new Connection/Serial panel for serial port
-    // configuration.
-    //
-    ctrl_settitle(b, "Connection/Serial", "Options controlling local serial lines");
-    if (!midsession)
-    {
-        //
-        // We don't permit switching to a different serial port in
-        // midflight, although we do allow all other
-        // reconfiguration.
-        //
-        s = ctrl_getset(b, "Connection/Serial", "serline", "Select a serial line");
-        ctrl_editbox(s, "Serial line to connect to", 'l', 40, HELPCTX(serial_line), dlg_stdeditbox_handler, I(offsetof(Config,serline)), I(sizeof(((Config *)0)->serline)));
-    }
+//-------------------------------------------------------------------------
+// OnCancel()
+//-------------------------------------------------------------------------
+void ComPortsDlg::OnCancel(wxCommandEvent& event)
+{
+    this->EndModal(wxID_CANCEL);
+}
 
-    s = ctrl_getset(b, "Connection/Serial", "sercfg", "Configure the serial line");
-    ctrl_editbox(s, "Speed (baud)", 's', 40, HELPCTX(serial_speed), dlg_stdeditbox_handler, I(offsetof(Config,serspeed)), I(-1));
-    ctrl_editbox(s, "Data bits", 'b', 40, HELPCTX(serial_databits), dlg_stdeditbox_handler,I(offsetof(Config,serdatabits)),I(-1));
-    //
-    // Stop bits come in units of one half.
-    //
-    ctrl_editbox(s, "Stop bits", 't', 40, HELPCTX(serial_stopbits), dlg_stdeditbox_handler,I(offsetof(Config,serstopbits)),I(-2));
-    ctrl_droplist(s, "Parity", 'p', 40,          HELPCTX(serial_parity),   serial_parity_handler, I(parity_mask));
-    ctrl_droplist(s, "Flow control", 'f', 40, HELPCTX(serial_flow), serial_flow_handler,   I(flow_mask));
+//-------------------------------------------------------------------------
+// OnClose()
+//-------------------------------------------------------------------------
+void ComPortsDlg::OnOK(wxCommandEvent& event)
+{
+    ExchangeData(EXCHANGE_DATA_OUT);
+    this->EndModal(wxID_OK);
 }
-*/
+
 
     m_textVoiceOutput.Empty();
     m_strSampleRate.Empty();
     m_strBitrate.Empty();
+    m_boolUseTonePTT   = false;
+    m_boolUseSerialPTT = true;
     // Create the main application window
     MainFrame *frame = new MainFrame(NULL);
     SetTopWindow(frame);
     // note: run DebugView program to see this message under windows
     wxLogDebug("x = %d y = %d w = %d h = %d\n", x,y,w,h);
 
-    wxGetApp().m_show_wf      = pConfig->Read(wxT("/MainFrame/show_wf"),      1);
-    wxGetApp().m_show_spect   = pConfig->Read(wxT("/MainFrame/show_spect"),   1);
-    wxGetApp().m_show_scatter = pConfig->Read(wxT("/MainFrame/show_scatter"), 1);
-    wxGetApp().m_show_timing  = pConfig->Read(wxT("/MainFrame/show_timing"),  1);
-    wxGetApp().m_show_freq    = pConfig->Read(wxT("/MainFrame/show_freq"),    1);
-    wxGetApp().m_show_speech_in = pConfig->Read(wxT("/MainFrame/show_speech_in"),    1);
-    wxGetApp().m_show_speech_out = pConfig->Read(wxT("/MainFrame/show_speech_out"),    1);
-    wxGetApp().m_show_demod_in = pConfig->Read(wxT("/MainFrame/show_demod_in"),    1);
-    
+    wxGetApp().m_show_wf            = pConfig->Read(wxT("/MainFrame/show_wf"),      1);
+    wxGetApp().m_show_spect         = pConfig->Read(wxT("/MainFrame/show_spect"),   1);
+    wxGetApp().m_show_scatter       = pConfig->Read(wxT("/MainFrame/show_scatter"), 1);
+    wxGetApp().m_show_timing        = pConfig->Read(wxT("/MainFrame/show_timing"),  1);
+    wxGetApp().m_show_freq          = pConfig->Read(wxT("/MainFrame/show_freq"),    1);
+    wxGetApp().m_show_speech_in     = pConfig->Read(wxT("/MainFrame/show_speech_in"),    1);
+    wxGetApp().m_show_speech_out    = pConfig->Read(wxT("/MainFrame/show_speech_out"),    1);
+    wxGetApp().m_show_demod_in      = pConfig->Read(wxT("/MainFrame/show_demod_in"),    1);
+
     g_SquelchActive = pConfig->Read(wxT("/Audio/SquelchActive"), 1);
     g_SquelchLevel = pConfig->Read(wxT("/Audio/SquelchLevel"), (int)(SQ_DEFAULT_SNR*2));
     g_SquelchLevel /= 2.0;
             g_nSoundCards = 2;
     }
 
-    wxGetApp().m_strRigCtrlPort     = pConfig->Read("/Rig/Port",                wxT("\\\\.\\com1"));
-    wxGetApp().m_strRigCtrlBaud     = pConfig->Read("/Rig/Baud",                wxT("9600"));
-    wxGetApp().m_strRigCtrlDatabits = pConfig->Read("/Rig/DataBits",            wxT("8"));
-    wxGetApp().m_strRigCtrlStopbits = pConfig->Read("/Rig/StopBits",            wxT("1"));
-    wxGetApp().m_strRigCtrlParity   = pConfig->Read("/Rig/Parity",              wxT("n"));
-
+    wxGetApp().m_strRigCtrlPort     = pConfig->Read(wxT("/Rig/Port"),           wxT("COM3"));
+    wxGetApp().m_strRigCtrlBaud     = pConfig->Read(wxT("/Rig/Baud"),           wxT("9600"));
+    wxGetApp().m_strRigCtrlDatabits = pConfig->Read(wxT("/Rig/DataBits"),       wxT("8"));
+    wxGetApp().m_strRigCtrlStopbits = pConfig->Read(wxT("/Rig/StopBits"),       wxT("1"));
+    wxGetApp().m_strRigCtrlParity   = pConfig->Read(wxT("/Rig/Parity"),         wxT("n"));
+    wxGetApp().m_boolUseTonePTT     = pConfig->ReadBool(wxT("/Rig/UseTonePTT"),     false);
+    wxGetApp().m_boolUseSerialPTT   = pConfig->ReadBool(wxT("/Rig/UseSerialPTT"),   true);
+    wxGetApp().m_boolUseRTS         = pConfig->ReadBool(wxT("/Rig/UseRTS"),         true);
+    wxGetApp().m_boolRTSPos         = pConfig->ReadBool(wxT("/Rig/RTSPolarity"),    false);
+    wxGetApp().m_boolUseDTR         = pConfig->ReadBool(wxT("/Rig/UseDTR"),         false);
+    wxGetApp().m_boolDTRPos         = pConfig->ReadBool(wxT("/Rig/DTRPolarity"),    false);
     wxGetApp().m_playFileToMicInPath = pConfig->Read("/File/playFileToMicInPath", wxT(""));
     wxGetApp().m_recFileFromRadioPath = pConfig->Read("/File/recFileFromRadioPath", wxT(""));
     wxGetApp().m_recFileFromRadioSecs = pConfig->Read("/File/recFileFromRadioSecs", 30);
     m_togBtnSplit->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this);
     m_togBtnAnalog->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this);
     //m_togBtnALC->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnALCClickUI), NULL, this);
-    m_btnTogTX->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTXClickUI), NULL, this);
+    m_btnTogPTT->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTXClickUI), NULL, this);
 
     m_togBtnSplit->Disable();
     m_togRxID->Disable();
     m_togTxID->Disable();
     m_togBtnAnalog->Disable();
     //m_togBtnALC->Disable();
-    m_btnTogTX->Disable();
+    //m_btnTogPTT->Disable();
+    SetupSerialPort();
+
 
 //    m_menuItemPlayAudioFile->Enable(false);
 
     // squelch settings
-
     char sqsnr[15];
     m_sliderSQ->SetValue((int)(g_SquelchLevel*2.0));
     sprintf(sqsnr, "%4.1f", g_SquelchLevel);
     g_split = 0;
 
     // data states
-    
     g_txDataInFifo = fifo_create(MAX_CALLSIGN*VARICODE_MAX_BITS);   
     g_rxDataOutFifo = fifo_create(MAX_CALLSIGN*VARICODE_MAX_BITS);   
     varicode_decode_init(&g_varicode_dec_states);
         pConfig->Write(wxT("/Rig/RTSPolarity"),             wxGetApp().m_boolRTSPos);
         pConfig->Write(wxT("/Rig/UseDTR"),                  wxGetApp().m_boolUseDTR);
         pConfig->Write(wxT("/Rig/DTRPolarity"),             wxGetApp().m_boolDTRPos);
+        pConfig->Write(wxT("/Rig/UseTonePTT"),              wxGetApp().m_boolUseTonePTT);
+        pConfig->Write(wxT("/Rig/UseSerialPTT"),            wxGetApp().m_boolUseSerialPTT);
 
         pConfig->Write(wxT("/File/playFileToMicInPath"),    wxGetApp().m_playFileToMicInPath);
         pConfig->Write(wxT("/File/recFileFromRadioPath"),   wxGetApp().m_recFileFromRadioPath);
     m_togBtnSplit->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnSplitClickUI), NULL, this);
     m_togBtnAnalog->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnAnalogClickUI), NULL, this);
     //m_togBtnALC->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnALCClickUI), NULL, this);
-    m_btnTogTX->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTXClickUI), NULL, this);
-
+    m_btnTogPTT->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MainFrame::OnTogBtnTXClickUI), NULL, this);
+    
+    CloseSerialPort();
+    
     if (m_RxRunning)
     {
         stopRxStream();
 //-------------------------------------------------------------------------
 void MainFrame::OnTogBtnTXClick(wxCommandEvent& event)
 {
-    if (g_tx) {
+    if (g_tx) 
+    {
         // tx-> rx transition, swap to Waterfall
         m_auiNbookCtrl->ChangeSelection(0); 
     }
-    else {
+    else 
+    {
         // rx-> tx transition, swap to Mic In page to monitor speech
         m_auiNbookCtrl->ChangeSelection(4); // is there a way to avoid hard coding this?
     }
-    g_tx = m_btnTogTX->GetValue();
-
+    g_tx = m_btnTogPTT->GetValue();
+    
+    if(event.IsChecked()) 
+    {
+        m_serialPort->SetLineState(ctb::LinestateRts);
+       // m_btnTogPTT->SetLabel(wxT("PTT"));
+    } 
+    else 
+    {
+        m_serialPort->ClrLineState(ctb::LinestateRts);
+       // m_btnTogPTT->SetLabel(wxT("PTT"));
+    }
+    
     // reset level gauge
     m_maxLevel = 0;
     m_textLevel->SetLabel(wxT(""));
     m_togTxID->Disable();
     m_togBtnAnalog->Disable();
     //m_togBtnALC->Disable();
-    m_btnTogTX->Disable();
+    m_btnTogPTT->Disable();
 }
 
 //-------------------------------------------------------------------------
     if(rv == wxID_OK)
     {
         dlg->ExchangeData(EXCHANGE_DATA_OUT);
+        CloseSerialPort();
+        SetupSerialPort();
     }
     delete dlg;
 }
         //m_togRxID->Enable();
         //m_togTxID->Enable();
         m_togBtnAnalog->Enable();
-        m_btnTogTX->Enable();
+        m_btnTogPTT->Enable();
         m_togBtnOnOff->SetLabel(wxT("Stop"));
 
         // init modem and codec states
         m_togRxID->Disable();
         m_togTxID->Disable();
         m_togBtnAnalog->Disable();
-        m_btnTogTX->Disable();
+        m_btnTogPTT->Disable();
         m_togBtnOnOff->SetLabel(wxT("Start"));
     }
 }
     }
 }
 
+//----------------------------------------------------------------
+// SetupSerialPort()
+//----------------------------------------------------------------
+void MainFrame::SetupSerialPort(void)
+{
+/*
+    wxString            m_strRigCtrlBaud;
+    wxString            m_strRigCtrlDatabits;
+    wxString            m_strRigCtrlStopbits;
+    wxString            m_strRigCtrlParity;
+    bool                m_boolUseSerialPTT;
+    bool                m_boolUseTonePTT;
+    bool                m_boolUseRTS;
+    bool                m_boolRTSPos;
+    bool                m_boolUseDTR;
+    bool                m_boolDTRPos;
+*/
+    long baudrate;
+    
+    wxGetApp().m_strRigCtrlBaud.ToLong(&baudrate, 10);
+    if(!wxGetApp().m_strRigCtrlPort.IsEmpty())
+    {
+        wxString protocol = wxGetApp().m_strRigCtrlDatabits + wxGetApp().m_strRigCtrlParity + wxGetApp().m_strRigCtrlStopbits; //"8N1";
+        m_serialPort = new ctb::SerialPort();
+        if(m_serialPort->Open(wxGetApp().m_strRigCtrlPort.c_str(), baudrate, protocol.c_str(), ctb::SerialPort::NoFlowControl ) >= 0 ) 
+        {
+            m_device = m_serialPort;
+        }
+        m_btnTogPTT->Enable(true);
+        //m_btnTogPTT->SetLabel(wxT("Rx"));
+    }
+    else
+    {
+        wxMessageBox(wxT("You must select a Serial port to Open!"), wxT("Error"), wxOK);
+    }
+}
+
+//----------------------------------------------------------------
+// CloseSerialPort()
+//----------------------------------------------------------------
+void MainFrame::CloseSerialPort(void)
+{
+    if(m_serialPort->IsOpen())
+    {
+        m_serialPort->Close();
+        m_device = NULL; 
+        //m_btnTogPTT->SetLabel(wxT("PTT"));
+        m_btnTogPTT->Enable(false);
+    }
+}