public bool CalibrationTest(Behavior behavior)
        {
            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");

            WtxModbus WTXModbusObj = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            int testCalibrationValue = 111;

            WTXModbusObj.Calibrate(testCalibrationValue, "111");

            // Check if: write reg 46, CalibrationWeight and write reg 50, 0x7FFFFFFF

            if (
                (testConnection.getArrElement1 == (testCalibrationValue & 0xffff0000) >> 16) &&
                (testConnection.getArrElement2 == (testCalibrationValue & 0x0000ffff)) &&

                (testConnection.getArrElement3 == (0x7FFFFFFF & 0xffff0000) >> 16) &&
                (testConnection.getArrElement4 == (0x7FFFFFFF & 0x0000ffff))
                )
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool LogEventSetTest(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);
            testConnection.IsConnected = true;

            WTXModbusObj.Async_Call(0x00, callbackMethod);

            Thread.Sleep(100);

            if (testConnection._logObj.Args.Equals("Read successful: Registers have been read"))
            {
                return(true);
            }

            else
            if (testConnection._logObj.Args.Equals("Read failed : Registers have not been read"))
            {
                return(false);
            }

            else
            {
                return(false);
            }
            //return WTXModbusObj.ApplicationMode;
        }
Example #3
0
        public bool WriteArrayTestCasesModbus(Behavior behavior)
        {
            bool parameterEqualArrayWritten = false;

            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WtxModbus _wtxObj = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.WriteOutputWordS32(0x7FFFFFFF, 50, Write_DataReceived);

            if ((testConnection.getArrElement1 == (0x7FFFFFFF & 0xffff0000) >> 16) &&
                (testConnection.getArrElement2 == (0x7FFFFFFF & 0x0000ffff)))
            {
                parameterEqualArrayWritten = true;
            }
            else
            {
                parameterEqualArrayWritten = false;
            }

            //Assert.AreEqual(true ,parameterEqualArrayWritten);

            return(parameterEqualArrayWritten);
        }
        public bool CalculateCalibrationTest(Behavior behavior)
        {
            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WtxModbus WTXModbusObj = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            double preload  = 1;
            double capacity = 2;

            double multiplierMv2D = 500000; //   2 / 1000000; // 2mV/V correspond 1 million digits (d)

            double dPreload     = preload * multiplierMv2D;
            double dNominalLoad = dPreload + (capacity * multiplierMv2D);

            WTXModbusObj.Calculate(preload, capacity);

            if (
                (testConnection.getArrElement1 == (Convert.ToInt32(dPreload) & 0xffff0000) >> 16) &&
                (testConnection.getArrElement2 == (Convert.ToInt32(dPreload) & 0x0000ffff)) &&

                (testConnection.getArrElement3 == (Convert.ToInt32(dNominalLoad) & 0xffff0000) >> 16) &&
                (testConnection.getArrElement4 == (Convert.ToInt32(dNominalLoad) & 0x0000ffff)) &&

                WTXModbusObj.getDPreload == dPreload &&
                WTXModbusObj.getDNominalLoad == dNominalLoad
                )
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public void TareAsyncTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.Async_Call(0x1, callbackMethod);

            Assert.AreEqual(0x1, _wtxObj.getCommand);
        }
        public int testHandshake(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            WTXModbusObj.SyncCall(0, 0x1, OnWriteData);

            return(WTXModbusObj.Handshake);
        }
Example #7
0
        public int ResetTimerTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.ResetTimer(500);

            return((int)_wtxObj._aTimer.Interval);
            //Assert.AreEqual(_wtxObj._aTimer.Interval, 500);
        }
Example #8
0
        public void AdjustingNominalMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.adjustNominal(callbackMethod);

            //return _wtxObj.getCommand;
            Assert.AreEqual(0x100, _wtxObj.getCommand);
        }
Example #9
0
        public void ZeroMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.zeroing(callbackMethod);

            //return testConnection.getCommand;
            Assert.AreEqual(0x40, _wtxObj.getCommand);
        }
Example #10
0
        public void AbortDosingMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);
            //_wtxObj.isConnected = true;

            _wtxObj.abortDosing(callbackMethod);

            Assert.AreEqual(0x8, _wtxObj.getCommand);
        }
Example #11
0
        public void ClearDosingResultsMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.clearDosingResults(callbackMethod);

            //return _wtxObj.getCommand;
            Assert.AreEqual(0x4, _wtxObj.getCommand);
        }
Example #12
0
        public void RecordweightMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.recordWeight(callbackMethod);

            //return _wtxObj.getCommand;
            Assert.AreEqual(0x4000, _wtxObj.getCommand);
        }
Example #13
0
        public void /*int*/ ActivateDataMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.activateData(callbackMethod);

            //return _wtxObj.getCommand;
            Assert.AreEqual(0x800, _wtxObj.getCommand);
        }
Example #14
0
        public void ManualRedosingMethodTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.manualReDosing(callbackMethod);

            //return _wtxObj.getCommand;
            Assert.AreEqual(0x8000, _wtxObj.getCommand);
        }
        public string testModbus_WeightMovingStringComment_Case1(Behavior behavior)
        {
            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WtxModbus _wtxObj = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.Async_Call(0x00, OnReadData);
            Thread.Sleep(10);
            //testConnection.ReadRegisterPublishing(new DataEvent(new ushort[58], new string[58]));

            return(_wtxObj.WeightMovingStringComment());
        }
Example #16
0
        // This method is called in the constructor of class LiveValue and establishs a connection.
        private void Connect()
        {
            _modbusObj = new ModbusTcpConnection(this._ipAddress);

            _wtxObj = new WtxModbus(_modbusObj, this._timerInterval);

            _wtxObj.getConnection.NumofPoints = 6;

            _wtxObj.DataUpdateEvent += ValuesOnConsole;

            this.toolStripLabel1.Text = "disconnected";
            button1_Click(this, null);
        }
Example #17
0
        public int WriteTestCasesModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            // Write : Gross/Net
            _wtxObj.Async_Call(0x2, OnWriteData);

            return(testConnection.getCommand);
            // Alternative Assert.AreEqual(0x2, testConnection.getCommand);
        }
Example #18
0
        public int WriteSyncTest(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");

            _wtxObj = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.SyncCall(0, 0x100, callbackMethod);

            return(testConnection.getCommand);
            // Alternative : Assert.AreEqual(0x100, testConnection.getCommand);
        }
        public bool DisconnectTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            Thread.Sleep(1000); // Do something.... and disconnect.

            WTXModbusObj.Disconnect(this.OnDisconnect);

            return(WTXModbusObj.isConnected);
            // Alternative : Assert.AreEqual(WTXModbusObj.isConnected, true);
        }
        public bool ConnectTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            this.connectCallbackCalled = false;

            WTXModbusObj.Connect(this.OnConnect, 100);

            Thread.Sleep(300);

            return(WTXModbusObj.isConnected);
            // Alternative : Assert.AreEqual(this.connectCallbackCalled, true);
        }
Example #21
0
        public bool UpdateOutput1Test(Behavior behavior)
        {
            bool compareDataWritten = false;

            ushort[] _dataWritten = new ushort[2];
            ushort[] _outputData  = new ushort[43];

            for (int i = 0; i < _outputData.Length; i++)
            {
                _outputData[i] = 1;
            }

            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.UpdateOutputWords(_outputData);

            for (int i = 0; i < _outputData.Length; i++)
            {
                _wtxObj.WriteOutputWordS32(_outputData[i], (ushort)(i + 40), callbackMethod);

                _dataWritten[0] = (ushort)((_outputData[i] & 0xffff0000) >> 16);
                _dataWritten[1] = (ushort)(_outputData[i] & 0x0000ffff);

                if (testConnection.getArrElement1 == _dataWritten[0] && testConnection.getArrElement2 == _dataWritten[1] && testGetOutputwords() == true)
                {
                    compareDataWritten = true;
                }
                else
                {
                    compareDataWritten = false;
                }
            }

            _wtxObj.activateData(callbackMethod);

            if (compareDataWritten == true /* && testConnection.getCommand==0x800*/)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
Example #22
0
        public int ApplicationModeTest(Behavior behavior)
        {
            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");

            WtxModbus WTXModbusObj = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            testConnection.Write(0, 0);

            testConnection.Read(0);

            return(testConnection.getData[5] & 0x3 >> 1);

            //return WTXModbusObj.ApplicationMode;
        }
        public void testModbus_NetGrossValueStringComment_6D(Behavior behavior)
        {
            TestModbusTCPConnection testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WtxModbus _wtxObj = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.Async_Call(0x00, OnReadData);
            Thread.Sleep(10);
            //testConnection.ReadRegisterPublishing(new DataEvent(new ushort[58], new string[58]));

            string strValue = _wtxObj.NetGrossValueStringComment(_wtxObj.GrossValue, 6 /*_wtxObj.Decimals*/);
            double dValue   = _wtxObj.GrossValue / Math.Pow(10, 6 /*_wtxObj.Decimals*/);

            Assert.AreEqual(dValue.ToString("0.000000"), strValue);
        }
        // Constructor of class WeightCalibration:
        public WeightCalibration(WtxModbus wtxObj, bool connected)
        {
            this._powCalibrationWeight = 0.0;
            this._potenz = 0.0;

            this._wtxObj = wtxObj;
            _state       = 0;

            _strCommaDot = "";
            //Provider for english number format
            //Provider = CultureInfo.InvariantCulture;

            InitializeComponent();

            if (!connected)
            {
                textBox1.Enabled = false;
                button1.Enabled  = false;
                button2.Text     = "Close";
                textBox2.Text    = "No WTX connected!";
            }

            switch (wtxObj.Unit)
            {
            case 0:
                label2.Text = "kg";
                break;

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

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

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

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

            textBox2.Text = "Enter a calibration weight";
        }
Example #25
0
        public ushort ReadTestModbus(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);
            testConnection.IsConnected = true;

            WTXModbusObj.Async_Call(0x00, callbackMethod);

            Thread.Sleep(100);

            return(WTXModbusObj.GetDataUshort[1]);

            //return (ushort)WTXModbusObj.NetValue;
            // Alternative :Assert.AreEqual(_dataReadSuccess[0], WTXModbusObj.GetDataUshort[0]);
        }
Example #26
0
        // Constructor of class 'CalcCalibration' :
        public CalcCalibration(WtxModbus wtxObj, bool connected)
        {
            this._wtxObj = wtxObj;

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

            _strCommaDot = "";

            InitializeComponent();

            if (!connected)
            {
                textBox1.Enabled     = false;
                textBox2.Enabled     = false;
                buttonCalculate.Text = "Close";
                _finished            = true;
                label5.Visible       = true;
                label5.Text          = "No WTX connected!";
            }
        }
Example #27
0
        public bool WriteU08ArrayTestModbus(Behavior behavior)
        {
            ushort[] _data = new ushort[1];

            _data[0] = (ushort)(0xA1 & 0xFF);

            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.WriteOutputWordU08(0xA1, 1, callbackMethod);

            if (testConnection.getArrElement1 == _data[0] && testConnection.getWordNumber == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #28
0
        public bool WriteS32ArrayTestModbus(Behavior behavior)
        {
            ushort[] _data = new ushort[2];

            _data[0] = (ushort)((0x7FFFFFFF & 0xFFFF0000) >> 16);
            _data[1] = (ushort)(0x7FFFFFFF & 0x0000FFFF);

            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            _wtxObj        = new WtxModbus(testConnection, 200);

            _wtxObj.Connect(this.OnConnect, 100);

            _wtxObj.WriteOutputWordS32(0x7FFFFFFF, 48, Write_DataReceived);

            if (testConnection.getArrElement1 == _data[0] && testConnection.getArrElement2 == _data[1] &&
                testConnection.getWordNumber == 48)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #29
0
        public bool MeasureZeroTest(Behavior behavior)
        {
            testConnection = new TestModbusTCPConnection(behavior, "172.19.103.8");
            WTXModbusObj   = new WtxModbus(testConnection, 200);

            WTXModbusObj.Connect(this.OnConnect, 100);

            WTXModbusObj.MeasureZero();

            WTXModbusObj.Async_Call(0x00, OnReadData);

            //check if : write reg 48, 0x7FFFFFFF and if Net and gross value are zero.

            if ((testConnection.getArrElement1 == (0x7FFFFFFF & 0xffff0000) >> 16) &&
                (testConnection.getArrElement2 == (0x7FFFFFFF & 0x0000ffff)) &&
                WTXModbusObj.NetValue == 0 && WTXModbusObj.GrossValue == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }