=
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NationalInstruments.VisaNS;
namespace USBPowerTester
{
class DPit6700 : IDigitalPower
{
#region IDigitalPower 成员
public bool OpenDevice()
{
bool flag = true;
try
{
mbSession
(MessageBasedSession)ResourceManager.GetLocalManager().Open(resourceName);
}
catch
{
flag = false;
}
return flag;
}
public void SetVoltage(double voltage)
{
string str = "VOLT " + voltage.ToString("0.0000");
mbSession.Write(str);
}
public void SetCurrent(double current)
{
string str = "CURR " + current.ToString("0.0000");
mbSession.Write(str);
}
public double GetSetVoltage()
{
double vol = 0;
vol = GetDoubleCmd("VOLT?");
return vol;
}
public double GetSetCurrent()
{
double cur = 0;
cur = GetDoubleCmd("CURR?");
return cur;
}
public double GetOutVoltage()
{
double vol = 0;
vol = GetDoubleCmd("MEAS:VOLT?");
return vol;
}
public double GetOutCurrent()
{
double cur = 0;
cur = GetDoubleCmd("MEAS:CURR?");
return cur;
}
public void SetOutput(bool open)
{
if (open)
mbSession.Write("OUTP 1");
else
}
mbSession.Write("OUTP 0");
public bool GetOutputStatus()
{
bool ret = false;
string str = mbSession.Query("OUTP?");
if (str == "1\n")
ret = true;
else
ret = false;
return ret;
}
public void CloseDevice()
{
try
{
mbSession.Dispose();
}
catch { }
}
#endregion
private MessageBasedSession mbSession;
private
string
const
"USB0::0xFFFF::0x6500::60026501068742XXXX::INSTR";
resourceName
=
private double GetDoubleCmd(string cmd)
{
double ret = 0;
try
{
string str = mbSession.Query(cmd);
ret = Convert.ToDouble(str);
}
catch { }
return ret;
}
}
}
接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace USBPowerTester
{
interface IDigitalPower
{
bool OpenDevice();
void SetVoltage(double voltage);
void SetCurrent(double current);
double GetSetVoltage();
double GetSetCurrent();
double GetOutVoltage();
double GetOutCurrent();
void SetOutput(bool open);
bool GetOutputStatus();
void CloseDevice();
}
}