Dear all,
Following your helps and suggestions on my former message, I have used successfully the function within ps4000 folder to control my card ps4262 with C++Builder.
Now I have met another difficulty with my new card ps4824a. In ps4000a folder, there are some examples (3 years’ ago) designed for the card ps4824a: https://github.com/picotech/picosdk-c-examples.
I think these functions may be designed for either Visual C++ or Linux. In fact, I have compiled some functions successfully with C++Builder but I can’t get data, there is something wrong in the function “ps4000aRunBlock(unit->handle, 0, sampleCount, timebase, &timeIndisposed, 0, CallBackBlock, NULL)”, the data is never ready!
Many thanks in advance
Warm regards
Xavier
Thank you Martyn.
Here is the function adapted to C++Builder 64bits, version 10.4.
Main issue is in the function "ps4000aRunBlock()": no return value of "timeIndisposed" !
Xavier
}
/* find the maximum number of samples, the time interval (in timeUnits),
* the most suitable time units */
while (ps4000aGetTimebase2(unit->handle, timebase, sampleCount, &timeInterval, &maxSamples, 0))
{
timebase++;
}
Form1->Memo1->Lines->Add(String("Timebase, SampleInterval: ") + FloatToStr(timebase) + " , " + FloatToStr(timeInterval) );
/* Start it collecting, then wait for completion*/
g_ready = FALSE;
status = ps4000aRunBlock(unit->handle, 0, sampleCount, timebase, &timeIndisposed, 0, CallBackBlock, NULL);
// Problem: no return value of "timeIndisposed" !!!
if (status != PICO_OK && status != PICO_USB3_0_DEVICE_NON_USB3_0_PORT)
{
Form1->Memo1->Lines->Add("Error in BlockDataHandler:ps4000aRunBlock status: " + FloatToStr(status) );
return;
}
Form1->Memo1->Lines->Add("Waiting for trigger...Press a key to abort");
// Why g_ready is never true!
while (!g_ready)
{
Sleep(0);
}
if (g_ready)
{
// Data processing ......
}
else
{
Form1->Memo1->Lines->Add("data collection aborted");
}
timeIndisposed will return a value in msecs, if the time taken to collect a block of data defined by the settings for timebase and sampleCount is less than 1 msec then the value will be 0
ps4000aRunBlock doesn't return with status OK (g_ready is always false).
timeIndisposed has always its big and random value. It is not changed after ps4000aRunBlock().
Thanks a lot
Xavier
What error code is being returned?
What values are used for sampleCount and timebase?
Try with a sampleCount of 1000 and a timebase of 2000 and see if you get a value for timeIndisposed (with a different model scope I get 67), and that the BlockCapture runs and collects data.
In fact, there is no error returned, only status = 286. I have tried with a computer with true USB3.0, always 286 returned.
I have tried with a sampleCount of 1000 and a timebase of 2000: the same as before, timeIndisposed didn't change.
Many thanks
Xavier
ps4000aChangePowerSource
PICO_STATUS ps4000aChangePowerSource
(
int16_t handle,
PICO_STATUS powerstate
)
This function controls the two-stage power-up sequence when the device is plugged
into a non-USB 3.0 port.
If you receive the PICO_USB3_0_DEVICE_NON_USB3_0_PORT status code from one of
the OpenUnit functions (ps4000aOpenUnit, ps4000aOpenUnitAsync or
ps4000aOpenUnitProgress), you must then call ps4000aChangePowerSource to
switch the device into non-USB 3.0-power mode.
Note. The PicoScope 4824 has two power supply options:
1.To power it from a USB 3.0 port, use the USB 3.0 cable supplied.
2.To power it from a non-USB 3.0 port, use the double-headed USB 2.0 cable supplied
and plug it into two USB 1.1 or USB 2.0 ports on the host machine.
/* find the maximum number of samples, the time interval (in timeUnits),
* the most suitable time units */
while (ps4000aGetTimebase2(unit->handle, timebase, sampleCount, &timeInterval, &maxSamples, 0))
{
timebase++;
}
Form1->Memo1->Lines->Add(String("Timebase, SampleInterval: ") + FloatToStr(timebase) + " , " + FloatToStr(timeInterval) );
// Just for testing:
sampleCount = 1000;
timebase = 2000;
/* Start it collecting, then wait for completion*/
g_ready = FALSE;
status = ps4000aRunBlock(unit->handle, 0, sampleCount, timebase, &timeIndisposed, 0, CallBackBlock, NULL);
Form1->Memo1->Lines->Add(String("Returned timeIndisposed = ") + IntToStr(timeIndisposed));
if (status != PICO_OK)
{
Form1->Memo1->Lines->Add("Error in BlockDataHandler:ps4000aRunBlock status: " + FloatToStr(status) );
return;
}
Form1->Memo1->Lines->Add("Waiting for trigger...Press a key to abort");
while (!g_ready)
{
// Sleep(0);
timebase = timebase; // do something as Sleep(0) can't work in my system?
}
if (g_ready)
{
// Data processing ......
status = ps4000aGetValues(unit->handle, 0, (uint32_t*) &sampleCount, 1, PS4000A_RATIO_MODE_NONE, 0, &g_ready);
if (status != PICO_OK)
{
Form1->Memo1->Lines->Add("Error, BlockDataHandler:ps4000aGetValues ------ 0x%08x " + FloatToStr(status));
}
else
{
// Print out the first 10 readings, converting the readings to mV if required
//------------------------------------------------------------------------
Form1->Memo1->Lines->Add(text);
if (scaleVoltages)
Form1->Memo1->Lines->Add("Channel readings are in mV");
else Form1->Memo1->Lines->Add("Channel readings are in ADC Counts");
if ((status = ps4000aStop(unit->handle)) != PICO_OK)
{
Form1->Memo1->Lines->Add("BlockDataHandler:ps4000aStop ------ 0x%08x " + FloatToStr(status));
}
if (fp != NULL)
{
fclose(fp);
}
for (i = 0; i < unit->channelCount; i++)
if (unit->channelSettings.enabled)
{
free(buffers[i * 2]);
free(buffers[i * 2 + 1]);
}
ClearDataBuffers(unit);
}
Here are the tested results:
Channels A and B are selected with scale 10V
The input of the two chennels are short-circuited with 50 Ohm resistances.
The results are not good in values:
Returned timeIndisposed = 42
Waiting for trigger...Press a key to abort
First 10 readings
Just a result of some additional tests with signal generator:
ChanelA is connected to a signal generator: 0 to 2.5V, 10kHz square waveform.
ChanelA is set to no DC coupling (otherwise, all saturation).
ChanelB is short-circuited with 50 Ohm resistor
The recorded time step is correct according to first 100 samples (40 samples / cycle), but the values are not correct: saturation value int16?
If I use Picoscope6, all correct.
I have taken the following function (sorry, I don't totally understand the content):
void SetDefaults(UNIT * unit)
{
PICO_STATUS status;
PICO_STATUS powerStatus;
int32_t i;
unit->resolution = Form1->ComboBox2->ItemIndex; // 0 to 4 (I have tested from 8bits to 16 bits)
if (unit->hasETS)
{
status = ps4000aSetEts(unit->handle, PS4000A_ETS_OFF, 0, 0, NULL);
Form1->Memo1->Lines->Add(status?String("SetDefaults:ps4000aSetEts------ %08x "):"" + String(status));
}
powerStatus = ps4000aCurrentPowerSource(unit->handle);
for (i = 0; i < unit->channelCount; i++)
{
status = ps4000aSetChannel(unit->handle, (PS4000A_CHANNEL)(PS4000A_CHANNEL_A + i),
unit->channelSettings[PS4000A_CHANNEL_A + i].enabled,
(PS4000A_COUPLING)unit->channelSettings[PS4000A_CHANNEL_A + i].DCcoupled,
(PS4000A_RANGE)unit->channelSettings[PS4000A_CHANNEL_A + i].range,
unit->channelSettings[PS4000A_CHANNEL_A + i].analogueOffset);
// printf(status?"SetDefaults:ps4000aSetChannel------ 0x%08x \n":"", status);
Form1->Memo1->Lines->Add( status?String("SetDefaults:ps4000aSetChannel------ 0x%08x "):" " + String(status));
}
}
Per some tests, I realized that in each chanel, it measured either -32767 or + 32767. It behaviors as a sign detector!
At the entrance of ps4000aRunBlock(....), I have captured all values of unit by debug (I try to upload a picture, I am not sure it works, here is the link: http://xaviery.free.fr/000.jpg):
I have tried to set
(PS4000A_RANGE)unit->channelSettings[PS4000A_CHANNEL_A + i].range: 5, 10 and 50V.
In all these cases, buffer values are always -32767, +32767, i.e. .range doesn't have any effect on the channels.
Furthermore, when DCCoupled is enabled, results are even worse: almost all saturation.
I wonder if any different format of INT values: the order of High byte and Low byte? (but with my 4642, every thing is OK).