I am working on robot which has to control using wireless serial communication. Robot is running on micro controller( by burning .hex file). I want to control it using my Linux(Ubuntu) pc. I am new to serial port programming. I am able to send the data but I am not able to read data. few piece of code which is running over micro controller:
function to send data
void TxData(unsigned char tx_data)
{ SBUF = tx_data; //Transmit data that is passed to this function
while(TI == 0); //wait while data is being transmitted
}
I am sending data through array of characters data_array[i]
for (i=4;i<=6;i++)
{
TxData(data_array[i]);
RI = 0; //Clear receive interrupt. Must be cleared by the user.
TI = 0; //Clear transmit interrupt. Must be cleared by the user.
}
Now the piece of code from C program running on Linux...
> while (flag==0) {
> int res = read(fd,buf,255);
> buf[res]=0; /* set end of string, so we can printf */
> printf(":%s:%d\n", buf, res);
> if (buf[0]=='\0') flag=1;
}
It prints out value of res = 0 .
Actually I want to read data character-by-character to perform calculations and take further decision. Is there other way of doing this? Please help because I am not able to proceed with project.
Note: If someone can suggest good study material(code) for serial port programming on Linux, it would help me.
Thanks....