Exemple #1
0
        private void DataReceived(object sender, DataEventArgs eventArgs)
        {
            if (eventArgs.Buffer.Length < FullPacketSize)
            {
                _portBuffer += SerialPort.ASCIIByteArrayToString(eventArgs.Buffer);
                if (!IsLocalBufferComplete)
                {
                    return;
                }
            }
            else if (eventArgs.Buffer.Length > FullPacketSize)
            {
                _serialPort.ClearOutputBuffer();
                _portBuffer = string.Empty;
                return;
            }
            else
            {
                _portBuffer = SerialPort.ASCIIByteArrayToString(eventArgs.Buffer);
            }
            var readingEventArgs = new ReadingEventArgs {
                Weight = new ScaleWeight(_portBuffer)
            };

            Reading(this, readingEventArgs);
            _portBuffer = String.Empty;
        }
        private void _serialPort_Received(object sender, DataEventArgs e)
        {
            // Read all bytes in the buffer
            _dataReceived += SerialPort.ASCIIByteArrayToString(e.Buffer);

            if (Showform != null)
            {
                _showcom.AddReceived = _dataReceived;
            }

            switch (Gcode)
            {
            case "INIT":
                ParseInit();
                break;

            case "G29":
                ParseG29();
                break;

            case "G30":
                ParseG30();
                break;

            case "M114":
                ParseM114();
                break;

            case "M119":
                ParseM119();
                break;

            case "M48":
                ParseM48();
                break;

            case "M301":
                ParseM301();
                break;


            case "M303":
                ParseM303();
                break;

            case "M304":
                ParseM304();
                break;

            case "M500":
                ParseM500();
                break;

            case "M501":
                ParseM501();
                break;

            default:
                ParseDefault();
                break;
            }
        }