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);
92 unsigned __stdcall vrpn_Nidaq::runThread(
void *pVrpnNidaq) {
93 ((vrpn_Nidaq *)pVrpnNidaq)->runNidaq();
98 void 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);
129 vrpn_Nidaq::~vrpn_Nidaq() {
131 WaitForSingleObject(hDAQThread,INFINITE);
138 void vrpn_Nidaq::mainloop(
void) {
143 int vrpn_Nidaq::doing_okay() {
144 return (pDAQ->status()==DAQ::RUNNING);
147 void vrpn_Nidaq::report_changes() {
165 EnterCriticalSection(&csAnalogBuffer);
176 double dTime = dSampleTime;
177 LeaveCriticalSection(&csAnalogBuffer);
183 if (d_connection->pack_message(cChars, tv, channel_m_id, d_sender_id, rgch,
185 cerr <<
"vrpn_Nidaq::report_changes: cannot write message: tossing.\n";
188 LeaveCriticalSection(&csAnalogBuffer);
197 cerr <<
"vrpn_Nidaq::report_changes: no valid connection.\n";
200 #endif // def(VRPN_USE_NIDAQ) 201 #endif // def(WIN32) || def(_WIN32) const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
timeval vrpn_TimevalDiff(const timeval &tv1, const timeval &tv2)
Generic connection class not specific to the transport mechanism.
timeval vrpn_MsecsTimeval(const double dMsecs)
#define vrpn_gettimeofday
virtual vrpn_int32 encode_to(char *buf)
timeval vrpn_TimevalSum(const timeval &tv1, const timeval &tv2)