private void DataReceivedHandlerChunks(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp        = (SerialPort)sender;
            Stopwatch  stopwatch = new Stopwatch();

            stopwatch.Start();

            _logger.Debug("Data Received:");

            string readChunk = sp.ReadExisting();
            string inndata   = readChunk.TrimEnd();

            while (!string.IsNullOrWhiteSpace(readChunk) && stopwatch.ElapsedMilliseconds < _timeoutMs)
            {
                readChunk = sp.ReadExisting();
                if (string.IsNullOrWhiteSpace(readChunk))
                {
                    continue;
                }
                inndata += readChunk.TrimEnd();
                _logger.Debug($".---{readChunk}---");
            }

            _logger.Debug($">>>{inndata}<<<");

            PortDataRead?.Invoke(this, inndata);
        }
        private void DataReceivedHandlerReadLine(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //sp.ReadTimeout = 500;
            //sp.NewLine = "\n";
            //sp.NewLine = "\r";
            //sp.NewLine = "\r\n";
            _logger.Debug("Data Received:");
            string inndata = String.Empty;

            //List<string> lstList = new List<string>();

            while (stopwatch.ElapsedMilliseconds < 500)
            {
                //string chunk = sp.ReadExisting();
                //inndata += chunk;
                inndata += sp.ReadExisting();
                //if (!string.IsNullOrEmpty(chunk))
                //{
                //    lstList.Add($"{stopwatch.ElapsedMilliseconds}-{chunk}");
                //}
            }
            _logger.Debug($">>>{inndata}<<<");

            PortDataRead?.Invoke(this, inndata);
        }
Example #3
0
        public void SendCommand(string cmd)
        {
            _logger.Debug($"Send command: {cmd}");
            readDataTwo          = $"T,GS,   {_measuredWeightTest:F1},kg";
            _measuredWeightTest -= 6.1;

            PortDataRead?.Invoke(this, readDataTwo);
        }
        private void DataReceivedHandlerSlashRSlashN(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;

            _logger.Debug("Data Received:");
            string saveSpNewline = sp.NewLine;

            sp.NewLine = "\r\n";
            string inndata = sp.ReadLine();

            sp.NewLine = saveSpNewline;

            _logger.Debug($">>>{inndata}<<<");
            PortDataRead?.Invoke(this, inndata);
        }
Example #5
0
 public void SendCommand(string cmd)
 {
     _logger.Debug($"Send PS command: {cmd}");
     PortDataRead?.Invoke(this, readDataTwo);
 }