예제 #1
0
 private void frmRead_FormClosing(object sender, FormClosingEventArgs e)
 {
     ModbusScan.Stop();
     CalibrScan.Stop();
     serialPort1.Close();
     MMaster.Disconnection();
 }
예제 #2
0
        private void frmRead_Load(object sender, EventArgs e)
        {
            serialPort1.Close();

            if (PublicVar.TestEnd1 == false && PublicVar.TestEnd2 == false)
            {
                c = PublicVar.Counter1;
                Course = Convert.ToInt32(PublicVar.Course1);
                TestStep = 1;
            }
            else if (PublicVar.TestEnd1 == true && PublicVar.TestEnd2 == false)
            {
                c = PublicVar.Counter2;
                Course = Convert.ToInt32(PublicVar.Course2);
                TestStep = 2;
            }
            else if (PublicVar.TestEnd1 == false && PublicVar.TestEnd2 == true)
            {
                c = PublicVar.Counter1;
                Course = Convert.ToInt32(PublicVar.Course1) * 2;
                TestStep = 3;
            }
            else if (PublicVar.TestEnd1 && PublicVar.TestEnd2)
            {
                MessageBox.Show("End Test");
                Close();
            }

            txtProgramID.EditValue = PublicVar.ProgramID;
            DateStart.DateTime = PublicVar.DateTest;
            txtDiscription.EditValue = PublicVar.Discription_program;

            txtforce1.EditValue = PublicVar.Force1 + "kg";
            txtCounter1.EditValue = PublicVar.Counter1;
            txtCourse1.EditValue = PublicVar.Course1;
            txtDimension1.EditValue = PublicVar.Dimension1 + "mm";

            txtForce2.EditValue = PublicVar.Force2 + "kg";
            txtCounter2.EditValue = PublicVar.Counter2;
            txtCourse2.EditValue = PublicVar.Course2;
            txtDimension2.EditValue = PublicVar.Dimension2 + "mm";



            PublicVar.LoadCell1OK = PublicVar.LoadCell2OK = false;
            btnRead.Enabled = simpleButton1.Enabled = true;
            try
            {
                MMaster = new ModbusASCIIMaster(PublicVar.ConnPortWieght, 9600, 7, System.IO.Ports.StopBits.One, System.IO.Ports.Parity.Even);
                MMaster.Connection();
                MMaster.WriteSingleCoil(1, 3120, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ModbusScan.Stop();
            }
        }
예제 #3
0
 private void simpleButton1_Click_1(object sender, EventArgs e)
 {
     ModbusScan.Stop();
     PublicVar.LoadCell1OK = false;
     PublicVar.LoadCell2OK = false;
     btnRead.Enabled = false;
     simpleButton1.Enabled = false;
     MMaster.WriteSingleCoil(1, 3120, false);
     MMaster.WriteSingleCoil(1, 1281, true);
     Thread.Sleep(2000);
     MMaster.WriteSingleCoil(1, 1281, false);
     CalibrScan.Start();
 }
예제 #4
0
 private void Stop()
 {
     ModbusScan.Stop();
     PublicVar.LoadCell1OK = false;
     PublicVar.LoadCell2OK = false;
     btnRead.Enabled = false;
     simpleButton1.Enabled = false;
     MMaster.WriteSingleCoil(1, 3120, false);
     MMaster.WriteSingleCoil(1, 1281, true);
     Thread.Sleep(2000);
     MMaster.WriteSingleCoil(1, 1281, false);
     MMaster.Disconnection();
 }
예제 #5
0
        //////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

        private void ModbusScan_Tick(object sender, EventArgs e)
        {
            watch.Start();
            mmstart = true;
            if (c == Course)
            {
                ModbusScan.Stop();
                if (TestStep == 1)
                {
                    PublicVar.TestEnd1 = true;
                    db.Database.ExecuteSqlCommandAsync("UPDATE CTest.dbo.ProgramMain SET Counter1 =" + c + " ,TestEnd1 = 1 WHERE id =" + PublicVar.ProgramID);
                    Stop();
                    MessageBox.Show("The test was completed with course" + PublicVar.Course1 + "and tensile strength of" + PublicVar.Force1 + "kg", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
                else if (TestStep == 2)
                {
                    db.Database.ExecuteSqlCommand("UPDATE CTest.dbo.ProgramMain SET Counter2 =" + c + ",TestEnd2 = 1 WHERE id =" + PublicVar.ProgramID);
                    db.Database.ExecuteSqlCommand("UPDATE CTest.dbo.ProgramMain SET TestEnd1 = 0 WHERE id =" + PublicVar.ProgramID);
                    Stop();
                    MessageBox.Show("The test was completed with course" + PublicVar.Course2 + "and tensile strength of" + PublicVar.Force2 + "kg", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    PublicVar.TestEnd2 = true;
                    MessageBox.Show("The settings for the second test step apply to change the spring", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
                else if (TestStep == 3)
                {
                    db.Database.ExecuteSqlCommand("UPDATE CTest.dbo.ProgramMain SET Counter1 =" + c + ",TestEnd1 = 1 WHERE id =" + PublicVar.ProgramID);
                    Stop();
                    MessageBox.Show("The test was completed with course" + PublicVar.Course2 + "and tensile strength of" + PublicVar.Force2 + "kg", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
            }

            try
            {

                byte[] bytes = MMaster.ReadHoldingRegisters(2, 231, 4);
                for (int i = 0, j = 1; i < bytes.Length;)
                {
                    byte TempA = bytes[j];  // B
                    bytes[j] = bytes[i]; // B <= A
                    bytes[i] = TempA; //  A<= B
                    i += 2;
                    j += 2;
                }
                float valueff2 = BitConverter.ToSingle(bytes, 4); // لودسل سمت فنر
                int x2 = (int)valueff2;   //
                txtLoadcell1.Text = string.Format("{0},    ", valueff2);
                if (Enumerable.Range(105, 105).Contains(x2))// && x2 > Convert.ToInt32(PublicVar.Force2) + 10)
                {
                    watch.Stop();
                    txtTime.Text = watch.Elapsed.ToString();
                    watch.Reset();
                    c++;
                    PrcLoadCell(valueff2);
                    Thread.Sleep(1000);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error  ModBusScan", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ModbusScan.Stop();
            }
        }