Exemple #1
0
        // This method connects to the given IP address
        private void InitializeConnection()
        {
            txtInfo.Text    = "Connecting...";
            this._ipAddress = txtIPAddress.Text;

            if (this.rbtConnectionModbus.Checked)    // If 'Modbus/Tcp' is selected:
            {
                // Creating objects of ModbusTcpConnection and WTXModbus:
                ModbusTcpConnection _modbusConnection = new ModbusTcpConnection(this._ipAddress);

                _wtxDevice = new WtxModbus(_modbusConnection, this._timerInterval);
            }
            else
            {
                if (this.rbtConnectionJet.Checked)  // If 'JetBus' is selected:
                {
                    // Creating objects of JetBusConnection and WTXJet:
                    JetBusConnection _jetConnection = new JetBusConnection(_ipAddress, "Administrator", "wtx");

                    _wtxDevice = new WtxJet(_jetConnection);
                }
            }

            // Connection establishment via Modbus or Jetbus :
            try
            {
                _wtxDevice.Connect();
            }
            catch (Exception)
            {
                txtInfo.Text = MESSAGE_CONNECTION_FAILED;
            }

            if (_wtxDevice.isConnected == true)
            {
                if (this.rbtConnectionJet.Checked)
                {
                    picConnectionType.Image = WTXGUIsimple.Properties.Resources.jet_symbol;
                }
                if (this.rbtConnectionModbus.Checked)
                {
                    picConnectionType.Image = WTXGUIsimple.Properties.Resources.modbus_symbol;
                }

                picNE107.Image = WTXGUIsimple.Properties.Resources.NE107_DiagnosisActive;

                _wtxDevice.DataUpdateEvent += Update;

                this.Update(this, null);
            }
            else
            {
                picNE107.Image = WTXGUIsimple.Properties.Resources.NE107_DiagnosisPassive;
                txtInfo.Text   = MESSAGE_CONNECTION_FAILED;
            }
        }
Exemple #2
0
        // This method connects to the given IP address
        private static void InitializeConnection()
        {
            if (mode == "Modbus" || mode == "modbus")    // If 'Modbus/Tcp' is selected:
            {
                // Creating objects of ModbusTcpConnection and WTXModbus:
                ModbusTcpConnection _modbusConection = new ModbusTcpConnection(_ipAddress);

                _wtxDevice = new WtxModbus(_modbusConection, _timerInterval);

                _wtxDevice.getConnection.NumofPoints = 6;
            }
            else
            {
                if (mode == "Jet" || mode == "jet" || mode == "Jetbus" || mode == "jetbus")  // If 'JetBus' is selected:
                {
                    // Creating objects of JetBusConnection and WTXJet:
                    JetBusConnection _jetConnection = new JetBusConnection(_ipAddress, "Administrator", "wtx");

                    _wtxDevice = new WtxJet(_jetConnection);
                }
            }

            // Connection establishment via Modbus or Jetbus :
            try
            {
                _wtxDevice.Connect();
            }
            catch (Exception)
            {
                Console.WriteLine(MESSAGE_CONNECTION_FAILED);
            }


            if (_wtxDevice.getConnection.IsConnected == true)
            {
                // Coupling the data via an event-based call - If the event in class WTX120_Modbus is triggered, the values are updated on the console: Already done in main for presentation.
                //_wtxDevice.DataUpdateEvent += Update;

                Update(null, null);

                Console.WriteLine("\nThe connection has been established successfully.\nThe values of the WTX device are printed on the console ... :");

                WTXModbusExamples.Properties.Settings.Default.IPaddress = _ipAddress;
                WTXModbusExamples.Properties.Settings.Default.Save();
            }
            else
            {
                Console.WriteLine(MESSAGE_CONNECTION_FAILED);
                Console.WriteLine("\nFailure : The connection has not been established successfully.\nPlease enter a correct IP Adress for the connection establishment...");
                _ipAddress = Console.ReadLine();
            }
        } // End method Connect()