Memory Access Violation?

Post your .Net discussions here
Post Reply
ARC
Newbie
Posts: 0
Joined: Wed Aug 08, 2012 8:38 am

Memory Access Violation?

Post by ARC »

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 586 times
error screen shot, error on line with green arrow
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?

Post by ARC »

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?

Post by ARC »

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 :)

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

Re: Memory Access Violation?

Post by Martyn »

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

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

Re: Memory Access Violation?

Post by ARC »

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 :)

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

Re: Memory Access Violation?

Post by Martyn »

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

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

Re: Memory Access Violation?

Post by ARC »

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

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

Re: Memory Access Violation?

Post by Martyn »

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

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

Re: Memory Access Violation?

Post by ARC »

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 :)

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

Re: Memory Access Violation?

Post by Martyn »

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

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

Re: Memory Access Violation?

Post by ARC »

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 :)

Post Reply