01-04-2006 02:26 AM
01-05-2006 08:29 AM
01-30-2006 07:57 AM
Hi Roberto,
Sorry to bother you but i am having trouble received data via the serial port. As u can read on previous messeges, i was having trouble receiving all the data and you suggested bunch of ways to get around it. I followed the step and everything seemed to be working fine up until i added counters at the end of the data packet and a led to check for Data loss....i am noticing a strange behaviour.
So basically i have a start button on my UAP, when pressed triggers InstallComCallback (comport, LWRS_RXFLAG, 0, read_term, ComCallback, 0)......... and
ComCallback is the routine where i actually read the COM Port
void ComCallback(int portNo, int eventMask, void *data)
{
unsigned int tbox=0,tbox_1=0;
int error,len;
len=GetInQLen(comport);
if (len < 0)
return;
else
{
do
{
tbox=0;
bytes_read = ComRdTerm (comport, read_data, read_cnt,read_term);
//Receives data from serial port and saves it in read_data
CopyString (tbox_read_data, 0, read_data, 0, read_cnt);
tbox=(((tbox_read_data[1] & 0x0C)<<4) |(tbox_read_data[8] & 0x0F));
}while(tbox != 0xC);
}
i check for bytes_read<0 and bytes_read<read_cnt
}
The Data packets i receive are 26bytes followed by a CR and LF.......thus read_cnt=28 and read_term=13...........well i usually get all the packets in sync.....but sometimes...once in may be 200 or more packets i get a glitch........below are the packets when glitch occurs..
@L@@@@@A@O@ALDOI@EII@@@JAA
where last 2bytes are counters.....A=$41 hence take lower 4bits....thus this packet no is 11.......and the next one i receive should b with counter AB which is packet no 12 but instead get@L@@@@@@L@@@@@AO@ALDOI@EII
and here counter becomes I=$49 hence 99 whereas my last counter was 11 so next it expects 12 not 99.....but from what i notice this happens only sometimes...that when ui keep goin start stop start stop.....but its totally random.....i dont know if its because of my linefeed.....cos it is noticed that LF =0xA and the error occured...it took the first 7bytes then saw A which technically is $41 but repeated the first bytes and then carried on to get the next ones.....thus skippin the last 7bytes.......but the packet after the glitch becomes all fine and in sync.....so its really wierd
Please let me know if can figure out where the problem could be occuring........also let me know if need any more explaination on any of the parts!
Lookin forward to hear from you.
Thanks
k1_ke