Adept Scientific - English
The world's best software and hardware for research, science and engineering.
flag arrow
clearclear

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Academic Discounts
Support
My Adept
International |  About Us |  Adept Scientific Blog |  Contact Us |  Press Room |  Jobs
Adept Scientific on Facebook Adept Scientific on Twitter Adept Scientific on YouBube Adept Scientific on LinkedIn
Knowledge Base  > Browse Categories  > Universal Library
Step-By-Step: Starting a C#.NET Data Acquisition solution using the Universal Library

Email This Article

To email this article enter and address below and click on the "Email" Article button.



Last Modified: 3rd Jan 2013
Category: Data Acquisition Hardware and Software > Universal Library
Platform: Windows
Version: All
Article Ref.: BEB2
»Return to previous search
»Print friendly version of this article.
1 out of 1 people have found this article useful.

Step-By-Step: Starting a C#.NET Data Acquisition solution using the Universal Library

Open C#.NET, and start a new Windows Application

Add a reference to MccDaq

· Go to your Solution Explorer window
· Expand the References folder (if it is not already expanded)
· Right mouse click on References folder, and select “Add Reference…”
· The Add Reference dialog box appears
· Scroll down to MccDaq, click on it, click on the Select button at the right
· Then click on the ‘OK’ button at the bottom of the dialog box

Add the namespace to the project

· Go to your Solution Explorer window
· click on Form1.vb then press F7 to activate the code window
· Locate the line “using System.Data;
· Just after that add “using MccDaq;

Add Project variables

· Locate the line “public class Form1 : System.Windows.Forms.Form
· After the opening parenthesis add (paste in ) the following code:

//Here's where we declare our variables for the project

private MccDaq.MccBoard DaqBoard;
    private MccDaq.ErrorInfo ULStat;
    private MccDaq.Range Range;

Add the Initialization to Form1 procedure

· Locate public Form1()” procedure
· Locate “InitializeComponent();
· Just after that add the following

      //  Initiate error handling
      //   activating error handling will trap errors like
      //   bad channel numbers and non-configured conditions.
      //   Parameters:
      //     MccDaq.ErrorReporting.PrintAll :all warnings and errors
      //                encountered will be printed
//     MccDaq.ErrorHandling.StopAll   :if an error is encountered,
      //                the program will stop

     ULStat = MccDaq.MccService.ErrHandling(MccDaq.ErrorReporting.PrintAll, MccDaq.ErrorHandling.StopAll);

Add a new instance of a board object

· Go to your Solution Explorer window
· click on Form1.vb then press Shift + F7 to activate the Form Designer
· Double click on the form to activate the “Form1_Load event
· Just after that add  
int BoardNum;

   BoardNum = 1; //board number assigned by InstaCal
   DaqBoard = new MccDaq.MccBoard(BoardNum);


That’s it.  From here you can add code and procedures to things such as:

Analog input:DaqBoard.AIn
Analog InScan:DaqBoard.AInScan
Digital In:DaqBoard.DIn
Digital Out:DaqBoard.DOut
Digital Bit In :DaqBoard.DBitIn
Digital Bit Out:DaqBoard.DBitOut
Analog Out:DaqBoard.AOut
Analog Out Scan:DaqBoardAOutScan

Please see the Universal Library function reference guide or C:\MCC\Unilib.chm for more information.

For example, you could add a command button and 2 labels to the form, then paste in the follow to the code window:

private void button1_Click(object sender, System.EventArgs e)
{
float EngUnits;
System.UInt16 DataValue;
int Chan;

//  Collect the data by calling AIn memeber function of MccBoard object
//   Parameters:
//     Chan       :the input channel number
//     Range      :the Range for the board.
//     DataValue  :the name for the value collected
Range = Range.Bip10Volts; //  select Bip10Volts (member of Range enumeration)
Chan = 0; //  set input channel

ULStat = DaqBoard.AIn( Chan, Range, out DataValue);
if (ULStat.Value == MccDaq.ErrorInfo.ErrorCode.BadRange)
{
MessageBox.Show( "Change the Range argument to one supported by this board.", "Unsupported Range", MessageBoxButtons.OK);
Application.Exit();
}

//  Convert raw data to Volts by calling ToEngUnits (member function of MccBoard class)
ULStat = DaqBoard.ToEngUnits( Range, DataValue, out EngUnits);

label1.Text = DataValue.ToString();                //  print the counts
label2.Text = EngUnits.ToString("F4") + " Volts"; //  print the voltage
}

Note:  This will only work for MCC hardware that has an A/D converter with a Bipolar 10 volt range.
 
 
Related Articles
adept

Top of the Page

Popular Links: ChemDraw | ChemOffice | Data Acquisition | Data Analysis | EndNote | Maple | MapleSim | Mathcad | MathType | Quality Analyst | Reference Manager | VisSim

EU ePrivacy Directive | Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2013, Adept Scientific plc.
Site designed and maintained by Lyndon Ash

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055