how can I receive messages (line by line) through serial port from microcontroller by received event like hyperterminal?

Dear friends,

I have programmed a small form for receiving messages from a microcontroller through a serial port.

when I use readline() method in the event of clicking a button (open port), it can receive a line of messages sending from microcontroller and show it in a textbox.

But I need to receive continuously the messages without pressing any button after opening serial port until closing the port in a multi line textbox with vertical scrollbar.

I used serialPort1_DataReceived event but I don't exactly what should I write in this event function. I tested readByte() and readChar() I couldn't receive any thing.

The microcontroller is sending data character by character with a very small delay (in order of micro seconds) in between and at the end of every message, there is \n\r.

Could you guide me to solve this problem? Should I read character by character? How? Do I need to define another function/method?

I appreciate a lot in advance.
maybe you can put readline() into an infinite loop.
doing this will most likely freeze your program, so i suggest you run this loop in a second thread.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
typedef something Parameter_type;

void function ( void* ptrParameter )
{
    Parameter_type * pObject;
    pObject = reinterpret_cast<Parameter_type*> (ptrParameter);
    /* do whatever you want here */
    
     std::string buffer;
     while(true)
     {
           buffer.clear();
           buffer.append( readline() );
           ProcessMessage( buffer );
      }
}

int main()
{
    _beginthread( function , 0 , ArrayOfPointersToParameters_Voidptr );


    // your code goes here.


    return 0;
}


MSDN - sample multi-thread program:
http://msdn.microsoft.com/en-us/library/esszf9hw.aspx
thanks... i needed this type of information...
Topic archived. No new replies allowed.