Test and Measurement Forum

_kbhit?

Post any questions you may have about our current range of oscilloscopes

_kbhit?

Postby ARC » Wed Aug 29, 2012 12:10 pm

Hello,

I'm trying to control capturing stream of data through oscilloscope 2206 but I'm unsure how to stop it capturing because if i just exit the thread it obviously doesn't finish with the file so there's nothing in it.

I'm calling the stream functions in a DLL from a c# GUI program. and it works but i can't stop it, so how can i set _kbhit to make it exit the while loop and finish the function?

Any ideas on this welcome :)

Thank you for the help :)
Last edited by ARC on Wed Aug 29, 2012 2:38 pm, edited 1 time in total.
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: _kbhit?

Postby Martyn » Wed Aug 29, 2012 2:11 pm

You can use
Code: Select all
            while (!Console.KeyAvailable) Thread.Sleep(100);

            if (Console.KeyAvailable) Console.ReadKey(true); // clear the key
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Postby ARC » Wed Aug 29, 2012 2:38 pm

sorry not sure how to use that?

put it in the C DLL or C# code?

The C DLL is from the SDK so its inside the main while loop taking readings and printing them to the txt file, so it can't sleep until key press otherwise no samples will be recorded? unless im understanding this wrong?

Many thanks
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: _kbhit?

Postby Martyn » Wed Aug 29, 2012 2:52 pm

That is C# code equivalent to kbhit to allow you to exit from the wait for data loop in your code
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Postby ARC » Thu Aug 30, 2012 7:18 am

my c# code is windows app so console commands dont work, sorry i realised i didnt mention this and edited my first post to include this.

so it errors saying "InvalidOperationException was unhandled" "Cannot see if a key has been pressed when either application does not have a console or when console input has been redirected from a file".

because im calling the DLL in a thread my C# program continues which is fine my issue is causing the C DLL which is a cut down version of the ps2000con.c in the SDK to exit the collect data while loop, which looks like:

Code: Select all
while (!_kbhit() && !g_autoStopped && !g_overflow)


so i need to set kbhit or autostopped to make it stop collecting data. but i need to do this from the c# code to the DLL.

I have attached the code incase it helps.

Many Thanks
Attachments
PS2000Acon.c
(67.47 KiB) Downloaded 180 times
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: _kbhit?

Postby Martyn » Thu Aug 30, 2012 7:57 am

You need an additional function in PS2000A.con which sets a global variable, say g_manualStop, and this value can be checked by the data collection function instead of _kbhit().

This function can be called from your C# GUI by pressing a button.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Postby ARC » Thu Aug 30, 2012 9:31 am

Ah i see when i did that before i didnt make it global for some stupid reason. :|

Thanks so much.
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am


Return to USB PC Oscilloscopes

Who is online

Users browsing this forum: No registered users and 0 guests