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);
            }
        }
Ejemplo n.º 2
0
        // Calls the correct method depending on the current calibration state "State" and
        // adapts respectively the text on the button "Start".
        // The states are start, measure zero, measure calibration weight, close.
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            this.Cursor     = Cursors.WaitCursor;

            //Switch depending on the current calibration step described by State
            switch (_state)
            {
            case 0:     //start

                try
                {
                    //CalibrationWeight = Convert.ToDouble(textBox1.Text, Provider);

                    _strCommaDot       = textBox1.Text.Replace(".", ",");                 // Neu : 12.3 - Für die Umwandlung in eine Gleitkommazahl.
                    _calibrationWeight = double.Parse(_strCommaDot);                      // Damit können Kommata und Punkte eingegeben werden.

                    textBox1.Enabled = false;
                    textBox2.Text    = _calibrationWeight.ToString();
                }
                catch (FormatException)
                {
                    textBox2.Text = "Wrong format!" + Environment.NewLine
                                    + "Only numbers in the form of 123,456,789.0123 allowed!";
                    break;
                }
                catch (OverflowException)
                {
                    textBox2.Text = "Overflow! Number to big.";
                    break;
                }

                textBox2.Text = "Unload Scale!";
                button1.Text  = "Measure Zero";
                button2.Text  = "<Back";
                _state        = 1;
                break;

            case 1:     // measure zero

                button1.Enabled = false;

                textBox2.Text = "Measure zero in progess.";
                Application.DoEvents();

                _wtxObj.MeasureZero();

                textBox2.Text = "Dead load measured." + Environment.NewLine + "Put weight on scale.";
                button1.Text  = "Calibrate";
                _state        = 2;

                break;

            case 2:     // start calibration

                button1.Enabled = false;

                textBox2.Text = "Calibration in progress.";
                Application.DoEvents();

                _wtxObj.Calibrate(this.PotencyCalibrationWeight(), _calibrationWeight.ToString());

                if (_wtxObj.Status == 1 && _wtxObj.Handshake == 0)
                {
                    textBox2.Text = "Calibration successful and finished.";
                }
                else
                {
                    textBox2.Text = "Calibration  failed.";
                }

                button1.Text = "Close";
                _state       = 3;
                break;

            default:     //close window

                button1.Enabled = false;
                _state          = 0;

                Close();
                break;
            }
            button1.Enabled = true;
            this.Cursor     = Cursors.Default;
        }