00001
00024 #include <iostream>
00025 #include "ljacklm_wrapper.h"
00026
00027 using namespace std;
00028
00029 int main(int argc, char **argv)
00030 {
00031 int op = 1;
00032 long error = 0;
00033 float v, v0, v1;
00034 int ch;
00035 long n, m, cd, cio;
00036 short i;
00037 long *lineas;
00038 float *voltajes;
00039 char stringError[50];
00040
00041 LabjackDriverInterface * lj = new LjacklmWrapper();
00042
00043 if ((error = lj->config()) != 0) {
00044 GetErrorString(error, stringError);
00045 printf("Error configuring Labjack. %s\n", stringError);
00046 return -1;
00047 }
00048
00049 while(op != 0) {
00050 cout << "\n Options: \n";
00051 cout << "\t 1.Reset\n";
00052 cout << "\t 2.getAI\n";
00053 cout << "\t 3.setAI\n";
00054 cout << "\t 4.getD\n";
00055 cout << "\t 5.setD\n";
00056 cout << "\t 6.getIO\n";
00057 cout << "\t 7.setIO\n";
00058 cout << "\t 8.getDIOs\n";
00059 cout << "\t 9.setDIOs\n";
00060 cout << "\t 10.set&confDIOs\n";
00061 cout << "\t 11.enableWatchdog\n";
00062 cout << "\t 12.disableWatchdog\n";
00063 cout << "\t 13.getAIs\n";
00064 cout << "\t 14.setAOs\n";
00065 cout << "\t 15.setPulso\n";
00066 cout << "\t 16.getDireccionDs\n";
00067 cout << "\t 17.setD&confDIOs\n";
00068 cout << "\t 18.setDIOsCONFIG\n";
00069 cout << "\t 0.FIN\n";
00070 cin >> op;
00071
00072 switch(op) {
00073 case 0:
00074 printf("End communication with labjack\n");
00075 break;
00076 case 1:
00077 printf("Reseting labjack...");
00078
00079 if ((error = lj->reset()) != 0) {
00080 GetErrorString(error, stringError);
00081 printf("Error reseting Labjack. %s\n", stringError);
00082 }
00083 break;
00084 case 2:
00085 printf("Reading AnalogInput...\n");
00086
00087 printf("Channel(0..7) = ");
00088 cin >> ch;
00089
00090 if ((error = lj->readAI((long) ch, &v)) != 0) {
00091 GetErrorString(error, stringError);
00092 printf("Error in readAI. %s\n", stringError);
00093 }
00094 else
00095 printf("Voltage in AI%d=%f\n", ch, v);
00096 break;
00097 case 3:
00098 printf("Writing AnalogOutput..\n");
00099
00100 printf("Channel(0..2) = ");
00101 cin >> ch;
00102 printf("Voltage(0.0..5.0) = ");
00103 cin >> v;
00104
00105 if ((error = lj->writeAO(ch, v)) != 0) {
00106 GetErrorString(error, stringError);
00107 printf("Error in writeAI. %s\n", stringError);
00108 }
00109 break;
00110 case 4:
00111 printf("Reading DigitalInput...\n");
00112
00113 printf("Channel(0..15) = ");
00114 cin >> ch;
00115
00116 if ((error = lj->readD((long) ch, &n)) != 0) {
00117 GetErrorString(error, stringError);
00118 printf("Error in readD. %s\n", stringError);
00119 }
00120 else
00121 printf("Level in D%d=%li\n", ch, n);
00122 break;
00123 case 5:
00124 printf("Writing DigitalInput..\n");
00125
00126 printf("Channel(0..15) = ");
00127 cin >> ch;
00128 printf("Level(0-1) = ");
00129 cin >> n;
00130
00131 if ((error = lj->writeD(ch, n)) != 0) {
00132 GetErrorString(error, stringError);
00133 printf("Error in writeD. %s\n", stringError);
00134 }
00135 break;
00136 case 6:
00137 printf("Reading digital InputOutput...\n");
00138
00139 printf("Channel(0..3) = ");
00140 cin >> ch;
00141
00142 if ((error = lj->readIO((long) ch, &n)) != 0) {
00143 GetErrorString(error, stringError);
00144 printf("Error in readIO. %s\n", stringError);
00145 }
00146 else
00147 printf("Level in IO%d=%li\n", ch, n);
00148 break;
00149 case 7:
00150 printf("Writing digital InputOutput..\n");
00151
00152 printf("Channel(0..3) = ");
00153 cin >> ch;
00154 printf("Level(0-1) = ");
00155 cin >> n;
00156
00157 if ((error = lj->writeIO(ch, n)) != 0) {
00158 GetErrorString(error, stringError);
00159 printf("Error in writeIO. %s\n", stringError);
00160 }
00161 break;
00162 case 8:
00163 printf("Reading D and IO...\n");
00164
00165 if ((error = lj->readDIOs(&n, &m)) != 0) {
00166 GetErrorString(error, stringError);
00167 printf("Error in readDIOs. %s\n", stringError);
00168 }
00169 else {
00170 printf("Levels D = %li | %li\n", n, n);
00171 printf("Levels IO = %li | %li\n", m, m);
00172 }
00173 break;
00174 case 9:
00175 printf("Writing a D y IO...\n");
00176
00177 printf("Level of signals D(binary: 0=level low, 1=level high) = ");
00178 cin >> n;
00179 printf("Level of signals IO(binary: 0=level low, 1=level high) = ");
00180 cin >> m;
00181
00182 if ((error = lj->writeDIOsCONFIG(&n, &m)) != 0) {
00183 GetErrorString(error, stringError);
00184 printf("Error in writeDIOsCONFIG. %s\n", stringError);
00185 }
00186 else {
00187 printf("Levels D = %li | %li\n", n, n);
00188 printf("Levels IO = %li | %li\n", m, m);
00189 }
00190 break;
00191 case 10:
00192 printf("Writing and configuring D and IO...\n");
00193
00194 printf("Direction of Lines D (binary: 0=input, 1=output) = ");
00195 cin >> cd;
00196 printf("Direction of Lines IO (binary: 0=input, 1=output) = ");
00197 cin >> cio;
00198 printf("Level of signals D(binary: 0=level low, 1=level high) = ");
00199 cin >> n;
00200 printf("Level of signals IO(binary: 0=level low, 1=level high) = ");
00201 cin >> m;
00202
00203 if ((error = lj->writeDIOs(&cd, &cio, &n, &m)) != 0) {
00204 GetErrorString(error, stringError);
00205 printf("Error in writeDIOs. %s\n", stringError);
00206 }
00207 else {
00208 printf("Direction D = %li | %li\n", cd, cd);
00209 printf("Levels D = %li | %li\n", n, n);
00210 printf("Levels IO = %li | %li\n", m, m);
00211 }
00212 break;
00213 case 11:
00214 printf("Enabling Watchdog...\n");
00215
00216 printf("Timeout(1..715) = ");
00217 cin >> m;
00218 printf("Line D(0,1,8) = ");
00219 cin >> ch;
00220 printf("Level D%d(0-1) = ", ch);
00221 cin >> n;
00222
00223 if ((error = lj->enableWatchdog(m, ch, n)) != 0) {
00224 GetErrorString(error, stringError);
00225 printf("Error in setWatchdog. %s\n", stringError);
00226 }
00227 break;
00228 case 12:
00229 printf("Disabling Watchdog...\n");
00230
00231 printf("Line D(0,1,8) = ");
00232 cin >> ch;
00233
00234 if ((error = lj->disableWatchdog(ch)) != 0) {
00235 GetErrorString(error, stringError);
00236 printf("Error in unsetWatchdog. %s\n", stringError);
00237 }
00238 break;
00239 case 13:
00240 printf("Reading Analog Inputs...\n");
00241
00242 printf("Number of Lines to read (1, 2, 4) = ");
00243 cin >> n;
00244 lineas = (long *) calloc(n, sizeof(long));
00245 voltajes = (float *) calloc(n, sizeof(float));
00246 for (i = 0; i < n; i++) {
00247 printf("Lines %d AI (0..7) = ", i + 1);
00248 cin >> lineas[i];
00249 }
00250
00251 if ((error = lj->readAIs(n, lineas, voltajes)) != 0) {
00252 GetErrorString(error, stringError);
00253 printf("Error in readAIs. %s\n", stringError);
00254 }
00255 else {
00256 for (i = 0; i < n; i++) {
00257 printf("Voltage in AI%li=%f\n", lineas[i], voltajes[i]);
00258 }
00259 }
00260 free(lineas);
00261 free(voltajes);
00262 break;
00263 case 14:
00264 printf("Writing Analog Outs...\n");
00265
00266 printf("Voltage AO0 = ");
00267 cin >> v0;
00268 printf("Voltage AO1 = ");
00269 cin >> v1;
00270
00271 if ((error = lj->writeAOs(v0, v1)) != 0) {
00272 GetErrorString(error, stringError);
00273 printf("Error in writeAOs. %s\n", stringError);
00274 }
00275 break;
00276 case 15:
00277 printf("Writing Pulses...\n");
00278
00279 printf("Level of pulse (<=0 -> low, >0 -> high) = ");
00280 cin >> n;
00281 printf("Type Line (0->Lines D, 1->Lines IO) = ");
00282 cin >> cd;
00283 if (cd == 0)
00284 printf("Lines D (0..15) = ");
00285 else
00286 printf("Lines IO (0..3)");
00287 cin >> m;
00288 printf("Pulse duration [us] (1..2000000) = ");
00289 cin >> cio;
00290
00291 if ((error = lj->writePulse(n, m, cio, cd)) != 0) {
00292 GetErrorString(error, stringError);
00293 printf("Error in writePulse. %s\n", stringError);
00294 }
00295 break;
00296 case 16:
00297 printf("Reading D directions...\n");
00298
00299 if ((error = lj->readDirectionDs(&m)) != 0) {
00300 GetErrorString(error, stringError);
00301 printf("Error in readDirectionDs. %s\n", stringError);
00302 }
00303 else
00304 printf("Direction Ds = %li | %li\n", m, m);
00305 break;
00306 case 17:
00307 printf("Writing D...\n");
00308
00309 printf("Channel(0..15) = ");
00310 cin >> m;
00311 printf("Level(0-1) = ");
00312 cin >> n;
00313
00314 if ((error = lj->writeDCONFIG(m, n)) != 0) {
00315 GetErrorString(error, stringError);
00316 printf("Error in writeDCONFIG. %s\n", stringError);
00317 }
00318 break;
00319 case 18:
00320
00321 printf("Writing D and IO\n");
00322
00323 long stateD = CONFIG_D;
00324 long stateIO = CONFIG_IO;
00325
00326 if ((error = lj->writeDIOsCONFIG(&stateD, &stateIO)) != 0) {
00327 GetErrorString(error, stringError);
00328 printf("Error in writeDIOsCONFIG. %s\n", stringError);
00329 }
00330 break;
00331 }
00332 }
00333
00334 delete lj;
00335
00336 return 0;
00337 }