Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connects to wtx device
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            if (_wtxDevice != null)
            {
                DisplayText("Disconnecting...");
                _wtxDevice.Connection.Disconnect();
                _wtxDevice = null;
            }

            DisplayText("Connecting...");
            this.InitializeConnection();
        }
Ejemplo n.º 3
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.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);
            }
        }
Ejemplo n.º 4
0
 private void ReadDigitalIOFunctions(object sender, IOFunctionEventArgs e)
 {
     /*DDD Todo
      * int out1 = _wtxDevice.DataStandard.Output1;
      * int out2 = _wtxDevice.DataStandard.Output2;
      * int out3 = _wtxDevice.DataStandard.Output3;
      * int out4 = _wtxDevice.DataStandard.Output4;
      * int in1 = _wtxDevice.DataStandard.Input1;
      * int in2 = _wtxDevice.DataStandard.Input2;
      */
     if (this.rbtConnectionModbus.Checked)    // If 'Modbus/Tcp' is selected, disconnect and reconnect from Jetbus to Modbus
     {
         _wtxDevice.Disconnect();
         ModbusTCPConnection _connection = new ModbusTCPConnection(_ipAddress);
         _wtxDevice = new Hbm.Weighing.API.WTX.WTXModbus(_connection, this._timerInterval, this.update);
     }
 }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor of class WeightCalibration
        /// </summary>
        /// <param name="wtxDevice"></param>
        public AdjustmentWeigher(BaseWTDevice wtxDevice)
        {
            this._wtxDevice = wtxDevice;

            InitializeComponent();

            if (!wtxDevice.IsConnected)
            {
                txtCalibrationWeight.Enabled = false;
                cmdAdjust.Enabled            = false;
                cmdCancel.Text = "Close";
                txtInfo.Text   = "No WTX connected!";
            }

            // Get some settings from the connected Device
            _wtxDeviceDecimals = wtxDevice.ProcessData.Decimals;

            lblUnit.Text = wtxDevice.Unit;

            txtInfo.Text = "Enter a calibration weight";
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Constructor of class 'CalcCalibration' : Initialze values
        /// </summary>
        /// <param name="wtxDevice"></param>
        public AdjustmentCalculator(BaseWTDevice wtxDevice)
        {
            this._wtxDevice = wtxDevice;

            _finished = false;
            //Provider for english number format
            _provider = CultureInfo.InvariantCulture;

            _strCommaDot = "";

            InitializeComponent();

            if (!wtxDevice.IsConnected)
            {
                textBox1.Enabled     = false;
                textBox2.Enabled     = false;
                buttonCalculate.Text = "Close";
                _finished            = true;
                label5.Visible       = true;
                label5.Text          = "No WTX connected!";
            }
        }
Ejemplo n.º 9
0
 private void WriteDigitalIOFunctions(object sender, IOFunctionEventArgs e)
 {
     /*DDD Todo
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Output1 = (int)e.FunctionOutputIO1;
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Output2 = (int)e.FunctionOutputIO2;
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Output3 = (int)e.FunctionOutputIO3;
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Output4 = (int)e.FunctionOutputIO4;
      *
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Input1 = (int)e.FunctionInputIO1;
      * if ((int)e.FunctionOutputIO1 != (-1))
      *  _wtxDevice.DataStandard.Input2 = (int)e.FunctionInputIO2;
      */
     if (this.rbtConnectionModbus.Checked)    // If 'Modbus/Tcp' is selected, disconnect and reconnect from Jetbus to Modbus
     {
         _wtxDevice.Disconnect();
         ModbusTCPConnection _connection = new ModbusTCPConnection(_ipAddress);
         _wtxDevice = new Hbm.Weighing.API.WTX.WTXModbus(_connection, this._timerInterval, this.update);
     }
 }
Ejemplo n.º 10
0
        } // End method Connect()

        private static void MenuCases()
        {
            // This while loop is repeated till the user enters 'e' (=e meaning exit). After the timer interval the register of the device is read out.
            // In the while-loop the user can select commands, which are send immediately to the device.
            while (_valueExitapplication.KeyChar != 'e')
            {
                //_isCalibrating = false;
                _valueOutputwords = Console.ReadKey();
                int valueOutput = Convert.ToInt32(_valueOutputwords.KeyChar);

                switch (_valueOutputwords.KeyChar)
                {
                case '0': _wtxDevice.Tare(); break;                          // Taring

                case '1': _wtxDevice.SetGross(); break;                      // Gross/Net

                case '2': _wtxDevice.Zero(); break;                          // Zeroing

                case '3': _wtxDevice.AdjustZeroSignal(); break;              // Adjust zero

                case '4': _wtxDevice.AdjustNominalSignal(); break;           // Adjust nominal

                case '5': _wtxDevice.RecordWeight(); break;                  // Record Weight

                // 'c' for writing on multiple registers, which is necessary for the calibration.
                case 'c':           // Calculate Calibration
                    CalculateCalibration();
                    break;

                case 'w':           // Calculation with weight
                    CalibrationWithWeight();
                    break;

                // Change connection from Jetbus to Modbus or from Modbus to Jetbus:
                case 'j':
                    if (_wtxDevice != null)        // Necessary to check if the object of BaseWtDevice have been created and a connection exists.
                    {
                        _wtxDevice.Connection.Disconnect();
                        _wtxDevice = null;
                    }

                    Thread.Sleep(WAIT_DISCONNECT);         // Wait for 2 seconds till the disconnection request is finished.

                    if (connectiontype == ConnectionType.Modbus)
                    {
                        connectiontype = ConnectionType.Jetbus;
                    }
                    else
                    if (connectiontype == ConnectionType.Jetbus)
                    {
                        connectiontype = ConnectionType.Modbus;
                    }

                    InitializeConnection();
                    break;

                default: break;
                }   // end switch-case

                _valueExitapplication = Console.ReadKey();
                if (_valueExitapplication.KeyChar == 'e')
                {
                    break;
                }
            } // end while
        }     // end method MenuCases()