Пример #1
0
        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);
            }
        }
Пример #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     // 断开连接
     xGBCnet.Close( );
     button2.Enabled = false;
     button1.Enabled = true;
     panel2.Enabled  = false;
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public void Disconnection()
        {
            try
            {
                xGBCnet.Close();

                IsConnected = false;
            }
            catch (TimeoutException ex)
            {
                EventscadaException?.Invoke(this.GetType().Name, ex.Message);
            }
        }
Пример #5
0
 public bool Disconnection()
 {
     try
     {
         xGBCnet.Close();
         IsConnected = false;
         return(IsConnected);
     }
     catch (TimeoutException ex)
     {
         EventscadaException?.Invoke(GetType().Name, ex.Message);
         return(IsConnected);
     }
 }
Пример #6
0
        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);
            }
        }