Hi, I'm witing a program on iphone and im stock with the part to receive data on an iphone from the out side world. In fact i can receive and display data and it works great but when i try to read more than one time on the serial port i'm stock with old data in the buffer and can't manage to flush it. What would solve my problem would be a way to flush the unwanted data queue in the Rx buffer. Here is my code:
int Test_Rx_Serial_Port(void) { char dummy_buff[8]; int i;
if (Check_Serial_Port() == 1) { // Polling, blocks until MAX_RX_DATA NUMBER OF char are received // Dangerous of blocking the Apps if no data is received or PIC crashs....Have to implent a timeout of watch dog write(fileDescriptor,"<",1); // Write handshaking message over serial write(fileDescriptor,"R",1); // Write handshaking message over serial write(fileDescriptor,">",1); // Write handshaking message over serial
write(fileDescriptor,"*",1); for (i=0; i<3; i++) { read(fileDescriptor,&dummy_buff[0],1); RxData[i] = dummy_buff[0]; write(fileDescriptor,&RxData[i],1); } write(fileDescriptor,"*",1);
if(RxData[0]=='<' && RxData[1]=='R' && RxData[2]=='>') // Check if this byte is a "handshaking" message { return 1; // Debugg succes good Rx char } else { write(fileDescriptor,"",1); write(fileDescriptor,&RxData[0],1); write(fileDescriptor,&RxData[1],1); write(fileDescriptor,&RxData[2],1); write(fileDescriptor,"",1); return 0; // Debugg fail bad Rx char } } else { return -1; } }