Пример #1
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);
            }
        }
Пример #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;
        }