Example #1
0
        private void BarcodeScanner1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                while (true)
                {
                    Application.DoEvents();
                    ReadData += BarcodeScanner1.ReadExisting();
                    if (ReadData.IndexOf('\r') >= 0)
                    {
                        break;
                    }
                }
                ReadData = ReadData.Replace("", "");
                ReadData = ReadData.Trim();

                if (Txt_Test.InvokeRequired)
                {
                    Txt_Test.BeginInvoke(new Action(() =>
                    {
                        Txt_Test.Text = ReadData + "\n";
                    }));
                }
                else
                {
                    Txt_Test.Text = ReadData;
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        private void MLCP_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            double HeightVal = Convert.ToDouble(info[2]);
            double Height2;

            ReadData = MLCP.ReadLine();

            strar   = ReadData.Split(',');
            chararr = strar[2].ToCharArray();
            double value;
            string str2;

            str2 = chararr[0].ToString() + chararr[1].ToString() + chararr[2].ToString() +
                   chararr[3].ToString() + chararr[4].ToString();
            bool isDouble = double.TryParse(str2, out value);

            if (isDouble)
            {
                str2 = chararr[0].ToString() + chararr[1].ToString() + "." + chararr[2].ToString() +
                       chararr[3].ToString() + chararr[4].ToString();
                str2    = str2.Trim();
                Height2 = Convert.ToDouble(str2) + HeightVal;
            }
            else
            {
                str2 = chararr[0].ToString() + "." + chararr[1].ToString() + chararr[2].ToString() +
                       chararr[3].ToString();
                str2    = str2.Trim();
                Height2 = Convert.ToDouble(str2) + HeightVal;
            }

            if (Txt_Test.InvokeRequired)
            {
                Txt_Test.BeginInvoke(new Action(() =>
                {
                    Txt_Test.Text = Height2.ToString();
                }));
            }
            else
            {
                Txt_Test.Text = Height2.ToString();
            }
        }