ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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 << "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 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;
}
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.