public PortSetupForm(bool useCustom, Configuration.SerialParameters serParams) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); SerialParameters = serParams; if (useCustom) { radioCustom.Checked = true; } else { radioDefault.Checked = true; } textBaudrate.Text = serParams.BaudRate.ToString(); comboDataBits.SelectedIndex = serParams.DataBits - 1; comboParity.Items.AddRange(Enum.GetNames(typeof(Parity))); comboStopBits.Items.AddRange(Enum.GetNames(typeof(StopBits))); comboParity.SelectedIndex = (int)serParams.Parity; comboStopBits.SelectedIndex = (int)serParams.StopBits; }
void ButtonPortSetupClick(object sender, EventArgs e) { var sp = useCustomSerialParameters ? serialParameters : createSerialReader().GetDefaultSerialParameters(); var d = new PortSetupForm(useCustomSerialParameters, sp); d.ShowDialog(); if (d.DialogResult == DialogResult.OK) { useCustomSerialParameters = d.UseCustomSerialParameters; serialParameters = d.SerialParameters; } }
private void loadProfile(Configuration.Profile p) { lua = null; while (mappings.Count > 0) { mappings[0].Remove(); } if (!connected) { // load this stuff only if not connected comboProtocol.SelectedIndex = p.Protocol < comboProtocol.Items.Count ? p.Protocol : 0; comboPorts.SelectedItem = p.COMPort; if (comboPorts.SelectedItem == null && comboPorts.Items.Count > 0) { comboPorts.SelectedIndex = 0; } useCustomSerialParameters = p.UseCustomSerialParameters; serialParameters = p.SerialParameters; protocolConfig = p.ProtocolConfiguration; comboJoysticks1.SelectedItem = p.VJoyInstance1; comboJoysticks2.SelectedItem = p.VJoyInstance2; if (comboJoysticks1.SelectedItem == null && comboJoysticks1.Items.Count > 0) { comboJoysticks1.SelectedIndex = 0; } if (comboJoysticks2.SelectedItem == null && comboJoysticks2.Items.Count > 0) { comboJoysticks2.SelectedIndex = 0; } } foreach (var m in p.Mappings) { addMapping(m.Copy()); } failsafeUpdateRate = p.FailsafeUpdateRate; failsafeTime = p.FailsafeTime; luaScript = p.LuaScript; lua = new Lua(luaScript); setScriptButtonAndMenuText(); currentProfile = p; }
bool OpenLinuxPortCustomBaudRate(string port, Configuration.SerialParameters sp) { try { // first try to open with safe baudrate serialPort = new SerialPort(port, 9600, sp.Parity, sp.DataBits, sp.StopBits); serialPort.Open(); // it worked, no try to set the custom baud rate if (!SetLinuxCustomBaudRate(port, sp.BaudRate)) { serialPort.Close(); return(false); } return(true); } catch (Exception) { return(false); } }
public virtual bool OpenPort(string port, Configuration.SerialParameters sp) { try { serialPort = new SerialPort(port, sp.BaudRate, sp.Parity, sp.DataBits, sp.StopBits); serialPort.Open(); return(true); } catch (Exception) { if (System.Environment.OSVersion.Platform == PlatformID.Unix) { // mono on linux has trouble opening serial ports with non standard baud rates return(OpenLinuxPortCustomBaudRate(port, sp)); } return(false); } }
public override bool OpenPort(string port, Configuration.SerialParameters sp) { // do not do anything return(true); }