Test and Measurement Forum

Memory Access Violation?

Post your .Net discussions here

Memory Access Violation?

Postby ARC » Wed Feb 13, 2013 9:51 am

Hello,

Has anybody had memory access violation errors with 2206 Picoscope?
I am using the console SDK as DLL for a main C# program.

The error is in attached jpeg, the line
Code: Select all
status = ps2000aGetStreamingLatestValues(unit->handle, CallBackStreaming, NULL);
is causing this, i presume due to something before it missed or done but i can't see it when compared to the original and i have attached my code for the background information.

Thanks for looking :)
Attachments
PS2000Acon.c
code
(70.87 KiB) Downloaded 126 times
access violation.jpg
error screen shot, error on line with green arrow
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: Memory Access Violation?

Postby ARC » Wed Feb 13, 2013 2:08 pm

I have figured out the error and some how i managed to remove the while loop waiting for the Picoscope to start getting samples.
Code: Select all
while (!g_ready && !_kbhit())
{
   Sleep(0);
}

but there is still nothing in the recorded file and if i try to open the file when its writing to another one and it is in use with another application so i cant open but when i close the application the file is still empty.

i have created a global variable g_manualstop which i change to true in this function:
Code: Select all
_declspec (dllexport) void stopstream()
{
   g_manualstop = TRUE;
}

and the oscilloscope loop has while !g_manualstop in it so when i call the above function the loop should exit, close the file and exit the dll. but that can't be happening if the file is still in use.
Code: Select all
while (!_kbhit() && !g_manualstop && !g_overflow)


any ideas?

thanks for the help :)
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: Memory Access Violation?

Postby ARC » Wed Feb 13, 2013 3:40 pm

Actually that hasn't fixed the issue it is just sitting in that while loop which stops that line from executing. i have tried changing the while loop to just while (!g-ready) but still no luck.

Any ideas?

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

Re: Memory Access Violation?

Postby Martyn » Fri Feb 15, 2013 10:05 am

If you make the following change
Code: Select all
   while (!_kbhit() && !g_manualstop && !g_overflow  && !g_autoStopped )

you should find it works correctly.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2351
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Memory Access Violation?

Postby ARC » Mon Feb 18, 2013 8:28 am

yep that and a few other things i found where wrong and it works now.

But ive now got error 67 when i call ps2000aSetSigGenArbitrary in soft trigger mode. I have seen this error sporadically a couple of times before but now it happens after about 3 calls without closing the Picoscope.
I know 67 isn't a part of the driver status codes so what does this mean?

Thanks for the help :)
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: Memory Access Violation?

Postby Martyn » Mon Feb 18, 2013 8:39 am

It is one of the status codes
Code: Select all
// A driver function has already been called and not yet finished
// only one call to the driver can be made at any one time
#define PICO_DRIVER_FUNCTION                                 0x00000043UL
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2351
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Memory Access Violation?

Postby ARC » Thu Feb 21, 2013 10:13 am

OK so to remove this problem i have the DLL running as a separate thread and i will change global variables to control the program.
After doing this i have got signal generation working again but the oscilloscope side wont work. When calling ps2000aGetTimebase in the while loop timeinterval and maxsamples pointers are not set so the loop never exits.

I must be missing something before calling that function.

I have attached my code, Thanks so much for the help :)
Attachments
PS2000Acon.c
(72.29 KiB) Downloaded 120 times
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: Memory Access Violation?

Postby Martyn » Mon Feb 25, 2013 3:10 pm

Do you mean stuck here
Code: Select all
      /*  find the maximum number of samples, the time interval (in timeUnits),
      *       the most suitable time units, and the maximum oversample at the current timebase*/
      while (ps2000aGetTimebase(unit->handle, timebase, sampleCount, &timeInterval, oversample, &maxSamples, 0))
      {
         timebase++;
      }

if so can you print our timebase, sampleCount and oversample before you hit the loop to check that they are sane values
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2351
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Memory Access Violation?

Postby ARC » Thu Feb 28, 2013 8:12 am

OK so passing:
offset = 0,
mode = analogue,
repname = a directory,
text = "Ten readings after trigger".

When the program gets to the while loop the values are:
timebase = 1,
sample count = 1024,
time interval = -858993460,
oversample 1,
max samples = -858993460.

Thanks for the help :)
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Re: Memory Access Violation?

Postby Martyn » Thu Feb 28, 2013 9:51 am

I have just tried with your code, modified it to remove the file writing code in BlockDataHandler and it enters the GetTimebase call with the parameters you have mentioned
Code: Select all
      while (ps2000aGetTimebase(unit->handle, timebase, sampleCount, &timeInterval, oversample, &maxSamples, 0))
      {
         timebase++;
      }

and exits after 1 pass with timebase 10 and maxSamples 24540 which is what I would expect.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2351
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Memory Access Violation?

Postby ARC » Thu Feb 28, 2013 10:27 am

Ah ok, I have just moved the file opening code to after its triggered, and now it works :D

Thank you very much for your help :)
ARC
Newbie
 
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests