13#if defined(WIN32) || defined(_WIN32)
14#if defined(VRPN_USE_NIDAQ)
27 double dSamplingRate,
double dInterChannelRate,
28 short sDeviceNumber,
int cChannels,
29 short rgsChan[],
short rgsGain[],
30 short sInputMode,
short sPolarity,
int fNice)
31 :
vrpn_Analog(pchName, pConnection), pDAQ(NULL), fNice(fNice), fStop(0),
32 fNewData(0), dSampleTime(0) {
35 cerr <<
"vrpn_Nidaq::vrpn_Nidaq: vrpn_Analog allows only "
37 <<
" requested). DAQ not initialized." << endl;
42 MMRESULT res = timeBeginPeriod(1);
43 if (res != TIMERR_NOERROR) {
44 cerr <<
"NidaqServer: timeBeginPeriod() failed!!!\n";
48 num_channel = cChannels;
49 daqSample.resize(cChannels);
55 struct timeval tv, tvUpTime;
56 double dTime1, dTime2;
67 dTime1 = (dTime1 + dTime2)/2.0;
83 pDAQ =
new DAQ(dSamplingRate, dInterChannelRate, sDeviceNumber, cChannels,
84 rgsChan, rgsGain, sInputMode, sPolarity);
87 InitializeCriticalSection(&csAnalogBuffer);
88 hDAQThread = (HANDLE) _beginthreadex(NULL, 0, runThread,
this, 0, NULL);
92unsigned __stdcall vrpn_Nidaq::runThread(
void *pVrpnNidaq) {
93 ((vrpn_Nidaq *)pVrpnNidaq)->runNidaq();
98void vrpn_Nidaq::runNidaq() {
111 if (pDAQ->getSample(&daqSample)) {
115 EnterCriticalSection(&csAnalogBuffer);
116 for (
int i=0;i<daqSample.cChannels;i++) {
117 channel[i]=daqSample.rgd[i];
120 dSampleTime=daqSample.dTime;
121 LeaveCriticalSection(&csAnalogBuffer);
129vrpn_Nidaq::~vrpn_Nidaq() {
131 WaitForSingleObject(hDAQThread,INFINITE);
138 fprintf(stderr,
"vrpn_Nidaq::~vrpn_Nidaq(): delete failed\n");
143void vrpn_Nidaq::mainloop(
void) {
148int vrpn_Nidaq::doing_okay() {
149 return (pDAQ->status()==DAQ::RUNNING);
152void vrpn_Nidaq::report_changes() {
170 EnterCriticalSection(&csAnalogBuffer);
181 double dTime = dSampleTime;
182 LeaveCriticalSection(&csAnalogBuffer);
188 if (d_connection->pack_message(cChars, tv, channel_m_id, d_sender_id, rgch,
190 cerr <<
"vrpn_Nidaq::report_changes: cannot write message: tossing.\n";
193 LeaveCriticalSection(&csAnalogBuffer);
202 cerr <<
"vrpn_Nidaq::report_changes: no valid connection.\n";
virtual vrpn_int32 encode_to(char *buf)
Generic connection class not specific to the transport mechanism.
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
timeval vrpn_TimevalDiff(const timeval &tv1, const timeval &tv2)
timeval vrpn_MsecsTimeval(const double dMsecs)
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)
#define vrpn_gettimeofday