_kbhit?

Post any questions you may have about our current range of oscilloscopes
Post Reply
ARC
Newbie
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

_kbhit?

Post by ARC »

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.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Post by Martyn »

You can use

Code: Select all

            while (!Console.KeyAvailable) Thread.Sleep(100);

            if (Console.KeyAvailable) Console.ReadKey(true); // clear the key
Martyn
Technical Support Manager

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

Re: _kbhit?

Post by ARC »

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

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Post by Martyn »

That is C# code equivalent to kbhit to allow you to exit from the wait for data loop in your code
Martyn
Technical Support Manager

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

Re: _kbhit?

Post by ARC »

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 611 times

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: _kbhit?

Post by Martyn »

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 Support Manager

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

Re: _kbhit?

Post by ARC »

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

Thanks so much.

Post Reply