11-13-2006 10:46 AM
How do I start a application using a NI GPIB interface and C#, I have red through the Simple Read Write application which is included with the drivers however when I open a Windows application it does not include the space to add the device initiator (shown below the NI Simple Read Write)
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
using
NationalInstruments.NI4882;
{
/// <summary>
/// Summary description for
Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button
openButton;
private System.Windows.Forms.Button
closeButton;
private System.Windows.Forms.TextBox
stringToWrite;
private System.Windows.Forms.Button
writeButton;
private System.Windows.Forms.Label
stringToWriteLabel;
private System.Windows.Forms.Button
readButton;
private System.Windows.Forms.Label
stringReadLabel;
private Device
device;
private System.Windows.Forms.NumericUpDown
boardId;
private System.Windows.Forms.Label
boardIdLabel;
private System.Windows.Forms.NumericUpDown
primaryAddress;
private System.Windows.Forms.NumericUpDown
secondaryAddress;
private System.Windows.Forms.Label
primaryAddressLabel;
private System.Windows.Forms.Label
secondaryAddressLabel;
private
System.Windows.Forms.TextBox stringRead;
I just get.
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
NationalInstruments.NI4882;
namespace
WindowsappExtn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Could
sombody please help me to understand how to start my own program. Many thanks
11-14-2006 04:57 AM
Hi,
I beleive that line was added by hand.
I'ts just a declaration of a private variable within the public form's class.
You can do similar just to one "area" instead by : (I've used c# express 2005 but you should get the idea)
using
System;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Device device1;
}
}
}
Hope that helps
Thanks
Sacha Emery
National Instruments (UK)
11-20-2006 04:01 AM
11-22-2006 08:34 AM
11-22-2006 08:35 AM
11-23-2006 03:22 AM
Hi,
my code example was just a place marker. You have to instantiate the device, not just declare it and then try writing to it.
For example to instantiate the "device1":
device1 =
new Device((int)boardId.Value,(byte)primaryAddress.Value,(byte)currentSecondaryAddress);(This line is taken straight from the example c# gpib simple read and write code, so the boardId, primaryAddress and SecondaryAddress are
just control on the main form, but you can obviously replace them with the appropriate numbers as constants if you prefer)
Then you can start to use it with the writes and reads.
device1.Write(ReplaceCommonEscapeSequences(stringToWrite.Text));
and
stringRead.Text = InsertCommonEscapeSequences(device1.ReadString());
(the common escapesequences are just there to make sure we're handling for carriage returns etc)
private string ReplaceCommonEscapeSequences(string s)To dispose of it :
device1.Dispose();
Hope that helps
Sacha Emery
National Instruments (UK)