interface is not receiving string from mikroC Pro

681 views Asked by At

I want to send string from mikroC pro to PC using C# interface. my code is:

void main()
{
    while (1) 
    {
        if (UART1_Data_Ready())
        {
            UART1_Write_Text("mikroC");
            Delay_ms(1000);
        }
    }
}

but when is received in C#, it return as whole string first time, then it returns pieces of it, like it first sends 'm' then 'ikroC'. etc where as my C# code is:

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
     MessageBox.Show(serialPort1.ReadExisting().ToString());
}
1

There are 1 answers

0
Soundararajan On

The MSDN document says : The DataReceived event is not guaranteed to be raised for every byte received. Use the SerialPort.BytesToRead property to determine how much data is left to be read in the buffer. For more information refer to this MSDN Article