Exemple #1
0
STDMETHODIMP CLabInput::ChildChange(DWORD typeofchange, NESTABLEPROP *pChan)
{
    if ((typeofchange & CHILDCHANGE_REASON_MASK)== ADD_CHILD)
    {
        int MaxChannels=_chanType.Value==DIFFERENTIAL ? GetDevCaps()->nDIInputIDs : GetDevCaps()->nSEInputIDs;
        if (_nChannels>=MaxChannels)
            return Error(L"Lab and LPM boards may not scan more channels then are present on the board.");
    }

    return Cnia2d::ChildChange( typeofchange, pChan);
}
Exemple #2
0
STDMETHODIMP CLabInput::SetProperty(long User, VARIANT *newVal)
{
    if (User==(long)&_chanSkew && GetDevCaps()->Is700())
    {
        return Error(L"Channel skew may not be set on LPM type devices because ChannelSkewMode must be Equisample.");
    }
    return Cnia2d::SetProperty(User,newVal);
}
Exemple #3
0
HRESULT CLabInput::Open(IDaqEngine *engine,int id,DevCaps* DeviceCaps)
{
    RETURN_HRESULT(Cnia2d::Open(engine, id,DeviceCaps));
    if (GetDevCaps()->Is700())
    {
        _chanSkewMode->ClearEnumValues();
        _chanSkewMode->AddMappedEnumValue(EQUISAMPLE, L"Equisample");
        _chanSkewMode=EQUISAMPLE;
        _chanSkewMode->put_DefaultValue(CComVariant(EQUISAMPLE));
        UpdateTimeing(FORSET);
    }

    return S_OK;
}
Exemple #4
0
int CLabInput::TriggerSetup()
{
    short starttrig=0;
    _ASSERTE(!GetDevCaps()->IsESeries()); // E series not supported by this function

    if (_triggerType & TRIG_TRIGGER_IS_HARDWARE)
    {
        switch(_triggerType)
        {
        case HW_DIGITAL:
            starttrig=1;
            break;
        default:
            return E_E_SERIES_ONLY;
        }
    }
    return(DAQ_Config(_id, starttrig, (short)_clockSrc));
}
//----------------------------------------------------------------------------
//	初期化
//----------------------------------------------------------------------------
int hidasp_init(int type, const char *serial)
{
	unsigned char rd_data[BUFF_SIZE];
	int i, r, result;

	result = 0;

	LoadHidDLL();
	if (OpenTheHid(serial, 0) == 0) {
#if DEBUG
		fprintf(stderr, "ERROR: fail to OpenTheHid(%s)\n", serial);
#endif
		return HIDASP_MODE_ERROR;
	}

	GetDevCaps();

#if DEBUG
	fprintf(stderr, "HIDaspx Connection check!\n");
#endif

	for (i = 0; i < CHECK_COUNT; i++) {
		hidCommand(HIDASP_TEST,(i),0,0);	// Connection test
		r = hidRead(hHID, rd_data ,REPORT_LENGTH1, REPORT_ID1);

#if DEBUG
		fprintf(stderr, "HIDasp Ping(%2d) = %d\n", i, rd_data[4]);
#endif
		if (r == 0) {
			fprintf(stderr, "Error: fail to Read().\n");
			return HIDASP_MODE_ERROR;
		}

		dev_id         = rd_data[2];
		dev_version    = rd_data[3] | (rd_data[4]<<8) ;
		dev_bootloader = rd_data[5];

		if((dev_id != DEV_ID_PIC)
		 &&(dev_id != DEV_ID_PIC18F14K)) {
			fprintf(stderr, "Error: fail to ping test. (id = %x)\n",dev_id);
			return HIDASP_MODE_ERROR;
		}

		if (hidmon_mode) {
//			fprintf(stderr, "TARGET DEV_ID=%x\n",dev_id);
		}

		if (rd_data[6] != i) {
			fprintf(stderr, "Error: fail to ping test. %d != %d\n", rd_data[6] , i);
			return HIDASP_MODE_ERROR;
		}
	}

	{	char *sBoot="";
		if(dev_bootloader==1) {sBoot="(Bootloader)";}
		fprintf(stderr, "TARGET DEV_ID=%x VER=%d.%d%s\n",dev_id
				,dev_version>>8,dev_version & 0xff,sBoot);
	}

#if	1
	if (!hidmon_mode) {
		hidCommand(HIDASP_SET_STATUS,0,HIDASP_RST_H_GREEN,0);	// RESET HIGH
		// ↓PIC18Fファームの場合、ハンドシェークパケットは必ず受け取る必要がある.
	r = hidRead(hHID, rd_data ,REPORT_LENGTH1, REPORT_ID1);
	if( rd_data[1] == 0xaa ) {				// ISPコマンド(isp_enable)が正常動作した.
		have_isp_cmd = HIDASP_ISP_MODE;		// ISP制御OK.
		result |= HIDASP_ISP_MODE;
	} else if( rd_data[1] == DEV_ID_FUSION ) {
		result |= HIDASP_FUSION_OK;			// NEW firmware
	} else if( rd_data[1] == DEV_ID_STD ) {
		result &= ~HIDASP_FUSION_OK;		// OLD firmware
	} else if( rd_data[1] == DEV_ID_MEGA88 ) {		// USB-IO mode
		result |= HIDASP_USB_IO_MODE;		// ISP制御NG.
	} else if( rd_data[1] == DEV_ID_MEGA88_USERMODE ) {		// USB-IO mode
		result |= HIDASP_USB_IO_MODE;		// ISP制御NG.
	}

#if DEBUG
	if (result & HIDASP_ISP_MODE) {
		fprintf(stderr, "[ISP CMD] ");
	}
	if (result & HIDASP_FUSION_OK) {
		fprintf(stderr, "[FUSION] ");
	}
	if (result & HIDASP_USB_IO_MODE) {
		fprintf(stderr, "[USB-IO mode] ");
	}
	if (result == 0) {
		fprintf(stderr, "ISP CMD Not support.\n");
	} else {
		fprintf(stderr, "OK.\n");
	}
#endif
#endif
	}

	return result;
}
int hidasp_init(int type, const char *serial)
{
	unsigned char rd_data[BUFF_SIZE];
	int i, r, result;

	result = 0;

	chg_vid_pid(type);
	LoadHidDLL();
	if (OpenTheHid(serial, 0) == 0) {
#if DEBUG
		fprintf(stderr, "ERROR: fail to OpenTheHid(%s)\n", serial);
#endif
		return HIDASP_MODE_ERROR;
	}

	GetDevCaps();
//	Sleep(100);

#if DEBUG
	fprintf(stderr, "HIDaspx Connection check!\n");
#endif

	for (i = 0; i < CHECK_COUNT; i++) {
		hidCommand(HIDASP_TEST,(i),0,0);	// Connection test
		r = hidRead(hHID, rd_data ,REPORT_LENGTH1, REPORT_ID1);
#if DEBUG
		fprintf(stderr, "HIDasp Ping(%2d) = %d\n", i, rd_data[1]);
#endif
		if (r == 0) {
			fprintf(stderr, "Error: fail to Read().\n");
			return HIDASP_MODE_ERROR;
		}
		dev_id = rd_data[1];
		if((dev_id != DEV_ID_FUSION)
		 &&(dev_id != DEV_ID_STD)
		 &&(dev_id != DEV_ID_MEGA88)
		 &&(dev_id != DEV_ID_MEGA88_USERMODE)) {
			fprintf(stderr, "Error: fail to ping test. (id = %x)\n",dev_id);
			return HIDASP_MODE_ERROR;
		}

		if (hidmon_mode) {
			fprintf(stderr, "TARGET DEV_ID=%x\n",dev_id);
		}

		if (rd_data[2] != i) {
			fprintf(stderr, "Error: fail to ping test. %d != %d\n", rd_data[2] , i);
			return HIDASP_MODE_ERROR;
		}
	}
	if (!hidmon_mode) {
		hidCommand(HIDASP_SET_STATUS,0,HIDASP_RST_H_GREEN,0);	// RESET HIGH
	}
#if	HIDMON88
		hidCommand(HIDASP_BOOT_RWW,0,0,0);	// Read-While-Write-Section Read Enable.
#endif
	r = hidRead(hHID, rd_data ,REPORT_LENGTH1, REPORT_ID1);
	if( rd_data[1] == 0xaa ) {				// ISPコマンド(isp_enable)が正常動作した.
		have_isp_cmd = HIDASP_ISP_MODE;		// ISP制御OK.
		result |= HIDASP_ISP_MODE;
	} else if( rd_data[1] == DEV_ID_FUSION ) {
		result |= HIDASP_FUSION_OK;			// NEW firmware
	} else if( rd_data[1] == DEV_ID_STD ) {
		result &= ~HIDASP_FUSION_OK;		// OLD firmware
	} else if( rd_data[1] == DEV_ID_MEGA88 ) {		// USB-IO mode
		result |= HIDASP_USB_IO_MODE;		// ISP制御NG.
	} else if( rd_data[1] == DEV_ID_MEGA88_USERMODE ) {		// USB-IO mode
		result |= HIDASP_USB_IO_MODE;		// ISP制御NG.
	}
#if DEBUG
	if (result & HIDASP_ISP_MODE) {
		fprintf(stderr, "[ISP CMD] ");
	}
	if (result & HIDASP_FUSION_OK) {
		fprintf(stderr, "[FUSION] ");
	}
	if (result & HIDASP_USB_IO_MODE) {
		fprintf(stderr, "[USB-IO mode] ");
	}
	if (result == 0) {
		fprintf(stderr, "ISP CMD Not support.\n");
	} else {
		fprintf(stderr, "OK.\n");
	}
#endif
	return result;
}
Exemple #7
0
HRESULT CLabInput::UpdateTimeing(ConfigReason reason)
{
    double newChanSkew=_chanSkew;
    double newRate=GetTargetSampleRate();

    newRate=GetDevCaps()->FindRate(newRate,&_scanTB,&_scanInterval); // base from samplerate
    if (_nChannels<2)
    {
        newChanSkew=(GetDevCaps()->settleTime+10)*1e-6;
    }
    else
    {
        switch (_chanSkewMode)
        {
        case CHAN_SKEW_MIN:
        {
            // settleTime is in uSec
            // we use a 10 uSec slop factor at the advice of NI
            double settleTime = GetDevCaps()->settleTime + 10;
            if (settleTime/1e6*(_nChannels+2) > 1.0/GetTargetSampleRate())
            {
                // switch to equalsample
                newChanSkew=1.0/RoundRate(_sampleRate*_nChannels);
                if (newChanSkew* (_nChannels+2) >= 1.0/GetTargetSampleRate())
                    // if no time to scan then use equal sample
                {
                    _scanInterval=0;
                    newChanSkew=1/(GetDevCaps()->FindRate(GetTargetSampleRate()*_nChannels,&_scanTB,&_sampleInterval));
                    // now fix up sample rate
                    newRate=1.0/ (newChanSkew *_nChannels);
                }
            }
            else
            {   // using min
                // DAQ_ Rate(settleTime/1e6, 1, &_sampleTB, &_sampleInterval);
                // *chanSkew=_sampleInterval*Timebase2ClockResolution(_sampleTB);
                double clockfreq=1.0/Timebase2ClockResolution(_scanTB);
                _sampleInterval=static_cast<unsigned short>(floor(clockfreq*settleTime/1e6+.01)); // spec says one percent tol (of what?)

                newChanSkew=_sampleInterval/clockfreq;
            }
        }
        break;
        case EQUISAMPLE:
        {
            newChanSkew=1/(GetDevCaps()->FindRate(GetTargetSampleRate()*_nChannels,&_scanTB,&_sampleInterval));
            _scanInterval=0;
            // now fix up sample rate
            newRate=1.0/ (newChanSkew *_nChannels);
        }
        break;
        case  CHAN_SKEW_MANUAL:
        {
            double clockfreq=1.0/Timebase2ClockResolution(_scanTB);
            _sampleInterval=static_cast<unsigned short>(floor(clockfreq*newChanSkew+.01)); // spec says one percent tol (of what?)
            newChanSkew=_sampleInterval/clockfreq;
        }
        break;
        default:
            break;
        }
    }
    // put the new value back to the engine.
    if (_chanSkew!=newChanSkew)
    {
        _chanSkew=newChanSkew;
    }
    if (newRate!=_sampleRate)
    {
        _sampleRate=newRate;
    }
    return S_OK;
}