PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
//-----------------------------------------------------------------------------------------------------------------------------------
USB_DRDAQ_INPUTS channel[3] = {USB_DRDAQ_CHANNEL_LIGHT, USB_DRDAQ_CHANNEL_TEMP,USB_DRDAQ_CHANNEL_MIC_WAVE};
//------------------------------------------------------------------------------------------------------------------------------------
//init section
char info[20];
short requiredSize = 0;
short channel=0;
printf ("USB DrDAQ driver example program\n");
printf ("Version 1.0\n\n");
printf ("\n\nOpening the device...\n");
status = UsbDrDaqOpenUnit(&g_handle);
if (status != 0)
{
printf ("Unable to open device\nPress any key\n");
_getch();
return;
}
else
{
printf ("Device opened successfully\n\n");
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_VARIANT_INFO);
printf("Model:\t\t\t %s\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_BATCH_AND_SERIAL);
printf("Serial Number:\t\t %s\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_CAL_DATE);
printf("Calibration Date:\t %s\n\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_USB_VERSION);
printf("%s\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_HARDWARE_VERSION);
printf("Hardware version %s\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_DRIVER_VERSION);
printf("USBDrDAQ.dll version %s\n", info);
status = UsbDrDaqGetUnitInfo(g_handle, info, 20, &requiredSize, PICO_KERNEL_VERSION);
printf("%s\n", info);
//Set to scope channel initially
channel = USB_DRDAQ_CHANNEL_SCOPE;
}
//-----------------------------------------------------
//init socket
//......
/---------------------------------------------------------------------------------------------------------------------------------------
//Streming function
unsigned int i;
int aInt=0;
int result=-1;
unsigned long nSamples = 2000;
short nChannels = 3;
unsigned long nSamplesPerChannel = 1000;
unsigned long nSamplesCollected;
short samples[3000];
unsigned long usForBlock = 1000000;
unsigned short overflow;
unsigned long triggerIndex = 0;
short nLines = 0;
FILE *fp;
char v1[BUFSIZ];
char v2[BUFSIZ];
char v3[BUFSIZ];
char out[BUFMAX];
printf ("Collect streaming (channel %d)...\n", channel);
printf ("Data is written to disk file (test.out)\n");
printf ("Press a key to start\n");
// _getch();
//Set the trigger (disabled)
status = UsbDrDaqSetTrigger(g_handle, FALSE, 0, 0, 0, 0, 0, 0, 0);
//set sampling rate and channels
status = UsbDrDaqSetInterval(g_handle, &usForBlock, nSamples, channel, nChannels);
//Start streaming
status = UsbDrDaqRun(g_handle, nSamples, BM_STREAM);
//Wait until unit is ready
isReady = 0;
while(isReady == 0)
{
status = UsbDrDaqReady(g_handle, &isReady);
}
//printf("Press any key to stop\n");
//fopen_s(&fp, "test.out", "w");
while((result!=FALSE))
{
// nSamplesCollected = nSamplesPerChannel;
status = UsbDrDaqGetValues(g_handle, samples, &nSamplesCollected, &overflow, &triggerIndex);
// printf("%d values\n", nSamplesCollected);
i = 0;
while( (i 0){
//printf("Bytes received: %d\n", iResult);
//printf(recvbuf);
result = strncmp(recvbuf, end_comm, DEFAULT_BUFLEN);
}
else if (iResult == 0)
printf("Connection closed\n");
else
printf("recv failed: %d\n", WSAGetLastError());
i++;
}//end invio blocco dati
Sleep(200)
}//
closesocket(ConnectSocket);
WSACleanup();
//fclose(fp);
//-----------------------------------------------------------------------------------------------------------
Code: Select all
.......
client>2;227;271
client>227;271;3
client>271;3;229
client>3;229;271
client>229;271;3
client>271;3;231
client>3;231;271
client>231;271;2
client>271;2;234
client>2;234;271
client>234;271;0
client>271;0;238
client>0;238;271
client>238;271;2
client>271;2;242
client>2;242;271
client>242;271;0
client>271;0;246
client>0;246;271
client>499;633;-20
client>633;-20;501
client>-20;501;628
client>501;628;-20
client>628;-20;501
client>-20;501;623
client>501;623;-20
client>623;-20;500
client>-20;500;615
client>500;615;-21
client>615;-21;501
client>-21;501;608
client>501;608;-20
client>608;-20;501
client>-20;501;600
client>501;600;-20
client>600;-20;500
client>-20;500;594
client>500;594;-20
client>594;-20;500
client>-20;500;589
client>500;589;-20
client>589;-20;501
client>-20;501;586
client>501;586;-20
client>586;-20;501
client>-20;501;584
client>501;584;-20
client>584;-20;502
client>-20;502;584
client>502;584;-20
client>584;-20;501
client>-20;501;586
client>501;586;-20
client>586;-20;503
client>-20;503;590
client>503;590;-20
client>590;-20;503
------
Code: Select all
while( (i
Code: Select all
usForBlock = 100000; //100ms
nSamples = 5236;
Code: Select all
void collect_block_immediate (void)
{
uint32_t i;
uint32_t nSamples = 5236;
int16_t nChannels = 3;
uint32_t nSamplesPerChannel = 5236;
uint32_t nSamplesCollected;
int16_t samples[18000] = {0};
uint32_t usForBlock = 100000;
uint16_t overflow;
uint32_t triggerIndex = 0;
FILE * fp;
USB_DRDAQ_INPUTS testChannel[3] = {USB_DRDAQ_CHANNEL_LIGHT, USB_DRDAQ_CHANNEL_TEMP, USB_DRDAQ_CHANNEL_MIC_WAVE};
printf ("Collect block immediate (channel %d)...\n", channel);
printf ("Press a key to start\n");
_getch();
//Set the trigger (disabled)
status = UsbDrDaqSetTrigger(g_handle, FALSE, 0, 0, 0, 0, 0, 0, 0);
//set sampling rate and channels
status = UsbDrDaqSetInterval(g_handle, &usForBlock, nSamples, testChannel, nChannels);
printf("Press any key to stop\n");
fopen_s(&fp, "usb_dr_daq_block_immediate.txt", "w");
while(!_kbhit())
{
//Run
status = UsbDrDaqRun(g_handle, nSamples, BM_SINGLE);
//Wait until unit is ready
isReady = 0;
while(isReady == 0)
{
status = UsbDrDaqReady(g_handle, &isReady);
}
nSamplesCollected = nSamplesPerChannel;
status = UsbDrDaqGetValues(g_handle, samples, &nSamplesCollected, &overflow, &triggerIndex);
//Print out the first 10 readings, converting the readings to mV if required
printf ("First 10 readings of %i (press any key to stop)\n\n", nSamplesCollected);
for (i = 0; i < 10; i++)
{
printf ("%d\n", adc_to_mv(samples[i]));
}
for (i = 0; i < nSamplesCollected; i++)
{
fprintf (fp, "%d\n", adc_to_mv(samples[i]));
}
Sleep(100);
}
fclose(fp);
status = UsbDrDaqStop(g_handle);
_getch();
}