save port

This commit is contained in:
Rene Hopf
2014-10-02 21:21:33 +02:00
parent aaadd54740
commit ddd93e2353
2 changed files with 11 additions and 0 deletions
+9
View File
@@ -3,6 +3,7 @@
MainFrame::MainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title){
connected = false;
histpos = 0;
config = new wxConfig("Servoterm");
wxBoxSizer *mainsizer = new wxBoxSizer(wxHORIZONTAL);
wxSplitterWindow *mainsplitter = new wxSplitterWindow(this,wxID_ANY,wxDefaultPosition, wxSize(1024,768),wxSP_LIVE_UPDATE|wxSP_3DSASH);
wxImage::AddHandler(new wxGIFHandler);
@@ -107,9 +108,13 @@ void MainFrame::listports(){
sp_free_port_list(ports);
}
if(sp_list_ports(&ports) == SP_OK){
wxString str;
choose_port->Clear();
for (int i = 0; ports[i]; i++) {
choose_port->Append(sp_get_port_description(ports[i]));
if(config->Read("port", &str) && sp_get_port_description(ports[i]) == str){
choose_port->SetSelection(i);
}
}
}
}
@@ -128,6 +133,10 @@ void MainFrame::OnConnect(wxCommandEvent& WXUNUSED(event)){
void MainFrame::connect(){
port = ports[choose_port->GetSelection()];
if(sp_open(port, SP_MODE_WRITE) == SP_OK){//port da und lässt sich öffnen
wxString str;
str = sp_get_port_description(port);
config->Write("port", str);
config->Flush();
sp_set_baudrate(port,38400);
sp_set_bits(port, 8);
sp_set_stopbits(port, 1);
+2
View File
@@ -10,6 +10,7 @@
#include <wx/choice.h>
#include <wx/arrstr.h>
#include <wx/button.h>
#include <wx/config.h>
#include <math.h>
#include <vector>
#include <libserialport.h>
@@ -25,6 +26,7 @@ private:
wxButton *clear;
wxRadioButton *uhu;
wxRadioButton *stmbl;
wxConfig *config;
struct sp_port **ports;
struct sp_port *port;
wxChoice *choose_port;