Ejemplo n.º 1
0
        //Connect device
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            if (_wtxDevice != null)    // Necessary to check if the object of BaseWtDevice have been created and a connection exists.
            {
                if (this.rbtConnectionJet.Checked == true && _wtxDevice.getWTXType == "Jetbus" && txtIPAddress.Text == _wtxDevice.getConnection.IpAddress)
                {
                    return;
                }
                else
                if (this.rbtConnectionModbus.Checked == true && _wtxDevice.getWTXType == "Modbus" && txtIPAddress.Text == _wtxDevice.getConnection.IpAddress)
                {
                    return;
                }
                else
                {
                    _wtxDevice.getConnection.Disconnect();
                    _wtxDevice = null;

                    picNE107.Image          = WTXGUIsimple.Properties.Resources.NE107_DiagnosisPassive;
                    picConnectionType.Image = WTXGUIsimple.Properties.Resources.NE107_DiagnosisPassive;

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

                    txtInfo.Text = "Connecting..." + Environment.NewLine;
                }
            }

            /* Establish a connection in Method InitializeConnection() */
            this.InitializeConnection();
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
        // Constructor of class WeightCalibration:
        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.Decimals;

            switch (wtxDevice.Unit)
            {
            case 0:
                lblUnit.Text = "kg";
                break;

            case 1:
                lblUnit.Text = "g";
                break;

            case 2:
                lblUnit.Text = "t";
                break;

            case 3:
                lblUnit.Text = "lb";
                break;

            default:
                lblUnit.Text = "unit";
                break;
            }

            txtInfo.Text = "Enter a calibration weight";
        }
Ejemplo n.º 5
0
        // Constructor of class 'CalcCalibration' :
        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.º 6
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();
             * }*/
        }
Ejemplo n.º 7
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);

                if (mode == "Modbus" || mode == "modbus")
                {
                    switch (_valueOutputwords.KeyChar)
                    {
                    case '0': _wtxDevice.taring(Write_DataReceived); break;                      // Taring

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

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

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

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

                    case '5': _wtxDevice.activateData(Write_DataReceived); break;                // Activate data

                    case '6': _wtxDevice.manualTaring(Write_DataReceived); break;                // Manual taring

                    case '7': _wtxDevice.recordWeight(Write_DataReceived); 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;

                    case 'a':      // Show all input words in the filler application.
                        if (_showAllInputWords == false)
                        {
                            _showAllInputWords = true;
                            //_wtxDevice.Refreshed = true;
                        }
                        else
                        if (_showAllInputWords == true)
                        {
                            _showAllInputWords = false;
                            //_wtxDevice.Refreshed = true;
                        }
                        break;

                    case 'o':     // Writing of the output words

                        if (_showAllOutputWords == false)
                        {
                            _showAllOutputWords = true;
                            //_wtxDevice.Refreshed = true;
                        }
                        else
                        if (_showAllOutputWords == true)
                        {
                            _showAllOutputWords = false;
                            //_wtxDevice.Refreshed = true;
                        }

                        break;

                    // Change connection from Modbus to Jetbus:
                    case 'j':
                        _wtxDevice.DataUpdateEvent -= Update;       // Delete Callback method 'Update' from the Eventhandler 'DataUpdateEvent'.

                        mode = "Jetbus";

                        if (_wtxDevice != null)        // Necessary to check if the object of BaseWtDevice have been created and a connection exists.
                        {
                            _wtxDevice.getConnection.Disconnect();
                            _wtxDevice = null;
                        }

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

                        InitializeConnection();
                        _wtxDevice.DataUpdateEvent += Update;       // To get updated values from the WTX, use method Update(..).
                        break;


                    default: break;
                    }   // end switch-case
                }

                else
                if (mode == "Jet" || mode == "Jetbus" || mode == "jet" || mode == "jetbus")
                {
                    switch (_valueOutputwords.KeyChar)
                    {
                    case '0': _wtxDevice.taring(Write_DataReceived); break;                      // Taring

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

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

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

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

                    case '5': _wtxDevice.activateData(Write_DataReceived); break;                // Activate data

                    case '6': _wtxDevice.manualTaring(Write_DataReceived); break;                // Manual taring

                    case '7': _wtxDevice.recordWeight(Write_DataReceived); 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:
                    case 'j':

                        _wtxDevice.DataUpdateEvent -= Update;       // Delete Callback method 'Update' from the Eventhandler 'DataUpdateEvent'.

                        mode = "Modbus";

                        if (_wtxDevice != null)        // Necessary to check if the object of BaseWtDevice have been created and a connection exists.
                        {
                            _wtxDevice.getConnection.Disconnect();
                            _wtxDevice = null;
                        }

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

                        InitializeConnection();
                        _wtxDevice.DataUpdateEvent += Update;       // To get updated values from the WTX, use method Update(..).
                        break;

                    default: break;
                    }   // end switch-case
                } // end if

                //int valueOutput = Convert.ToInt32(value_outputwords.KeyChar);
                int value = 0;
                if (valueOutput >= 9)
                {// switch-case for writing the additional output words of the filler application:
                 //InputWriteOutputWordsFiller((ushort)valueOutput, value);
                }

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