public void Connection() { try { lock (LockObject) { xGBCnet?.Close(); xGBCnet = new XGBCnet(); xGBCnet.Station = Station; try { xGBCnet.SerialPortInni(sp => { sp.PortName = serialPort.PortName; sp.BaudRate = serialPort.BaudRate; sp.DataBits = serialPort.DataBits; sp.StopBits = serialPort.StopBits; sp.Parity = serialPort.Parity; }); xGBCnet.Open(); IsConnected = true; } catch (Exception ex) { EventscadaException?.Invoke(this.GetType().Name, ex.Message); } } } catch (TimeoutException ex) { IsConnected = false; EventscadaException?.Invoke(this.GetType().Name, ex.Message); } }
public override void DeviceConn(XGBCnetConfig config) { XGBCnet gBCnet = new XGBCnet(); SetPort(); gBCnet.Station = config.StationNo; gBCnet.SerialPortInni(serialPort.PortName, serialPort.BaudRate, serialPort.DataBits, serialPort.StopBits, serialPort.Parity); gBCnet.Open(); NetworkDevice = gBCnet; }
private void button1_Click(object sender, EventArgs e) { if (!int.TryParse(textBox2.Text, out int baudRate)) { MessageBox.Show(DemoUtils.BaudRateInputWrong); return; } if (!int.TryParse(textBox16.Text, out int dataBits)) { MessageBox.Show(DemoUtils.DataBitsInputWrong); return; } if (!int.TryParse(textBox17.Text, out int stopBits)) { MessageBox.Show(DemoUtils.StopBitInputWrong); return; } if (!byte.TryParse(textBox15.Text, out byte station)) { MessageBox.Show("Station input wrong!"); return; } xGBCnet?.Close( ); xGBCnet = new XGBCnet( ); xGBCnet.Station = station; try { xGBCnet.SerialPortInni(sp => { sp.PortName = comboBox3.Text; sp.BaudRate = baudRate; sp.DataBits = dataBits; sp.StopBits = stopBits == 0 ? System.IO.Ports.StopBits.None : (stopBits == 1 ? System.IO.Ports.StopBits.One : System.IO.Ports.StopBits.Two); sp.Parity = comboBox1.SelectedIndex == 0 ? System.IO.Ports.Parity.None : (comboBox1.SelectedIndex == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even); }); xGBCnet.Open( ); button2.Enabled = true; button1.Enabled = false; panel2.Enabled = true; userControlCurve1.ReadWriteNet = xGBCnet; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public bool Connection() { try { lock (LockObject) { xGBCnet?.Close(); xGBCnet = new XGBCnet { Station = Station }; try { xGBCnet.SerialPortInni(sp => { sp.PortName = serialPort.PortName; sp.BaudRate = serialPort.BaudRate; sp.DataBits = serialPort.DataBits; sp.StopBits = serialPort.StopBits; sp.Parity = serialPort.Parity; }); xGBCnet.Open(); if (xGBCnet.IsOpen()) { EventscadaException?.Invoke(GetType().Name, StringResources.Language.ConnectedSuccess); IsConnected = true; } else { EventscadaException?.Invoke(GetType().Name, StringResources.Language.ConnectedFailed); } IsConnected = true; return(IsConnected); } catch (Exception ex) { EventscadaException?.Invoke(GetType().Name, ex.Message); return(IsConnected); } } } catch (TimeoutException ex) { IsConnected = false; EventscadaException?.Invoke(GetType().Name, ex.Message); return(IsConnected); } }