Exemplo n.º 1
0
STDMETHODIMP CLabInput::GetSingleValues(VARIANT* values)
{

    AUTO_LOCK; // Should not be needed inserted on a whim
    if (!_isConfig)
        DAQ_CHECK(Configure(FORSINGLEVALUE));
    // 3 SCANS IS THE MIN with scan_op
    SAFEARRAY *ps = SafeArrayCreateVector(VT_I2, 0, _nChannels*2);
    if (ps==NULL) return E_SAFEARRAY_ERR;

    // set the data type and values
    V_ARRAY(values)=ps;
    V_VT(values)=VT_ARRAY | VT_I2;
    TSafeArrayAccess <short > binarray(values);

    if (_nChannels<=2)
    {
        for (int i=0; i<_nChannels; i++)
        {
            DAQ_CHECK(AI_Read(_id, _chanList[i], _gainList[i], &binarray[i]));
        }
    }
    else
    {
        // setup the channels to read and scan them
        DAQ_TRACE(Set_DAQ_Device_Info(_id, ND_DATA_XFER_MODE_AI, ND_INTERRUPTS));
        short *dummy=(short*)_alloca(_nChannels*sizeof(short));
        DAQ_CHECK(Lab_ISCAN_Op(_id,static_cast<i16>(_nChannels),_gainList[0],&binarray[0],
                               _nChannels, 1.0/_chanSkew,0,dummy));
    }


    return S_OK;
}
Exemplo n.º 2
0
void binfileread(char * binfile)
{

	ifstream binarray(binfile, ios::in|ios::binary|ios::ate);
	
	if(binarray.is_open())
	{
		int filesize = binarray.tellg();
		int numberofvalues = filesize / sizeof(double);
		cout << "Binary File size is: " << filesize << endl;
		cout << "The number of values from the binary file is: " << numberofvalues << endl;
		
		dmemblock = new double [filesize];
		dmemallocated = true;
		binarray.seekg (0, ios::beg);
		binarray.read(reinterpret_cast<char *>(dmemblock), filesize);
		
		for(int i = 0; i < numberofvalues; i++)
		{
			cout << "Sample " << i << ": " << dmemblock[i] << endl;
		}
		
		binarray.close();
		cout << endl;
		cout << "The complete binary file content is in memory" << endl;
		cout << endl;

	// For alice.txt, Fs = 8kHz and a 'dit' is about 75ms in duration
	// A'dah' will be three times longer than a 'dit'
	// Choosing a 10ms window (80 samples) should give enough resolution
	//
	// ... Add your Code here .....
		/*BEGIN OFChoosing a 10ms Window
		double dresmemblock[numberofvalues];
		int tmp = 0;
		
		for(int i = 0; i < numberofvalues; i++)
		{
			//cout << "Sample " << i << ": " << dmemblock[i] << endl;
			for(int j = 0; j < 80; j++)
			{
				dresmemblock[i] = dresmemblock[i] + dmemblock[i+j];
				if(j == 79)
				{
				dresmemblock[i] = dresmemblock[i] / 80;
				tmp = i+j;
				i = tmp;
				}
			}
			
			//dresmemblock[i] = dmemblock[i];
			cout << "10ms Window #" << (i + 1)/80 << " "<< dresmemblock[i] << endl;
		}
		END OF choosing aa 10ms Window*/
		
		/*int tmp = 0, tmp2 = 0;
		
		for(int i = 0; i < numberofvalues; i++)
		{
			if(dmemblock[i] > 0.08998 || dmemblock[i] < -0.08998)
			{
				tmp = tmp + 1;
				//cout << 1;
				if(tmp == 1800)
				{
					cout << "-";
					tmp = 0;
				}
				if(tmp == 600)
				{
					cout << ".";
					tmp = 0;
				}
			}
			else
			{
				tmp2 = tmp2 + 1;
				if(tmp2 == 600)
				{
				}
				if(tmp2 == 1800)
				{
					cout << "/";
					tmp2 = 0;
				}
				if(tmp2 == 4200)
				{
					cout << " / ";
					tmp2 = 0;
				}
				//cout << 0;
			}
			//cout << "Sample " << i << ": " << dmemblock[i] << endl;
		}*/
	//
		cout << endl;
	moments(dmemblock, numberofvalues);

	}
	else
	{
		cout << "Unable to open file";
	}

	if(dmemallocated)
	{
		free(dmemblock);
	}

	
} // End of binarrayread()