コード例 #1
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);
     }
 }
コード例 #2
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);
            }
        }
コード例 #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.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);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: leistner/Automation-API
        // 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()
コード例 #5
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);
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: sindar/MBTCPMemTestConsole
        static void Main(string[] args)
        {
            if (args.Length < 1 || args.Length > 4)
            {
                Console.WriteLine("Неправильно указаны параметры запуска программы.");
                Console.WriteLine("<Файл_программы> <ip-адрес сервера> (кол-во потоков) (кол-во запросов) (чтение(0)/запись(1))");
                return;
            }

            try
            {
                MBTCPServerIP = IPAddress.Parse(args[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Неправильно задан ip-адрес ModBusTCP-сервера.");
                return;
            }

            if (args.Length >= 2)
            {
                try
                {
                    sockNum = Convert.ToByte(args[1]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Неверно задано количество потоков.");
                    return;
                }
            }
            else
            {
                sockNum = 1;
            }

            if (args.Length >= 3)
            {
                try
                {
                    queryNum = Convert.ToInt16(args[2]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Неверно задано количество запросов.");
                    return;
                }
            }
            else
            {
                queryNum = 1;
            }

            if (args.Length == 4)
            {
                try
                {
                    queryType = Convert.ToByte(args[3]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Неверно задан тип запросов.");
                    return;
                }
            }
            else
            {
                queryType = 0;
            }

            ModbusTCPConnection.QueryNum = queryNum;


            MBTCPconnections = new ModbusTCPConnection[sockNum];

            for (byte i = 0; i < sockNum; ++i)
            {
                MBTCPconnections[i] = new ModbusTCPConnection(MBTCPServerIP);
                Thread t = new Thread(new ParameterizedThreadStart(ThreadMBTCPRor));
                t.Start(i);
            }

            Console.ReadLine();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: sindar/MBTCPMemTestConsole
        private static void ThreadMBTCPRor(object number)
        {
            //ReadHoldingRegs(UInt16 baseRegister, UInt16 number)
            byte[] ReadData;
            int    index        = Convert.ToInt16(number);
            UInt16 baseRegister = Convert.ToUInt16(index * 1000 + 11000);
            UInt16 quantity     = 100;
            UInt16 TrID         = baseRegister;
            UInt16 CheckValue;

            byte[] WriteData = new byte[200];
            for (byte i = 0; i < 200; ++i)
            {
                WriteData[i] = i;
            }

            int j = 0;

            for (; ;)
            {
                ++j;
                if (MBTCPconnections[index].GetState())
                {
                    if (queryType != 0)
                    {
                        ReadData = MBTCPconnections[index].PresetMultipleRegs(baseRegister, quantity, WriteData);
                    }
                    else
                    {
                        ReadData = MBTCPconnections[index].ReadHoldingRegs(baseRegister, quantity, TrID);
                    }

                    if (ReadData != null)
                    {
                        Thread.Sleep(50);
                    }
                    else
                    {
                        Thread.Sleep(100);
                        DateTime dt = DateTime.Now;
                        //Console.WriteLine("Restarting socket connection...", dt, dt.Millisecond);
                        Console.WriteLine("Thread sleep for 100 milliseconds...", dt, dt.Millisecond);
                        //MBTCPconnections[index].Close();
                        //MBTCPconnections[index] = new ModbusTCPConnection(MBTCPServerIP);
                    }

                    /*
                     * CheckValue = Convert.ToUInt16((ReadData[9] << 8) | ReadData[10]);
                     * if (CheckValue != baseRegister)
                     * {
                     *  DateTime dt = DateTime.Now;
                     *  Console.WriteLine("Value = {0} => baseRegister = {1}, trID = {2}", CheckValue, baseRegister, TrID);
                     *  Console.WriteLine("Error time: {0}.{1}", dt, dt.Millisecond);
                     *  //Thread.Sleep(10);
                     * }*/
                }
                else
                {
                    Thread.Sleep(1000);
                    DateTime dt = DateTime.Now;
                    Console.WriteLine("Restarting socket connection...", dt, dt.Millisecond);
                    MBTCPconnections[index].Close();
                    MBTCPconnections[index] = new ModbusTCPConnection(MBTCPServerIP);
                }
            }
        }