/* 初始化串口列表框 */ void DlgOptions::AddCom(void) { EnumerateSerialPorts(ports,portse,portsu); unsigned short uicounter; unsigned short uisetcom; CString str; //获取可用串口个数 uicounter = portse.GetSize(); //获取串口总数 uicounter = ports.GetSize(); //如果串口总数大于0 if(uicounter > 0) { //初始化串口列表框 for(int i=0; i<uicounter; i++) { uisetcom = ports.ElementAt(i); str.Format(_T("COM%d "),uisetcom); m_cbCom1.AddString(str); m_cbCom2.AddString(str); m_cbCom3.AddString(str); m_cbCom4.AddString(str); m_cbCtrlCom.AddString(str); } } }
JNIEXPORT jobjectArray JNICALL Java_gurux_io_NativeCode_getPortNames (JNIEnv* env, jclass clazz) { std::vector<std::basic_string<char> > portItems; #if defined(_WIN32) || defined(_WIN64) char portname[MAX_PATH]; DWORD count = 0; long retCode = 0; while ((retCode = EnumerateSerialPorts(portname, MAX_PATH, count++, FALSE)) > -1) { std::basic_string<char> str; str.append(portname); portItems.push_back(str); } #else //If Linux GetLinuxSerialPorts (env, portItems); #endif jclass stringClass = env->FindClass ("java/lang/String"); jobjectArray ports = env->NewObjectArray ((jsize) portItems.size (), stringClass, 0); jsize pos = -1; for (std::vector<std::basic_string<char> >::iterator it = portItems.begin (); it != portItems.end (); ++it) { jobject item = env->NewStringUTF (it->c_str ()); env->SetObjectArrayElement (ports, ++pos, item); } return ports; }
IntConnectorSourceDlg::IntConnectorSourceDlg( wxWindow* parent ) : ConnectorSourceDlg( parent ) { wxArrayString *pAvailablePorts; pAvailablePorts = EnumerateSerialPorts(); m_choicePort->Clear(); for (unsigned int iPortIndex=0 ; iPortIndex < pAvailablePorts->GetCount() ; iPortIndex++) m_choicePort->Append( pAvailablePorts->Item(iPortIndex) ); m_choicePort->SetSelection(0); delete pAvailablePorts; this->CenterOnParent(); }
void TransPanel::initWidget() { std::vector<int> portsu ; std::vector<int> portse ; std::vector<int> ports ; //枚举存在的串口 EnumerateSerialPorts(portsu , portse , ports); //添加串口到列表 for(std::vector<int>::const_iterator it = ports.begin() ; it!=ports.end() ; ++ it) { int port_num = *it ; QString ComStr ; ComStr.sprintf("COM%d" , port_num) ; ui.comboBox_serialport->addItem(ComStr , port_num) ; } }
void SendToGpsDlg::CreateControls( const wxString& hint ) { SendToGpsDlg* itemDialog1 = this; wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL ); itemDialog1->SetSizer( itemBoxSizer2 ); // Create the ScrollBox list of available com ports in a labeled static box wxStaticBox* comm_box = new wxStaticBox( this, wxID_ANY, _("GPS/Plotter Port") ); wxStaticBoxSizer* comm_box_sizer = new wxStaticBoxSizer( comm_box, wxVERTICAL ); itemBoxSizer2->Add( comm_box_sizer, 0, wxEXPAND | wxALL, 5 ); wxArrayString *pSerialArray = EnumerateSerialPorts(); m_itemCommListBox = new wxComboBox( this, ID_STG_CHOICE_COMM ); // Fill in the listbox with all detected serial ports for( unsigned int iPortIndex = 0; iPortIndex < pSerialArray->GetCount(); iPortIndex++ ) { wxString full_port = pSerialArray->Item( iPortIndex ); full_port.Prepend(_T("Serial:")); m_itemCommListBox->Append( full_port ); } delete pSerialArray; // Make the proper inital selection if( !g_uploadConnection.IsEmpty() ) m_itemCommListBox->SetValue( g_uploadConnection ); else m_itemCommListBox->SetSelection( 0 ); comm_box_sizer->Add( m_itemCommListBox, 0, wxEXPAND | wxALL, 5 ); // Add a reminder text box itemBoxSizer2->AddSpacer( 20 ); wxStaticText *premtext = new wxStaticText( this, -1, _("Prepare GPS for Route/Waypoint upload and press Send...") ); itemBoxSizer2->Add( premtext, 0, wxEXPAND | wxALL, 10 ); // Create a progress gauge wxStaticBox* prog_box = new wxStaticBox( this, wxID_ANY, _("Progress...") ); wxStaticBoxSizer* prog_box_sizer = new wxStaticBoxSizer( prog_box, wxVERTICAL ); itemBoxSizer2->Add( prog_box_sizer, 0, wxEXPAND | wxALL, 5 ); m_pgauge = new wxGauge( this, -1, 100 ); prog_box_sizer->Add( m_pgauge, 0, wxEXPAND | wxALL, 5 ); // OK/Cancel/etc. wxBoxSizer* itemBoxSizer16 = new wxBoxSizer( wxHORIZONTAL ); itemBoxSizer2->Add( itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5 ); m_CancelButton = new wxButton( itemDialog1, ID_STG_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizer16->Add( m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); m_SendButton = new wxButton( itemDialog1, ID_STG_OK, _("Send"), wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizer16->Add( m_SendButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); m_SendButton->SetDefault(); }