DrDaq Streaming from three Channels problem

Post your C and C++ discussions here
Post Reply
giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

DrDaq Streaming from three Channels problem

Post by giovanni »

Dear,
i am trying to develop a deamon c that reads three channels of the drdaq (light, temperature and sound level) and send them to a java process via socket.
The socket session works but the session relates to the reading the values looks fail.
I have used the code in the SDk to begint he deleloping.
I post the code of the init fucntion and the streaming function.

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);
//-----------------------------------------------------------------------------------------------------------
the output of the server side look like that:

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
------
Please help me!!!

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hello Giovanni,

When the data values are returned in the array, they will be in the order

Ch 1, Ch 2, Ch 3, Ch 1, Ch 2, Ch 3, ... etc.

I think in your loop you should be incremeting the value of i by 3

e.g.

Code: Select all

while(   (i
That should hopefully extract the data correctly :)

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

Dear,

thank you for your response, that was a really stupid problem but with you r help i fixed it.
Now i am facing with something more worse.

The code i same but there are some periods in which the values of parameter as totally wrong.

I post the results:

client>(lignt, temp, sound)
client>156;296;5
client>161;296;5
client>167;296;3
client>170;296;3
client>173;296;3
client>175;296;0
client>175;296;0
client>173;296;3
client>170;296;4
client>164;296;5
client>157;296;7
client>149;296;5
client>142;296;4
client>138;296;1
client>136;296;1
client>135;296;0
client>137;296;3
client>140;296;1
client>144;296;0
client>150;296;1 <- What is happen after this point?!?!?!
client>500;805;-67
client>501;827;-66
client>500;848;-66
client>500;861;-67
client>501;32767;-66
client>500;32767;-66
client>500;862;-67
client>499;852;-67
client>500;835;-66
client>501;820;-66
client>501;803;-66
client>501;788;-66
client>501;774;-66
client>501;764;-67
client>500;756;-66
client>500;752;-66
client>501;752;-66
client>501;758;-66
client>502;766;-66
client>499;781;-66
client>501;802;-66
client>501;825;-66
client>501;845;-66
client>500;860;-66
client>499;32767;-67
client>500;32767;-66
client>500;862;-66
client>500;852;-66
client>501;837;-66
client>501;820;-67
client>501;805;-66
client>501;789;-67
client>501;776;-66
client>501;765;-67
client>500;758;-66
client>500;754;-67
client>500;755;-66


Please help me..again!!

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi,

Are you getting any overflow indications?

Is this consistently happening and does the same thing occur if you use PicoScope 6 or PicoLog to capture data using the same settings?

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

hi,

no i did not have any indication about overflow.

When i use picoscope 6 every thing works fine but i do not to know how to look if the settings are the same....

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi giovanni,

In PicoScope 6 click Views -> View Properties in order to see the sampling rate and number of samples being collected.

You can then adjust your settings (samples and collection time) accordingly.

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

The parameters are

sampling period: 19 uS

sampling rate: 52,63 KS/Sec

Number of samples: 5236

How can i set my C program with such as parameters?

Regards!!

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi Giovanni,

Could you please send me a PicoScope 6 data file showing the readings so I can check the settings.

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

really sorry but how can i get a PicoScope 6 data file? i think i have to connect the device and then start the reading.
and then?

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi Giovanni,

Once you have connected the device and captured some data, click File -> Save As..., then enter a name and click Save.

This will save a data file in the form .psdata

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

Dears,

hereby the psdata file.

Thank you!!!
Attachments
20141104-0001_data.psdata
(150.15 KiB) Downloaded 558 times

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

this is another one.
thank you!
Attachments
20141104-0001_data_2.psdata
(165.08 KiB) Downloaded 515 times

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi Giovanni,

Thank you for the files.

In the call to UsbDrDaqSetInterval try setting the following:

Code: Select all

usForBlock = 100000; //100ms
nSamples = 5236;
along with your selected channels.

When you call UsbDrDaqRun, ensure that nSamples is used as above.

I hope this helps.

Regards,

giovanni
Newbie
Posts: 0
Joined: Tue Oct 07, 2014 8:34 am

Re: DrDaq Streaming from three Channels problem

Post by giovanni »

it does not work... can you post me the code for the setting of the device?

Hitesh

Re: DrDaq Streaming from three Channels problem

Post by Hitesh »

Hi Giovanni,

Please find below the modified code:

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();
}

Please note that the sound waveform can have negative values. What are you capturing the sound waveform from?

Have you tried plotting the data?

I hope this helps. If you are still having issues, please post your code file here or send it to support@picotech.com

Post Reply