Ejemplo n.º 1
0
        public void OpenSerial(UartBuffer buffer, String portName, int baudrate)
        {
            m_buffer = buffer;

            serialPort.PortName = portName;
            serialPort.BaudRate = baudrate;

            serialPort.DataReceived += SerialPort_DataReceived;

            serialPort.Open();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            UART_MsgComposer uART_MsgComposer = new UART_MsgComposer();
            UartBuffer       uartBuffer       = new UartBuffer(100000);

            /* Passarlo al driver seriale che non abbiamo ancora */
            SerialManager serialManager = new SerialManager();

            serialManager.OpenSerial(uartBuffer, "COM4", 115200);

            ProcessBytes processBytes = new ProcessBytes();

            processBytes.UartBuffer       = uartBuffer;
            processBytes.UART_MsgComposer = uART_MsgComposer;
            processBytes.StartThread();

            uART_MsgComposer.OnFrameReceived += UART_MsgComposer_OnFrameReceived;


            /* Handshake */
            FrameFormat frameRequestFwVersion = new FrameFormat();

            frameRequestFwVersion.Command = 0x01; /* Read Fw Version */
            byte[] bytesToSend = uART_MsgComposer.GetBytesStream(frameRequestFwVersion);
            serialManager.SendCommand(bytesToSend);

            /* Wait For Rx */
            if (resetEvent.WaitOne(1000))
            {
                resetEvent.Reset();
                /* Analizzo frameRx */
            }
            else
            {
                /* Segnalo il timeout */
            }
        }