// Author & Date: Ehsan Azar 29 March 2011 // Purpose: Open and connect to the library void CSDKSampleDlg::OnBtnConnect() { cbSdkResult res = cbSdkOpen(0); if (res != CBSDKRESULT_SUCCESS) { PrintError(res); return; } cbSdkConnectionType conType; cbSdkInstrumentType instType; // Return the actual openned connection res = cbSdkGetType(0, &conType, &instType); if (res != CBSDKRESULT_SUCCESS) { SetStatusWindow("Unable to determine connection type"); return; } cbSdkVersion ver; res = cbSdkGetVersion(0, &ver); if (res != CBSDKRESULT_SUCCESS) { SetStatusWindow("Unable to determine nsp version"); return; } if (conType < 0 || conType > CBSDKCONNECTION_CLOSED) conType = CBSDKCONNECTION_CLOSED; if (instType < 0 || instType > CBSDKINSTRUMENT_COUNT) instType = CBSDKINSTRUMENT_COUNT; char strConnection[CBSDKCONNECTION_CLOSED + 1][8] = {"Default", "Central", "Udp", "Closed"}; char strInstrument[CBSDKINSTRUMENT_COUNT + 1][13] = {"NSP", "nPlay", "Local NSP", "Remote nPlay", "Unknown"}; CString strStatus; SetStatusWindow(strStatus); strStatus.Format("%s real-time interface to %s (%d.%02d.%02d.%02d) successfully initialized\n", strConnection[conType], strInstrument[instType], ver.nspmajor, ver.nspminor, ver.nsprelease, ver.nspbeta); SetStatusWindow(strStatus); // Slider shows analog threshold m_sldThresh.SetRange(-255, 255, TRUE); m_sldThresh.SetPageSize(5); m_cboChannel.ResetContent(); char label[cbLEN_STR_LABEL + 1]; for(UINT16 chan = 1; chan <= cbNUM_ANALOG_CHANS; chan++) { label[cbLEN_STR_LABEL] = 0; res = cbSdkGetChannelLabel(0, chan, NULL, label, NULL, NULL); if (res == CBSDKRESULT_SUCCESS) m_cboChannel.AddString(label); } if (m_cboChannel.GetCount() > 0) m_cboChannel.SetCurSel(m_channel - 1); SetChannel(m_channel); }
// Author & Date: Ehsan Azar 29 March 2011 // Purpose: Show version information in about dialog BOOL CAboutDlg::OnInitDialog() { CString strOld, strNew; CDialog::OnInitDialog(); cbSdkVersion ver; cbSdkResult res = cbSdkGetVersion(0, &ver); GetDlgItemText(IDC_STATIC_APP_VERSION, strOld); strNew.Format("%s v%u.%02u.%02u.%02u", strOld, ver.major, ver.minor, ver.release, ver.beta); SetDlgItemText(IDC_STATIC_APP_VERSION, strNew); GetDlgItemText(IDC_STATIC_LIB_VERSION, strOld); strNew.Format("%s v%u.%02u", strOld, ver.majorp, ver.minorp); SetDlgItemText(IDC_STATIC_LIB_VERSION, strNew); GetDlgItemText(IDC_STATIC_NSP_APP_VERSION, strOld); cbSdkConnectionType conType; cbSdkInstrumentType instType; // Return the actual openned connection if (res == CBSDKRESULT_SUCCESS) { res = cbSdkGetType(0, &conType, &instType); if (res == CBSDKRESULT_SUCCESS) { if (instType != CBSDKINSTRUMENT_LOCALNSP && instType != CBSDKINSTRUMENT_NSP) strOld = "nPlay"; if (conType == CBSDKCONNECTION_CENTRAL) strOld += "(Central)"; } strNew.Format("%s v%u.%02u.%02u.%02u", strOld, ver.nspmajor, ver.nspminor, ver.nsprelease, ver.nspbeta); SetDlgItemText(IDC_STATIC_NSP_APP_VERSION, strNew); GetDlgItemText(IDC_STATIC_NSP_LIB_VERSION, strOld); strNew.Format("%s v%u.%02u", strOld, ver.nspmajorp, ver.nspminorp); SetDlgItemText(IDC_STATIC_NSP_LIB_VERSION, strNew); } else { SetDlgItemText(IDC_STATIC_NSP_APP_VERSION, strOld + " not connected"); SetDlgItemText(IDC_STATIC_NSP_LIB_VERSION, ""); } return TRUE; }
int cbpy_version(int nInstance, cbSdkVersion *ver) { cbSdkResult sdkres = cbSdkGetVersion(nInstance, ver); return sdkres; }
// Purpose: Test openning the library cbSdkResult testOpen(void) { cbSdkConnectionType conType = CBSDKCONNECTION_DEFAULT; // Library version can be read even before library open (return value is a warning) // actual NSP version however needs library to be open cbSdkVersion ver; cbSdkResult res = cbSdkGetVersion(INST, &ver); printf("Initializing Cerebus real-time interface %d.%02d.%02d.%02d (protocol cb%d.%02d)...\n", ver.major, ver.minor, ver.release, ver.beta, ver.majorp, ver.minorp); cbSdkInstrumentType instType; res = cbSdkOpen(INST, conType); switch (res) { case CBSDKRESULT_SUCCESS: break; case CBSDKRESULT_NOTIMPLEMENTED: printf("Not implemented\n"); break; case CBSDKRESULT_INVALIDPARAM: printf("Invalid parameter\n"); break; case CBSDKRESULT_WARNOPEN: printf("Real-time interface already initialized\n"); case CBSDKRESULT_ERROPENCENTRAL: printf("Unable to open library for Central interface\n"); break; case CBSDKRESULT_ERROPENUDP: printf("Unable to open library for UDP interface\n"); break; case CBSDKRESULT_ERROPENUDPPORT: res = cbSdkGetType(INST, NULL, &instType); if (instType == CBSDKINSTRUMENT_NPLAY || instType == CBSDKINSTRUMENT_REMOTENPLAY) printf("Unable to open UDP interface to nPlay\n"); else printf("Unable to open UDP interface\n"); break; case CBSDKRESULT_OPTERRUDP: printf("Unable to set UDP interface option\n"); break; case CBSDKRESULT_MEMERRUDP: printf("Unable to assign UDP interface memory\n" " Consider using sysctl -w net.core.rmem_max=8388608\n" " or sysctl -w kern.ipc.maxsockbuf=8388608\n"); break; case CBSDKRESULT_INVALIDINST: printf("Invalid UDP interface\n"); break; case CBSDKRESULT_ERRMEMORYTRIAL: printf("Unable to allocate RAM for trial cache data\n"); break; case CBSDKRESULT_ERROPENUDPTHREAD: printf("Unable to Create UDP thread\n"); break; case CBSDKRESULT_ERROPENCENTRALTHREAD: printf("Unable to start Cerebus real-time data thread\n"); break; case CBSDKRESULT_ERRINIT: printf("Library initialization error\n"); break; case CBSDKRESULT_ERRMEMORY: printf("Library memory allocation error\n"); break; case CBSDKRESULT_TIMEOUT: printf("Connection timeout error\n"); break; case CBSDKRESULT_ERROFFLINE: printf("Instrument is offline\n"); break; default: printf("Unexpected error\n"); break; } if (res >= 0) { // Return the actual openned connection res = cbSdkGetType(INST, &conType, &instType); if (res != CBSDKRESULT_SUCCESS) printf("Unable to determine connection type\n"); res = cbSdkGetVersion(INST, &ver); if (res != CBSDKRESULT_SUCCESS) printf("Unable to determine instrument version\n"); if (conType < 0 || conType > CBSDKCONNECTION_CLOSED) conType = CBSDKCONNECTION_COUNT; if (instType < 0 || instType > CBSDKINSTRUMENT_COUNT) instType = CBSDKINSTRUMENT_COUNT; char strConnection[CBSDKCONNECTION_COUNT + 1][8] = {"Default", "Central", "Udp", "Closed", "Unknown"}; char strInstrument[CBSDKINSTRUMENT_COUNT + 1][13] = {"NSP", "nPlay", "Local NSP", "Remote nPlay", "Unknown"}; printf("%s real-time interface to %s (%d.%02d.%02d.%02d) successfully initialized\n", strConnection[conType], strInstrument[instType], ver.nspmajor, ver.nspminor, ver.nsprelease, ver.nspbeta); } return res; }