예제 #1
0
        /// <summary>
        /// 串口读写3190-7
        /// </summary>
        public void ControlComm31907()
        {
            byte[] recb;
            string disresult = "";
            //switch (weightType)
            //{
            //    case "3190": //仪表类型为“3190”,读写入参数格式。
            do
            {
                if (hComm7 != -1)
                {
                    //if (commThread.IsAlive)
                    Thread.Sleep(150);

                    if (commMethod == "setzero")
                    {
                        WriteBufferBytes = StringToByte(comm3190ZeroString);
                        Write(WriteBufferBytes, hComm7);
                        commMethod = "read";

                    }
                    else
                    {
                        WriteBufferBytes = StringToByte(comm3190ReadString);
                    }
                    try
                    {
                        //发送读数据命令。
                        Write(WriteBufferBytes, hComm7);
                        //读取串口数据。
                        recb = Read(80, hComm7);
                        if (recb.Length > 0)
                        {
                            disresult = dis(recb, recb.Length, 4, 6, 3, 10, true);
                            if (disresult != "")
                                try
                                {
                                    weightPhyNum7 = Convert.ToDouble(disresult);
                                }
                                catch (Exception ex)
                                {
                                    ErrorMsg = "读取数据格式错误!" + ex.Message;
                                }
                        }
                    }
                    catch
                    {
                        ErrorMsg = "发送失败!";
                    }

                    if (weightPhyNum7 != 0)
                    {
                        commCount7 += 1;
                        if (commCount7 >= 1000000)
                        {
                            commCount7 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, weightPhyNum3, weightPhyNum4, weightPhyNum5,
                         weightPhyNum6, weightPhyNum7, weightPhyNum8, weightPhyNum9, weightPhyNum10, commCount1, commCount2, commCount3, commCount4, commCount5,
                         commCount6, commCount7, commCount8, commCount9, commCount10);
                        NumReceived(null, e);

                    }

                    //PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    PurgeComm(hComm7, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                }

            } while (commThreadAlive7);
        }
예제 #2
0
 private void NumResult9(object sender, NumberReceivedEventArgs e)
 {
     bfzl9 = e.WeightPhyNum9.ToString("#0.00");
     if (strJLDID == "K09")
     {
         txtXSZL.Text = bfzl9;
     }
     if (e.WeightPhyNum9 > 0.1)
     {
         ultraGrid2.Rows[index9].Cells[1].Appearance.BackColor = Color.Red;
     }
     if (e.WeightPhyNum9 < 0.1)
     {
         ultraGrid2.Rows[index9].Cells[1].Appearance.BackColor = Color.Red;
     }
 }
예제 #3
0
        /// <summary>
        /// 串口读写CFC-100
        /// </summary>
        public void ControlCommCFC()
        {
            byte[] recb;
            string disresult = "";
            do
            {
                if (hComm6 != -1)
                {
                    if (commMethod == "setzero")
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                        Write(WriteBufferBytes, hComm6);
                        commMethod = "read";
                    }
                    else
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                    }
                    //发送读数据命令。
                    Write(WriteBufferBytes, hComm6);
                    //读取串口数据。
                    recb = Read(200, hComm6);
                    if (recb.Length > 0)
                    {
                        DisCFCWeightData(recb, ref weightPhyNum6, ref CFCMVResult);
                    }
                    else
                    {
                        ErrorMsg = "读取失败!";
                    }

                    if (inResult != 0 || weightPhyNum6 != 0)
                    {
                        commCount6 += 1;
                        if (commCount6 >= 1000000)
                        {
                            commCount6 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, weightPhyNum3, weightPhyNum4, weightPhyNum5,
                         weightPhyNum6, weightPhyNum7, weightPhyNum8, weightPhyNum9, weightPhyNum10, commCount1, commCount2, commCount3, commCount4, commCount5,
                         commCount6, commCount7, commCount8, commCount9, commCount10);
                        NumReceived(null, e);

                    }
                    //PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    PurgeComm(hComm6, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    //if (commThread.IsAlive)
                    Thread.Sleep(150);
                }

            } while (commThreadAlive6);
        }
예제 #4
0
        private void NumResult6(object sender, NumberReceivedEventArgs e)
        {
            bfzl6 = e.WeightPhyNum6.ToString("#0.00");
            if (strJLDID == "K06")
            {
                txtXSZL.Text = bfzl6;
            }
            if (e.WeightPhyNum6 > 0.1)
            {
                ultraGrid2.Rows[index6].Cells[1].Appearance.BackColor = Color.Red;
            }
            if (e.WeightPhyNum6 < 0.1)
            {
                ultraGrid2.Rows[index6].Cells[1].Appearance.BackColor = Color.White;
            }

            double ybcjzl1 = Convert.ToDouble(bfzl6);
            double ybcjzl2 = 0;
            Thread.Sleep(300);
            if (e.WeightPhyNum6 != ybcjzl1)
            {
                ybcjzl2 = e.WeightPhyNum6;
                if (ybcjzl2 - ybcjzl1 < 0.1)
                {
                    y6 = y6 + 1;
                }
            }
            if (y6 == 6)
            {
                sYBZL6 = e.WeightPhyNum6.ToString("#0.00");
                y6 = 0;
            }
        }
예제 #5
0
 private void NumResult7(object sender, NumberReceivedEventArgs e)
 {
     bfzl7 = e.WeightPhyNum7.ToString("#0.00");
     if (strJLDID == "K07")
     {
         txtXSZL.Text = (e.WeightPhyNum7 / 1000).ToString("#0.000");
     }
     if (e.WeightPhyNum7 > 0.1)
     {
         ultraGrid2.Rows[index7].Cells[1].Appearance.BackColor = Color.Red;
     }
     if (e.WeightPhyNum7 < 0.1)
     {
         ultraGrid2.Rows[index6].Cells[1].Appearance.BackColor = Color.White;
     }
 }
예제 #6
0
        private void NumResult4(object sender, NumberReceivedEventArgs e)
        {
            bfzl4 = e.WeightPhyNum4.ToString("#0.00");
            if (strJLDID == "K04")
            {
                txtXSZL.Text = bfzl4;
            }
            if (e.WeightPhyNum4 > 0.1)
            {
                ultraGrid2.Rows[index4].Cells[1].Appearance.BackColor = Color.Red;
            }
            if (e.WeightPhyNum4 < 0.1)
            {
                ultraGrid2.Rows[index4].Cells[1].Appearance.BackColor = Color.White;
            }

            //double t = e.CommCount;
            int y = 0;
            double ybcjzl1 = e.WeightPhyNum4;
            double ybcjzl2 = 0;
            //Thread.Sleep(300);
            if (e.WeightPhyNum4 != ybcjzl1)
            {
                ybcjzl2 = e.WeightPhyNum4;
                if (ybcjzl2 - ybcjzl1 < 0.1)
                {
                    y4 = y4 + 1;
                }
            }
            if (y4 == 6)
            {
                sYBZL4 = e.WeightPhyNum4.ToString("#0.00");
            }
        }
예제 #7
0
        private void NumResult2(object sender, NumberReceivedEventArgs e)
        {
            bfzl2 = e.WeightPhyNum2.ToString("#0.00");
            if (strJLDID == "K02")
            {
                txtXSZL.Text = bfzl2;
            }
            if (e.WeightPhyNum2 > 0.1)
            {
                ultraGrid2.Rows[index2].Cells[1].Appearance.BackColor = Color.Red;
            }
            if (e.WeightPhyNum2 < 0.1)
            {
                ultraGrid2.Rows[index2].Cells[1].Appearance.BackColor = Color.White;
            }

            //判断6次重量之差都小于20Kg,点击计量点后,系统自动读数
            //int t = e.CommCount2;
            //y2 = t;
            //double ybcjzl1 = Convert.ToDouble(bfzl2);
            //double ybcjzl2 = 0;
            //Thread.Sleep(300);
            //if (e.CommCount2 != t)
            //{
            //    ybcjzl2 = e.WeightPhyNum2;
            //    if (ybcjzl2 - ybcjzl1 < 5.1)
            //    {
            //        y2 = y2 + 1;
            //    }
            //}
            //if (y2 == 6)
            //{
            //    sYBZL2 = e.WeightPhyNum2.ToString("#0.00");
            //}
            double ybcjzl1 = Convert.ToDouble(bfzl2);
            double ybcjzl2 = 0;
            Thread.Sleep(300);
            if (e.WeightPhyNum2 != ybcjzl1)
            {
                ybcjzl2 = e.WeightPhyNum2;
                if (ybcjzl2 - ybcjzl1 < 0.1)
                {
                    y2 = y2 + 1;
                }
            }
            if (y2 == 6)
            {
                sYBZL2 = e.WeightPhyNum2.ToString("#0.00");
                y2 = 0;
            }
        }
예제 #8
0
 private void NumResult10(object sender, NumberReceivedEventArgs e)
 {
     bfzl10 = e.WeightPhyNum10.ToString("#0.00");
     if (strJLDID == "K10")
     {
         txtXSZL.Text = bfzl10;
     }
     if (e.WeightPhyNum10 > 0.1)
     {
         ultraGrid2.Rows[index10].Cells[1].Appearance.BackColor = Color.Red;
     }
     if (e.WeightPhyNum10 < 0.1)
     {
         ultraGrid2.Rows[index10].Cells[1].Appearance.BackColor = Color.Red;
     }
 }
예제 #9
0
        private void NumResult(object sender, NumberReceivedEventArgs e)
        {
            txtXSZL.Text = e.WeightPhyNum1.ToString("#0.00");

            //this.textBox1.Text = mycom1.CommCount.ToString();
            string xszl = txtXSZL.Text;
            string[] ss = xszl.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); //以小数点分割采集重量数据 "A|B|:|C:D"变ss[0]: A|B,ss[1]: C:D //把点改为“|:|”分割
            string[] zz = xszl.Split(".".ToCharArray()); //以小数点分割采集重量数据 "A|B|:|C:D"变zz[0]: A,zz[1]: B,zz[2]: ,zz[3]: ,zz[4]: C,zz[5]: D //用"|:|"分割
            string intzl = ss[0];
            int lenth = intzl.Length;
            cjzl = intzl.Substring(lenth - 1);
        }
예제 #10
0
 private void mycom9_NumReceived(object sender, NumberReceivedEventArgs e)
 {
     NumReceivedEvent fc = new NumReceivedEvent(NumResult9);
     this.Invoke(fc, new object[] { null, e });
 }