Example #1
0
        public void ControlComm814201(bool bLx)
        {
            byte[] recb;
            string disresult = "";

            do
            {
                try
                {
                    if (hComm1 != -1)
                    {
                        //if (commThread.IsAlive)
                        Thread.Sleep(50);

                        //读取串口数据。
                        recb = Read(200, hComm1);
                        if (recb.Length > 0)
                        {
                            disresult = dis(recb, recb.Length, 67, 6, 0, 0, false);
                            if (disresult != "")
                            {
                                try
                                {
                                    weightPhyNum1 = Convert.ToDouble(disresult);
                                }
                                catch (Exception ex)
                                {
                                    ErrorMsg = "读取数据格式错误!" + ex.Message;
                                }
                            }
                        }
                        else
                        {
                            ErrorMsg = "读取失败!";
                        }
                    }
                }
                catch
                {
                    ErrorMsg = "读取失败!";
                }

                if (weightPhyNum1 != 0)
                {
                    commCount1 += 1;
                    if (commCount1 >= 1000000)
                    {
                        commCount1 = 0;
                    }
                }
                if (NumReceived != null)
                {
                    NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                    NumReceived(null, e);
                }
                PurgeComm(hComm1, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
            } while (commThreadAlive1);
        }
Example #2
0
        /// <summary>
        /// 串口读写CFC-100
        /// </summary>
        public void ControlCommCFC()
        {
            byte[] recb;
            do
            {
                if (hComm1 != -1)
                {
                    if (commMethod == "setzero")
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                        Write(WriteBufferBytes, hComm1);
                        commMethod = "read";
                    }
                    else
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                    }
                    //发送读数据命令。
                    Write(WriteBufferBytes, hComm1);
                    //读取串口数据。
                    recb = Read(200, hComm1);
                    if (recb.Length > 0)
                    {
                        DisCFCWeightData(recb, ref weightPhyNum1, ref CFCMVResult);
                    }
                    else
                    {
                        ErrorMsg = "读取失败!";
                    }


                    if (inResult != 0 || weightPhyNum1 != 0)
                    {
                        commCount1 += 1;
                        if (commCount1 >= 1000000)
                        {
                            commCount1 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);
                    }
                    //PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    PurgeComm(hComm2, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    //if (commThread.IsAlive)
                    Thread.Sleep(150);
                }
            } while (commThreadAlive1);
        }
Example #3
0
        /// <summary>
        /// 串口读写CFC-100
        /// </summary>
        public void ControlCommCFC()
        {
            byte[] recb;
            do
            {
                if (hComm1 != -1)
                {
                    if (commMethod == "setzero")
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                        Write(WriteBufferBytes, hComm1);
                        commMethod = "read";
                    }
                    else
                    {
                        WriteBufferBytes = StringToByte(commCFC100ReadString);
                    }
                    //发送读数据命令。
                    Write(WriteBufferBytes, hComm1);
                    //读取串口数据。
                    recb = Read(200, hComm1);
                    if (recb.Length > 0)
                    {
                        DisCFCWeightData(recb, ref weightPhyNum1, ref CFCMVResult);
                    }
                    else
                    {
                        ErrorMsg = "读取失败!";
                    }


                    if (inResult != 0 || weightPhyNum1 != 0)
                    {
                        commCount1 += 1;
                        if (commCount1 >= 1000000)
                        {
                            commCount1 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);

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

            } while (commThreadAlive1);
        }
Example #4
0
        public void ControlComm814201(bool bLx)
        {
            byte[] recb;
            string disresult = "";
            do
            {
                try
                {
                    if (hComm1 != -1)
                    {
                        //if (commThread.IsAlive)
                        Thread.Sleep(50);

                        //读取串口数据。
                        recb = Read(200, hComm1);
                        if (recb.Length > 0)
                        {
                            disresult = dis(recb, recb.Length, 67, 6, 0, 0, false);
                            if (disresult != "")
                                try
                                {
                                    weightPhyNum1 = Convert.ToDouble(disresult);
                                }
                                catch (Exception ex)
                                {
                                    ErrorMsg = "读取数据格式错误!" + ex.Message;
                                }
                        }
                        else
                        {
                            ErrorMsg = "读取失败!";
                        }
                    }
                }
                catch
                {
                    ErrorMsg = "读取失败!";
                }

                if (weightPhyNum1 != 0)
                {
                    commCount1 += 1;
                    if (commCount1 >= 1000000)
                    {
                        commCount1 = 0;
                    }
                }
                if (NumReceived != null)
                {
                    NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                    NumReceived(null, e);

                }
                PurgeComm(hComm1, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
            } while (commThreadAlive1);
        }
Example #5
0
        /// <summary>
        /// 串口读写3190-2
        /// </summary>
        /// 命令行方式
        public void ControlComm3190()
        {
            byte[] recb;
            string disresult = "";
            //switch (weightType)
            //{
            //    case "3190": //仪表类型为“3190”,读写入参数格式。
            do
            {
                if (hComm2 != -1)
                {
                    //if (commThread.IsAlive)
                    //Thread.Sleep(150);

                    //连续方式
                    if (!bDataSend)
                    {
                        if (commMethod == "setzero")
                        {
                            WriteBufferBytes = StringToByte(comm3190ZeroString);
                            Write(WriteBufferBytes, hComm2);
                            commMethod = "read";

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

                    if (weightPhyNum2 != 0)
                    {
                        commCount2 += 1;
                        if (commCount2 >= 1000000)
                        {
                            commCount2 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);

                    }

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

            } while (commThreadAlive2);
        }
Example #6
0
        public void ControlCommXK2001b()
        {
            bool bGet = false;
            byte[] recb;
            double doubTmp = 0;

            do
            {
                if (hComm1 != -1)
                {
                    string disTmp = "";
                    try
                    {
                        //读取串口数据。
                        recb = Read(27, hComm1);
                        if (recb.Length > 0)
                        {
                            int j = 0;
                            for (int i = 0; i < 26; i++)
                            {
                                if ((recb[i] == 2) && (!bGet))
                                {
                                    bGet = true;
                                    continue;
                                }

                                if ((recb[i] == 2) && (bGet))
                                {
                                    bGet = false;
                                    break;
                                }

                                if (bGet)
                                {
                                    if ((recb[i] - 48) < 0)
                                    {
                                        disTmp += 0;
                                    }
                                    else
                                    {
                                        disTmp += recb[i] - 48;
                                    }
                                    j++;
                                    if (j == 12) break;
                                }
                            }

                            char[] mychars = disTmp.ToCharArray();
                            //Array.Reverse(mychars);
                            disTmp = mychars[1].ToString() + mychars[2].ToString() + mychars[3].ToString() + "." + mychars[4].ToString() + mychars[5].ToString() + mychars[6].ToString();
                            doubTmp = Convert.ToDouble(disTmp);

                            if (mychars[0] == 45)
                                doubTmp = doubTmp * -1;
                            else
                            {
                                doubTmp = doubTmp * 1;
                            }

                            try
                            {
                                weightPhyNum1 = doubTmp;
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg = "读取数据格式错误!" + ex.Message;
                            }
                        }
                    }
                    catch
                    {
                        ErrorMsg = "发送失败!";
                    }

                    if (weightPhyNum1 != 0)
                    {
                        commCount1 += 1;
                        if (commCount1 >= 1000000)
                        {
                            commCount1 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);

                    }

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

            } while (commThreadAlive1);
        }
Example #7
0
        /// <summary>
        /// 串口读写3190-2
        /// </summary>
        /// 命令行方式
        public void ControlComm3190()
        {
            byte[] recb;
            string disresult = "";

            //switch (weightType)
            //{
            //    case "3190": //仪表类型为“3190”,读写入参数格式。
            do
            {
                if (hComm2 != -1)
                {
                    //if (commThread.IsAlive)
                    //Thread.Sleep(150);

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

                    if (weightPhyNum2 != 0)
                    {
                        commCount2 += 1;
                        if (commCount2 >= 1000000)
                        {
                            commCount2 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);
                    }

                    //PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    PurgeComm(hComm2, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                }
            } while (commThreadAlive2);
        }
Example #8
0
        public void ControlCommXK2001b()
        {
            bool bGet = false;

            byte[] recb;
            double doubTmp = 0;

            do
            {
                if (hComm1 != -1)
                {
                    string disTmp = "";
                    try
                    {
                        //读取串口数据。
                        recb = Read(27, hComm1);
                        if (recb.Length > 0)
                        {
                            int j = 0;
                            for (int i = 0; i < 26; i++)
                            {
                                if ((recb[i] == 2) && (!bGet))
                                {
                                    bGet = true;
                                    continue;
                                }

                                if ((recb[i] == 2) && (bGet))
                                {
                                    bGet = false;
                                    break;
                                }

                                if (bGet)
                                {
                                    if ((recb[i] - 48) < 0)
                                    {
                                        disTmp += 0;
                                    }
                                    else
                                    {
                                        disTmp += recb[i] - 48;
                                    }
                                    j++;
                                    if (j == 12)
                                    {
                                        break;
                                    }
                                }
                            }

                            char[] mychars = disTmp.ToCharArray();
                            //Array.Reverse(mychars);
                            disTmp  = mychars[1].ToString() + mychars[2].ToString() + mychars[3].ToString() + "." + mychars[4].ToString() + mychars[5].ToString() + mychars[6].ToString();
                            doubTmp = Convert.ToDouble(disTmp);

                            if (mychars[0] == 45)
                            {
                                doubTmp = doubTmp * -1;
                            }
                            else
                            {
                                doubTmp = doubTmp * 1;
                            }

                            try
                            {
                                weightPhyNum1 = doubTmp;
                            }
                            catch (Exception ex)
                            {
                                ErrorMsg = "读取数据格式错误!" + ex.Message;
                            }
                        }
                    }
                    catch
                    {
                        ErrorMsg = "发送失败!";
                    }

                    if (weightPhyNum1 != 0)
                    {
                        commCount1 += 1;
                        if (commCount1 >= 1000000)
                        {
                            commCount1 = 0;
                        }
                    }
                    if (NumReceived != null)
                    {
                        NumberReceivedEventArgs e = new NumberReceivedEventArgs(weightPhyNum1, weightPhyNum2, commCount1, commCount2);
                        NumReceived(null, e);
                    }

                    //PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                    PurgeComm(hComm1, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
                }
            } while (commThreadAlive1);
        }