LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2007, 02:23 PM   #1
ChemMarc
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
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;
}
 
Old 10-05-2007, 10:04 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 10-06-2007, 03:17 PM   #3
ChemMarc
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 10-06-2007, 04:55 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] modifying ArchLinux anon08 Programming 3 05-15-2007 09:12 AM
difference between Channel Associated Signalling and Common Channel Signalling sailu_mvn Linux - Software 3 03-31-2006 06:25 AM
Help modifying FSTAB LinuxCrusader Linux - General 3 12-27-2004 01:26 AM
AirSnort works on only one channel - channel 11 kchhabria Linux - Wireless Networking 0 12-21-2004 03:53 PM
Hard drive in primary channel showing in secondary channel Ale Linux - Hardware 2 02-20-2004 11:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration