Exemple #1
0
        public void showComPortReadData(Control_weighing_By_Roman_07032017_0.Controler.info_weight param, Button tara, TextBox weight)
        {
            if (_shouldStop != true)
            {
                var bits = new BitArray(new byte[] { param.comand });
                if (bits[4] == true)
                {
                    set_color(tara, Color.Green);
                }
                else
                {
                    set_color(tara, Color.White);
                }

                if (bits[2] == false)
                {
                    update_weight(weight, param.index_weight.Replace(".", " "));
                }
                else
                {
                    update_weight(weight, param.index_weight);
                }
            }
        }
Exemple #2
0
        public void DoWork()
        {
            try
            {
                string tString = string.Empty;


                Control_weighing_By_Roman_07032017_0.Controler.info_weight answer = new Control_weighing_By_Roman_07032017_0.Controler.info_weight();

                if (myPort.IsOpen == false)
                {
                    myPort.Open();
                }

                myPort.DiscardInBuffer();
                myPort.DiscardOutBuffer();



                int i = 0;
                while (!_shouldStop)
                {
                    if (myPort.IsOpen != true)
                    {
                        _shouldStop = true;
                    }

                    if (myPort.BytesToRead > 0)
                    {
                        byte[] buffer = new byte[1];

                        int bytesRead = myPort.Read(buffer, 0, buffer.Length);

                        //i++;
                        //if (i == 10)
                        //{
                        //    i = 0;
                        //}
                        tString += System.Text.Encoding.ASCII.GetString(new[] { buffer[0] });

                        if (buffer[0] == '>')
                        {
                            if (tString.Length == 10)
                            {
                                showComPortReadData(parcer(tString), taraControl, showWeight);
                                //d(parcer(tString));

                                tString = string.Empty;
                            }
                            else if (tString.Length < 10)
                            {
                                tString = string.Empty;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }