• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# winform使用NI-VISA驱动来控制IT6522数控电源

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文参考NI的《C#与Visual Basic .Net仪器控制指南》

IT6522是ITECH公司的一款数控电源,提供USB,RS232,485,GPIB,以太网等接口,

在之前的文章《winform串口通过SCPI协议与数控电源M8811通信》使用的是串口,

本文介绍如何使用USB来控制数控电源。

USB协议很复杂,厂家也没有提供相应的dll,甚至连驱动都没有,幸好有NI-VISA

首先,http://www.ni.com/download/ni-visa-16.0/6184/en/建议您下载完整版的NI-VISA

安装完成之后,打开NI MAX,插上usb,打开数控电源,然后在面板上设置usb通信


这样复制VISA资源名称,备用。

打开VS2008或者VS2010,(VS2013似乎不行)

添加引用

然后上代码

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 const string resourceName = "USB0::0xFFFF::0x6500::60026501068742XXXX::INSTR";
 
        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();
    }
}


这上面的SCPI指令需要参考厂家提供的编程指南(随机光盘中有)
 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
WinForm实现简单的拖拽功能(C#)发布时间:2022-07-10
下一篇:
C#连接基于Java开发IM——Openfire发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap