Cat
NI6008.cpp
Go to the documentation of this file.
1 // $Id: $
2 #include <NIDAQmxBase.h>
3 // Include files
4 #include "Application.h"
5 
6 // local
7 #include "NI6008.h"
8 
9 //-----------------------------------------------------------------------------
10 // ImplementatI_On file for class : NI6008
11 //
12 // 2016-05-27 :
13 //-----------------------------------------------------------------------------
14 
15 #ifndef NODAQ
16 #define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
17 #endif
18 
19 //=============================================================================
20 // Standard constructor, initializes variables
21 //=============================================================================
23  setName("NI6008");
24  setType("NI6008");
26 }
27 //=============================================================================
28 // Destructor
29 //=============================================================================
31  info("Closing the NI6008 socket.");
32  close(m_sockfd);
33 }
34 
35 //=============================================================================
36 //
37 //=============================================================================
38 std::string NI6008::cmd(std::string dev, std::string mess){
39  int n;
40  std::string cmd = dev + std::string(" ") + mess;
41  std::copy(cmd.begin(), cmd.end(), buffer);
42  // strcat(buffer, " ");
43  // strcat(buffer, mess.c_str());
44  buffer[cmd.size()] = '\0';
45  // std::cout<<"sending:"<<buffer<<" length="<<strlen(buffer)<<std::endl;
46  n = write(m_sockfd,buffer,strlen(buffer));
47  if (n < 0) error("ERROR writing to socket");
48  bzero(buffer,256);
49  n = read(m_sockfd,buffer,255);
50  if (n < 0) error("ERROR reading from socket");
51  // printf("%s\n",buffer);
52  return std::string(buffer);
53 }
54 
55 // //=============================================================================
56 // //
57 // //=============================================================================
58 // std::vector<double> NI6008::ai(){
59 // // Task parameters
60 // int32 error = 0;
61 // TaskHandle taskHandle = 0;
62 // char errBuff[2048]={'\0'};
63 // // char chan[80];
64 
65 // // sprintf(chan,"%s/ai0,%s/ai1,%s/ai2,%s/ai3",
66 // // m_device.c_str(), m_device.c_str(), m_device.c_str(), m_device.c_str());
67 // char chan[] = "Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3";
68 
69 // // Channel parameters
70 // float64 min = -10.0;
71 // float64 max = 10.0;
72 
73 // // Timing parameters
74 // uInt64 samplesPerChan = 4;
75 
76 // // Data read parameters
77 // int32 pointsToRead = 1;
78 // int32 pointsRead;
79 // float64 timeout = 10.0;
80 // // float64 timeout = m_timeout;
81 // bool32 done = false;
82 // float64 data[4];
83 // data[0]=0.;
84 // data[1]=0.;
85 // data[2]=0.;
86 // data[3]=0.;
87 // std::cout<<"ai "<<chan<<std::endl;
88 // std::cout<<data[0]<<" "<<data[1]<<" "<<data[2]<<" "<<data[3]<<std::endl;
89 // //#ifndef NODAQ
90 // error = DAQmxBaseCreateTask("",&taskHandle);
91 // std::cout<<"error create task:"<<error<<std::endl;;
92 // std::cout<<&taskHandle<<std::endl;
93 // error = DAQmxBaseCreateAIVoltageChan(taskHandle,
94 // chan,
95 // "",
96 // DAQmx_Val_Cfg_Default,
97 // min,max,
98 // DAQmx_Val_Volts,
99 // NULL);
100 // std::cout<<"error ai task:"<<error<<std::endl;
101 // error = DAQmxBaseStartTask(taskHandle);
102 // std::cout<<"error start task:"<<error<<std::endl;
103 // wait(1000);
104 // error = DAQmxBaseReadAnalogF64(taskHandle,
105 // pointsToRead,
106 // timeout,
107 // DAQmx_Val_GroupByChannel,
108 // data,
109 // samplesPerChan,
110 // &pointsRead,
111 // NULL);
112 // wait(1000);
113 // std::cout<<"error read analog:"<<error<<std::endl;
114 // std::cout<<done<<std::endl;
115 // error = DAQmxBaseIsTaskDone(taskHandle, &done);
116 // std::cout<<"error task done:"<<error<<std::endl;
117 // std::cout<<done<<std::endl;
118 // error = DAQmxBaseStopTask(taskHandle);
119 // std::cout<<"error stop task:"<<error<<std::endl;
120 // error = DAQmxBaseClearTask(taskHandle);
121 // std::cout<<"error clear task:"<<error<<std::endl;
122 
123 // // Error:
124 // // if( DAQmxFailed(error) )
125 // // DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
126 // // if( taskHandle!=0 ) {
127 // // DAQmxBaseStopTask(taskHandle);
128 // // DAQmxBaseClearTask(taskHandle);
129 // // }
130 // // if( DAQmxFailed(error) )
131 // // printf ("DAQmxBase Error %ld: %s\n", error, errBuff);
132 // //#endif
133 // std::cout<<data[0]<<" "<<data[1]<<" "<<data[2]<<" "<<data[3]<<std::endl;
134 // std::vector<double> result;
135 // result.push_back(data[0]);
136 // result.push_back(data[1]);
137 // result.push_back(data[2]);
138 // result.push_back(data[3]);
139 // std::cout<<result[0]<<" "<<result[1]<<" "<<result[2]<<" "<<result[3]<<std::endl;
140 // return result;
141 // }
142 
143 // //=============================================================================
144 // //
145 // //=============================================================================
146 // int NI6008::di( ) {
147 // // Task parameters
148 // int code = 0;
149 // int32 error = 0;
150 // TaskHandle taskHandle = 0;
151 // int32 i;
152 // const uInt32 num_ports = 2;
153 // char errBuff[2048];
154 
155 // // Channel parameters
156 // // char chan1[32];
157 // // char chan2[32];
158 // // sprintf(chan1,"%s/port0", dev);
159 // // sprintf(chan2,"%s/port1", dev);
160 // char chan1[] = "Dev1/port0";
161 // char chan2[] = "Dev1/port1";
162 // unsigned char r_data[2];
163 // // Read parameters
164 // int32 read;
165 
166 // #ifndef NODAQ
167 // // Create Digital Input (DI) Task and Channel
168 // DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle));
169 // DAQmxErrChk (DAQmxBaseCreateDIChan(taskHandle,chan1,"",DAQmx_Val_ChanForAllLines));
170 // DAQmxErrChk (DAQmxBaseCreateDIChan(taskHandle,chan2,"",DAQmx_Val_ChanForAllLines));
171 
172 // // Start Task (configure port)
173 // DAQmxErrChk (DAQmxBaseStartTask (taskHandle));
174 
175 // // Read from port
176 // DAQmxErrChk (
177 // code = DAQmxBaseReadDigitalU8(
178 // taskHandle,
179 // 1,
180 // 10.0,
181 // DAQmx_Val_GroupByChannel,
182 // r_data,
183 // num_ports,
184 // &read,
185 // NULL)
186 // );
187 // info("Processing DI "+std::string(chan1)+"/"+std::string(chan2)+
188 // " ->"+ itos(r_data[0])+", "+itos(r_data[1]));
189 
190 // Error:
191 
192 // if (DAQmxFailed (error))
193 // DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);
194 // if (taskHandle != 0){
195 // DAQmxBaseStopTask (taskHandle);
196 // DAQmxBaseClearTask (taskHandle);
197 // }
198 // if (error)printf ("DAQmxBase Error %ld: %s\n", error, errBuff);
199 // #endif
200 // return 0;
201 // }
void info(std::string mymsg)
Definition: Object.h:38
char buffer[256]
Definition: NI6008.h:144
void setName(std::string name)
Definition: Object.h:51
virtual ~NI6008()
Destructor.
Definition: NI6008.cpp:30
std::string hostname()
Definition: Application.h:173
int m_sockfd
Definition: NI6008.h:141
Application * application()
Definition: Tools.cpp:42
void setType(std::string type)
Definition: Object.h:52
void error(std::string mymsg)
Definition: Object.h:40
std::string cmd(std::string, std::string)
Definition: NI6008.cpp:38
NI6008()
Standard constructor.
Definition: NI6008.cpp:22
std::string m_host
Definition: NI6008.h:139