LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using InstallComCallback

Hello,

I would appreciate if someone can help me with my problem. Basically, i am trying to receive data via a serial port. I have my UAP set up such that when i press start button it initialises the comport and configures it using OpenComConfig......then i use InstallComCallback which calls the callback routine.....in that routine i use ComRdTerm to read the serial port....

At the moment it works fine but sometimes when i press start, it doesnt receive any data.....so i stop it adn start again....it might get the data otherwise have to do it again.......i dont know why.......in my Stop button......i basically do the following..

InstallComCallback (comport, 0, 0, 0, 0, 0); //stops communication with serial port

FlushInQ (comport); //Flush input que buffer

len= GetInQLen (comport);

CloseCom(comport);

config_flag =0;

port_open =0;

Also i would like to know when i use InstallComCallback (comport, 0, 0, 0, 0, 0); does this also stop filling the input queue? because if i dont flushInQ when stopping...the next time its got 4096 character and because of that some data is missing thus a data loss led goes on.......so i hv realised flushing the input que out solves that problem n i receiev all the data bt sometimes i do not get any data....

Looking forward to hear from someone....

Thanks

k1_ke

0 Kudos
Message 1 of 5
(3,432 Views)

I am not convinced that your programming approach is sound. I am referring to the repeated calls you seem to make to InstallComCallback(), OpenComConfig() and CloseCom(), triggered by UIR button presses. It may actually be valid, but my personal preference would be to use the InstallComCallback() and OpenComConfig() calls just once in my CVI program, say in main() just before the call to RunUserInterface(). Similarly, I would only CloseCom() once, at the point of exit of the program, say just after the call to RunUserInterface(). That way, you can be sure that you will not be resetting ports at an inconvenient time, which could be causing unexpected and unpredictable data loss.

JR 

0 Kudos
Message 2 of 5
(3,424 Views)

Hi Jr,

Thanks for ur reply. Well i noted your comments but say if i use InstallComCallback in my main program....then as soon as i run it...it triggers the comback routine which starts reading the data from the input que n updating my user interface........but i would like my program to run such that when i press start it should start reading the input que....and when press stop stop readin it.......so how should i go about this then?

Looking forward for ur help.

Thanks

k1_ke

0 Kudos
Message 3 of 5
(3,422 Views)

It should not be too difficult to arrange for a global variable to be used as a flag throughout your program; for example:

    static int enabled;

Inside your Start and Stop button callbacks, you could set the value of this flag variable accordingly. (TRUE for Start; FALSE for Stop.) Inside your ComCallback routine (which is being continually triggered by reception of serial data) you can simply inspect the flag state and discard the data you have extracted if the flag is FALSE, or of course if the flag is TRUE you can process the data as normal and update the UIR. The key is that since you are now processing ALL data (even if you are then discarding data you don't want) it should be possible for you to at least maintain a 'lock' on the data stream coming in, without potentially corrupting it by opening/closing ports while they are still active.
 
JR
0 Kudos
Message 4 of 5
(3,409 Views)
Hi JR,
 
Sorry for the late reply, i was away from my office. I took into account your suggestion and now that i think about it i think you idea is more logical. And yeah regarding my problem i was able to solve it. it was more with the termination byte and the way i was readin it.
 
Thanks alot for ur help.
 
k1_ke
 
0 Kudos
Message 5 of 5
(3,374 Views)