예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Newly written IP address from textbox1:

            string _newIPAdress = textBox1.Text;
            string _newUri      = "wss://" + _newIPAdress + ":443/jet/canopen"; // For : -jet 172.19.103.8:443/jet/canopen ; Initialize Jet-Peer to address


            // Initializing an object of JetBusConnection and WtxJet to establish a connection to the WTX device, to read and write values.

            _sConnection = new JetBusConnection(_newUri, "Administrator", "wtx", delegate { return(true); });
            _wtxObj      = new HBM.WT.API.WTX.WtxJet(_sConnection);

            _sConnection.IpAddress = textBox1.Text;

            try
            {
                _sConnection.Connect();
            }
            catch (Exception exc)
            {
                _aTimer.Enabled = false;
                _aTimer.Stop();
                _wtxObj.isConnected = false;
            }
            if (_wtxObj.isConnected)
            {
                InitializeTimerJetbus(_timerInterval);
                _ipAddress = _newIPAdress;
            }
        }
        /// <summary>
        /// Toolstrip Click Event for Digital IO funcion settings: Input & Output functions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (_wtxDevice != null)
            {
                _wtxDevice.Stop();

                if (_wtxDevice.Connection.ConnectionType == ConnectionType.Modbus)
                {
                    _wtxDevice.Disconnect();

                    JetBusConnection _connection = new JetBusConnection(_ipAddress);
                    _wtxDevice = new WTXJet(_connection, 500, update);

                    _wtxDevice.Connect(5000);

                    _functionIOForm = new FunctionIO();

                    _functionIOForm.ReadButtonClicked_IOFunctions  += ReadDigitalIOFunctions;
                    _functionIOForm.WriteButtonClicked_IOFunctions += WriteDigitalIOFunctions;

                    DialogResult res = _functionIOForm.ShowDialog();
                }
                else
                if (_wtxDevice.Connection.ConnectionType == ConnectionType.Jetbus)
                {
                    _functionIOForm = new FunctionIO();

                    _functionIOForm.ReadButtonClicked_IOFunctions  += ReadDigitalIOFunctions;
                    _functionIOForm.WriteButtonClicked_IOFunctions += WriteDigitalIOFunctions;

                    DialogResult res = _functionIOForm.ShowDialog();
                }
                _wtxDevice.Restart();
            }
        }
예제 #3
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;
            }
        }
예제 #4
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()
        /// <summary>
        /// Initialze a Jetbus or Modbus/Tcp connection, creates objects of INetConnection derivations, BaseWtDevice derivations
        /// </summary>
        private void InitializeConnection()
        {
            this._ipAddress = txtIPAddress.Text;

            if (this.rbtConnectionModbus.Checked)
            {
                // Creating objects of ModbusTcpConnection and WTXModbus:
                ModbusTCPConnection _modbusConnection = new ModbusTCPConnection(this._ipAddress);
                _modbusConnection.CommunicationLog += Logger;
                _wtxDevice = new WTXModbus(_modbusConnection, this._timerInterval, this.update);
            }
            else
            {
                if (this.rbtConnectionJet.Checked)
                {
                    // Creating objects of JetBusConnection and WTXJet:
                    JetBusConnection _jetConnection = new JetBusConnection(_ipAddress, "Administrator", "wtx");
                    _jetConnection.CommunicationLog += Logger;

                    _wtxDevice = new WTXJet(_jetConnection, 500, update);
                }
            }

            // Connection establishment via Modbus or Jetbus
            try
            {
                _wtxDevice.Connect(5000);
            }
            catch (Exception)
            {
                DisplayText(MESSAGE_CONNECTION_FAILED);
            }

            if (_wtxDevice.IsConnected)
            {
                picNE107.Image = Properties.Resources.NE107_DiagnosisActive;
                Properties.Settings.Default.IPAddress = this._ipAddress;
                Properties.Settings.Default.IsJetBus  = rbtConnectionJet.Checked;
                Properties.Settings.Default.Save();
            }
            else
            {
                picNE107.Image = Properties.Resources.NE107_DiagnosisPassive;
                DisplayText(MESSAGE_CONNECTION_FAILED);
            }
        }
예제 #6
0
        /// <summary>
        /// Initialze a Jetbus or Modbus/Tcp connection, creates objects of INetConnection derivations, BaseWtDevice derivations
        /// </summary>
        private void InitializeConnection()
        {
            this._ipAddress = txtIPAddress.Text;

            if (this.cboDeviceType.SelectedIndex == 0)
            {
                // Creating objects of JetBusConnection and WTXJet:
                JetBusConnection _jetConnection = new JetBusConnection(_ipAddress, "Administrator", "wtx");
                _wtxDevice = new WTXJet(_jetConnection, 500, update);
            }
            else if (this.cboDeviceType.SelectedIndex == 1)
            {
                // Creating objects of ModbusTcpConnection and WTXModbus:
                ModbusTCPConnection _modbusConnection = new ModbusTCPConnection(this._ipAddress);
                _wtxDevice = new WTXModbus(_modbusConnection, this._timerInterval, this.update);
            }
            else
            {
                // Creating objects of DSEJetConnection:
                DSEJetConnection _jetConnection = new DSEJetConnection(_ipAddress);
                _wtxDevice = new DSEJet(_jetConnection, 500, update);
            }

            // Connection establishment via Modbus or Jetbus
            try
            {
                _wtxDevice.Connect(5000);
            }
            catch (Exception)
            {
                DisplayText(MESSAGE_CONNECTION_FAILED);
            }

            if (_wtxDevice.IsConnected)
            {
                picNE107.Image = GUISimple.Properties.Resources.NE107_DiagnosisActive;
                GUISimple.Properties.Settings.Default.IPAddress  = this._ipAddress;
                GUISimple.Properties.Settings.Default.DeviceType = cboDeviceType.SelectedIndex;
                GUISimple.Properties.Settings.Default.Save();
            }
            else
            {
                picNE107.Image = GUISimple.Properties.Resources.NE107_DiagnosisPassive;
                DisplayText(MESSAGE_CONNECTION_FAILED);
            }
        }
예제 #7
0
        // This method connects to the given IP address
        private static void InitializeConnection()
        {
            if (connectiontype == ConnectionType.Modbus)    // If 'Modbus/Tcp' is selected:
            {
                // Creating objects of ModbusTcpConnection and WTXModbus:
                ModbusTCPConnection _modbusConnection = new ModbusTCPConnection(_ipAddress);

                _wtxDevice = new WTXModbus(_modbusConnection, _timerInterval, Update);
            }
            else
            {
                if (connectiontype == ConnectionType.Jetbus)  // If 'JetBus' is selected:
                {
                    // Creating objects of JetBusConnection and WTXJet:
                    JetBusConnection _jetConnection = new JetBusConnection(_ipAddress, "Administrator", "wtx");

                    _wtxDevice = new WTXJet(_jetConnection, _timerInterval, Update);
                }
            }

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

            if (_wtxDevice.Connection.IsConnected == true)
            {
                //Update(null, null);  // call of callback method to print values on console, even though the measured values did not change.

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

                CommandLine.Properties.Settings.Default.IPaddress = _ipAddress;
                CommandLine.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()
예제 #8
0
        public LiveValue(string[] args)
        {
            InitializeComponent();

            pictureBox1.Image = WTXJetGUISimple.Properties.Resources.NE107_DiagnosisPassive;


            // Setting the connection for jetbus:
            if (args.Length > 0)
            {
                if (args[0] == "modbus" || args[0] == "Modbus")
                {
                    toolStripStatusLabel2.Text = "Modbus";
                }

                if (args[0] == "jet" || args[0] == "Jet")
                {
                    toolStripStatusLabel2.Text = "Jetbus";
                }
            }

            if (args.Length > 1)
            {
                _ipAddress = args[1];

                DEFAULT_IP_ADDRESS = args[1];
                textBox1.Text      = DEFAULT_IP_ADDRESS;
            }
            else
            {
                WTXJetGUISimple.Properties.Settings.Default.Reload();
                _ipAddress    = WTXJetGUISimple.Properties.Settings.Default.IPAddress;
                textBox1.Text = _ipAddress;
            }

            _timerInterval = 200;                 // A default value for the timer interval , 200 ms.

            _uri = "wss://" + _ipAddress;
            _uri = _uri + ":443/jet/canopen";     // For : -jet 172.19.103.8:443/jet/canopen ; Initialize Jet-Peer to address
            // Initializing an object of JetBusConnection and WtxJet to establish a connection to the WTX device, to read and write values.

            _sConnection = new JetBusConnection(_uri, "Administrator", "wtx", delegate { return(true); });
            _wtxObj      = new HBM.WT.API.WTX.WtxJet(_sConnection);

            try
            {
                _sConnection.Connect();
            }
            catch (Exception exc)
            {
                _wtxObj.isConnected = false;
                textBox2.Text       = "Connection failed, enter an other IP address please.";
            }

            pictureBox1.Image = WTXJetGUISimple.Properties.Resources.NE107_DiagnosisActive;  // Check, ob der Verbindungsaufbau erfolgreich war?

            if (_wtxObj.isConnected)
            {
                InitializeTimerJetbus(_timerInterval);
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            _previousNetValue = "";
            _timerInterval    = 500;
            _compareTest      = true;

            Thread thread1 = new Thread(new ThreadStart(InputOutput));

            try {
                switch (args[0])
                {
                case "jet":

                    _ipAddr = "wss://" + args[1];
                    _ipAddr = _ipAddr + ":443/jet/canopen";         // For : -jet 172.19.103.8:443/jet/canopen
                    Console.Write("Initialize Jet-Peer to address " + _ipAddr + "...");

                    _jetConnection = new JetBusConnection(_ipAddr, "Administrator", "wtx", delegate { return(true); });

                    _jetConnection.ConnectOnPeer(5000);
                    _jetConnection.FetchAll();

                    Console.WriteLine("OK");

                    //s_Connection.BusActivityDetection += S_Connection_BusActivityDetection;

                    Console.WriteLine("Parameter are fetching: ");
                    Console.Write((_jetConnection as JetBusConnection).BufferToString());

                    _wtxObj = new HBM.WT.API.WTX.WtxJet(_jetConnection);

                    Console.WriteLine("Parameter fetched");
                    Console.WriteLine("Net value : " + _wtxObj.NetValue);
                    Console.WriteLine("Gross value : " + _wtxObj.GrossValue);
                    Console.WriteLine("Decimals : " + _wtxObj.Decimals);

                    Console.ReadLine();

                    break;

                case "modbus":

                    _ipAddr = args[1];

                    _modbusConnection = new ModbusTcpConnection(_ipAddr);

                    _wtxObj = new HBM.WT.API.WTX.WtxModbus(_modbusConnection, _timerInterval);

                    // Konstruktor neu : Obj. von ModbusTCPConnection, Timer Intervall

                    _previousDataStrArr = new string[59];

                    for (int i = 0; i < 59; i++)
                    {
                        _previousDataStrArr[i] = "0";
                    }

                    // Start asynchronous data transfer : Method - Nur bei einer Änderung Werte ausgeben - Was abrufbar ist aus der Klasse Program zu WTX120_Modbus

                    _wtxObj.getConnection.Connect();         // Alternative : _wtxObj.Connect();

                    //WTXObj.isDataReceived = false;

                    thread1.Start();         // Thread für eine Eingabe. Wenn 'e' eingetippt wurde, wird die Anwendung bzgl. Modbus beendet.

                    //while (value_exitapplication.KeyChar != 'e')        // Solange bis Schleife verlassen wird mit einem Kommando für Exit.
                    //{
                    //    if (WTXObj.isDataReceived == true)      // Weiterer Asynchronener Aufruf eventbasiert
                    //    {
                    //        reset_values_on_console(WTXObj.DeviceValues);
                    //        WTXObj.isDataReceived = false;      // rücksetzen in der GUI.
                    //    }
                    //}

                    //Thread.Sleep(2000);


                    _wtxObj.DataUpdateEvent += AsyncUpdateData;

                    //WTXObj.Shutdown += Handler1;
                    //WTXObj.OnShutdown().Wait();

                    break;
                }


                if (args[0] == "-jet")
                {
                    string[] input = null;
                    do
                    {
                        try
                        {
                            Console.Write(_menuRequest);
                            Console.Write("/> ");
                            input = Console.ReadLine().Split(new char[] { ' ' });

                            if (_funktonSelect.ContainsKey(input[0].ToLower()))
                            {
                                _funktonSelect[input[0].ToLower()](input);
                                Console.ReadLine();
                            }
                            else
                            {
                                Console.WriteLine("Unknown instruction - try again \n");
                            }
                        }
                        catch (Exception operationException)
                        {
                            Console.WriteLine("Exception is thrown: " + operationException.Message);
                            Console.ReadLine();
                            continue;
                        }
                    } while (!input[0].ToUpper().Equals("QUIT"));
                    Console.WriteLine("good bye");
                }
            }
            catch (Exception e) {
                Console.WriteLine("FAILED with error: " + e.Message);
                Console.ReadLine();
            }

            /*
             * catch (Exception e) {
             *  Console.WriteLine("Jetbus:" + e.Message);
             *  Console.ReadLine();
             * }*/
        }