Exemple #1
0
//------------------------------------------------------------------------------
// Read one temperatures channel (ascii mode)
double mbug_2818_read( mbug_device dev, int channel )
{
	double temperatures[8];
	int ret;
	
	ret = mbug_2818_read_all(dev, temperatures, 8);
	if (ret<0) return NOT_A_TEMPERATURE;
	if (channel>8) return NOT_A_TEMPERATURE;
	return temperatures[channel];
}
Exemple #2
0
int main( int argc, char* argv[] )
{
	int i = 0;
	mbug_device thermometer = 0;
	double tem[8] = {0};
	unsigned short raw[8] = {0};

	parse_options( argc, argv );

	if (action==List)
		{
			// List all attached thermometers
			int i;
			mbug_device_list list = mbug_get_device_list(2818);
			for (i=0; list[i]!=0; i++ ) {
				puts(list[i]);
			}
			return 0;
		}

	if (action==Help)
		{
			puts(usage);
			return 0;
		}

	// Open device
	thermometer = mbug_2818_open(device_serial);
	if (thermometer ==0 )
		errorf( "#### Error opening device." );

	if (action==Read)
	{
		if (format==Raw)
			mbug_2818_read_raw( thermometer, raw, 8 );
		else
			mbug_2818_read_all( thermometer, tem, 8);

		if (format==Fahrenheit)
			for (i=0; i<8; i++)
				tem[i] = tem[i] * 9./5 + 32.;
		else if (format==Kelvin)
			for (i=0; i<8; i++)
				if (tem[i] >= -273.15)
					tem[i] += 273.15;

		if (channels[0]<0)
		{
			// print all values
			for (i=0; i<8; i++) channels[i] = i;
			channels[8] = -1;
		}
		for (i=0; channels[i]>=0 ;i++)
		{
			if (channels[i] > 7)
				channels[i] = 0;
			if (format==Raw)
				printf( "%d", raw[channels[i]] );
			else
				printf( "%.2f", tem[channels[i]] );
			printf( (channels[i+1]<0) ? "\n" : "," );
		}
	}

	mbug_2818_close(thermometer);
	return 0;
}