LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble using start and stop buttons

k1_ke, be sure to put away the while loop inside ReadData () function since it is no longer needed: the callback is fired only when the correct message is at port! StopButtonFlag global variable is also no longer needed since to stop the receiver you simply can use    InstallComCallback (comport, 0, 0, 0, 0, 0); inside your Quit callback.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 11 of 13
(1,142 Views)
Hi Roberto,
 
Thanks alot for your help! I was able to figure it out and so far i have been receiving all the data at the serial port and everything is fairly quick! I will get back to you if anything comes up.
 
Thanks alot once again.
 
Regards
 
k1_ke
0 Kudos
Message 12 of 13
(1,136 Views)

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

0 Kudos
Message 13 of 13
(1,080 Views)