Help With Modifying a Channel
Below is the program that I have downloaded, could anyone possibly show and tell me how to edit the first channel so that I can add an external mechanical-switch to the system instead of having to hit 'enter' on the keyboard?
To give some info as to what I am planning to do with the program... I'm testing the viscosity of liquids using LED's and Photosensors which are aligned on the side of a large bore capillary tube in order to catch the meniscus of the liquid as it passes. The passing of the meniscus should scatter the light from the LED and cause a change in the voltage across the gap which will be mapped by the program. As is right now, I have to hit enter to start the program when I flip the lever to start the flow of the liquid through the tube and would like to add a switch so I can set the sampling frequency, number of samples and number of channels the walk to the device and collect data. ------------------------------------------------------------------------ #include <stdlib.h> #include <string> #include <iostream> #include <iomanip> using namespace std; #include "dataqsdk.h" int main(int argc, char *argv[]) { int MY_CHANNELS = atoi(argv[3]); dataqsdk my_device; // device control/connection; main object long int error_code = 0; long int new_data = 0; char *sn = 0; // serial number int ChannelList[5] = {0,1,2,3,-1}; // used to set the channel list int MethodList[5] = {0,0,0,0,0}; // used to set the method list int points = 50; // how many scans to acquire points = atoi(argv[2]); // convert to integer and use it instead short int *iArray = new short int[points]; // will hold acquired data cout << "Supported devices:" << endl; char *temp = (char *)my_device.ProductName(); int i=0; while(temp[i] != 0 && temp[i+1] != 0) { cout << &temp[i] << endl; i += strlen(&temp[i]); i++; } if(temp != 0) { delete [] temp; temp = 0; } cout << "Setting product name: " << flush; my_device.ProductName("DI-194RS"); // set if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << my_device.ProductName(); // get cout << endl; cout << "Setting device file &" << endl; cout << "Connecting to device: " << flush; // the device file is the one the device is connected to // make sure the correct one is set my_device.DeviceFile("/dev/ttyS0"); // set if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << my_device.DeviceFile(); // get cout << endl; cout << "Setting event point: " << flush; my_device.EventPoint(1); if(my_device.ControlError(error_code)) { cerr << "Error: " << error_code << endl; return 1; } else cout << my_device.EventPoint(); cout << endl; cout << "Setting channel count: " << flush; // good idea to set this before channel list because it resets it my_device.ADChannelCount(MY_CHANNELS); // set if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << my_device.ADChannelCount(); // get cout << endl; cout << "Setting channel list: "; // make sure ChannelList is at least as big as ADChannelCount, // this function uses ADChannelCount to determine how much of ChannelList // to read and set up my_device.ADChannelList(ChannelList); // set, doesn't have get if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << "Success"; cout << endl; cout << "Setting method list: "; // make sure MethodList is at least as big as ADChannelCount, // this function uses ADChannelCount to determine how much of MethodList // to read and set up my_device.ADMethodList(MethodList); // set, doesn't have get if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << "Success"; cout << endl; cout << "Setting sample rate: " << flush; // it will automatically be set to max if the given value is bigger than // or equal to the maximum value my_device.SampleRate(atof(argv[1])); if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << my_device.SampleRate(); cout << endl; cout << "Getting serial number: " << flush; sn = (char *)my_device.InfoSerial(); // get if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << sn << endl; if(sn != 0) { delete [] sn; sn = 0; } cout << "Starting acquisition: " << flush; my_device.Start(); if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << "Acquiring..." << points << " scans" << endl; cout << " A.C. 1\t A.C. 2\t A.C. 3\t A.C. 4\t\t\tDigital" << endl; // gets one scan at a time and prints // it to the screen immediately int total = 0; while(total <= points) { if(my_device.NewData(new_data)) { for(int i=0; i<(new_data>points-total?points-total:new_data); i++) { my_device.GetDataEx(iArray, MY_CHANNELS); if(my_device.ControlError(error_code)) { cerr << "Error: " << error_code << endl; return 1; } else { // print out all the channels of the scan for(int j=0; j<MY_CHANNELS; j++) { if(MY_CHANNELS == 5 && j == 4) { cout << "\t\t"; for(int xyz=0; xyz<3; xyz++) cout << ((iArray[j] >> xyz) & 1); } else { cout.width(7); cout.precision(2); cout.setf(ios::fixed | ios::showpoint); cout << (double)iArray[j]*10/32767 << ' '; } } cout << endl; } } total += new_data; } if(my_device.ControlError(error_code)) { cerr << "Error: " << error_code << endl; return 1; } } if(iArray != 0) { delete [] iArray; iArray = 0; } cout << "Stopping acquisition... " << flush; my_device.Stop(); if(my_device.ControlError(error_code)) // error check { cerr << "Error: " << error_code << endl; return 1; } else cout << "Success" << endl; return 0; } |
Wow, that's a lot of code to try to decipher, especially when it isn't enclosed in [ c o d e ] tags.
Presumably, the Start() method forces you to press the enter key to commence the data acquisition run. The only way of knowing how to get around this would require access to the source code for the library you are using. Since the provider http://www.dataq.com/products/software/linux/ seems to provide the source code, it would seem to be a good idea to look there. Once you've isolated the code that implements the Start() method (assuming that is where your problem exists), you could post the relevant parts here (use [c o d e] tags, please), and we can help you. If you want to use a contact closure to replace the keystroke event that starts the acquisition process, you should probably consult the product users manual for your data logger. The web page says "Two Digital Inputs For Remote Start/Stop and Remote Event Marker Control", so I guess the manual explains how to actually use it, and my guess is that it's functionality is built into the Start() method. --- rod. |
I have no idea what a "[ c o d e ] tag" is, sorry. I've never programmed before in my life. i gave up on trying to figure it out... thanks anyway though, i'll try to figure out what you were talking about and see if i can't do something.
|
If you click on the 'Go Advanced' button in the forum article editor, you will see a '#' icon. When you select a section of text and click this icon, it encloses the selected text in [c o d e] tags, which causes it to retain the formatting of the source code, and not translate anything into smileys and other stuff. If you browse around on the forum, you will notice other people's source code is displayed in boxes with fixed-pitch font and actually looks like source code, ie. readable.
This helps others to help you. It works just as well to type the opening [c o d e] & closing [/c o d e] tags yourself, btw. Just like I have done here, but take out the space characters. Another tip: when asking about specific hardware &/or software packages, it is helpful to mention what they are and enough context for others to understand your question. You've mentioned channels and other stuff which few people will be able to make sense of without a little help. --- rod. |
All times are GMT -5. The time now is 10:20 AM. |