请问各位大虾有使用过C#来开发操作GPIB仪器的项目么
我正在做一个生产自动测试的项目,使用C#来做,但很奇怪,连不上仪器。之前我使用过VB来编程,VB能连上仪器,操作也很方便。但改了C#以后就出问题了。大家有没有相关的程序参考。 --------------------编程问答-------------------- 我做过。控制TA 的仪器DSC TGA --------------------编程问答-------------------- using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; // Used for _getch() to monitor user inputs
using NationalInstruments.NI4882; // This namespace must be included to reference the .NET language inte易做图ce
namespace GPIBcontrl
{
public partial class Form1 : Form
{
private static LangInt li; // declare an instance of the .NET language inte易做图ce functions
private static GpibConstants c; // declare an instance of the .NET language inte易做图ce constants
private const int ARRAYSIZE = 1024; // size of ReadBuffer
private static int Dev; // a reference to an instrument on the bus
private static string ValueStr; // holds the string returned from instrument
private static int ValueInt; //holds the number returned from instrument
private const int BDINDEX = 0; // board Index
private const int PRIMARY_ADDR_OF_PPS =5; // pimary address of device
private const int NO_SECONDARY_ADDR = 0; // secondary address of device
private static int TIMEOUT; // tmeout value
private const int EOTMODE = 1; // enable the END message
private const int EOSMODE = 0; // disable the EOS mode
private static string[] ErrorMnemonic = {"EDVR", "ECIC", "ENOL", "EADR", "EARG", // Error codes
"ESAC", "EABO", "ENEB", "EDMA", "",
"EOIP", "ECAP", "EFSO", "", "EBUS",
"ESTB", "ESRQ", "", "", "", "ETAB"};
[DllImport("msvcrt.dll")]
public static extern char _getch(); //Silently inputs a user keystroke
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
/*
* Allocate memory space for the classes and arrays
*/
li = new LangInt(); // Contains all GPIB functions
c = new GpibConstants(); // Contains all GPIB global constants
TIMEOUT = c.T10s; // Set timeout to 10 seconds
/*
* The application brings the power supply online using ibdev. A
* device handle, Dev, is returned and is used in all subsequent
* calls to the device.
*/
Dev = li.ibdev(BDINDEX, PRIMARY_ADDR_OF_PPS, NO_SECONDARY_ADDR, TIMEOUT, EOTMODE, EOSMODE);
if ((li.ibsta & c.ERR) != 0) // throw an error
MessageBox.Show("Unable to open device");
/*
* Clear the internal or device functions of the device. If the
* error bit ERR is set in ibsta, call GPIBCleanup with an error
* message.
*/
li.ibclr(Dev);
if ((li.ibsta & c.ERR) != 0) // throw an error
MessageBox.Show("unable to clear device");
/*
* The application issues the '*IDN?' command to the power supply.
*/
/* li.ibwrt(Dev, "VOLT 5",6);
li.ibwrt(Dev, "CURR 5", 6);
li.ibwrt(Dev, "SENS:FUNC 'CURR' ", 20);*/
li.ibwrt(Dev, "*IDN?\n", 6);
li.ibwrt(Dev, "READ?", 5);
if ((li.ibsta & c.ERR) != 0) // throw an error
MessageBox.Show("unable to write device");
}
private void button1_Click(object sender, EventArgs e)
{
li.ibrd(Dev, out ValueStr, ARRAYSIZE);
if ((li.ibsta & c.ERR) != 0) // throw an error
MessageBox.Show("Can not read the data");
textBox1.Text= ValueStr;
}
}
} --------------------编程问答-------------------- private const int PRIMARY_ADDR_OF_PPS =5; // pimary address of device
仪器上的主地址设置对了没有啊?
补充:.NET技术 , C#