提问人:St3althPatchin 提问时间:1/7/2023 更新时间:1/9/2023 访问量:274
通过 C 控制 AIM-TTI 电源#
Controlling AIM-TTI Power supply via C#
问:
我正在使用 Aim-TTi CPX400DP 电源,并负责使用 C# 严格通过 Visual Studio 远程使用它。我在这里看到很多人使用LabView和其他软件,但对Visual Studio却一无所知。此外,在查找此电源的手册时,我也没有看到任何可用于在 C# 中调用此电源的语法。有没有人可以为此问题提供知识或支持?
我试过下载 NiMax 并使用它来验证电源是否通过 USB 连接。它表示电源为 COM4。但是,当我在 NiMax 中打开面板时,没有其他连接或操作可言。我无法连接它并发送或接收数据
答:
0赞
Philip Hoole
1/9/2023
#1
首先,我应该让你知道我为 Aim-TTi 工作,这样我就可以帮助你在 Visual Studio 中使用 C# CPX400DP。
CPX400DP上的 USB 端口作为 CDC 类虚拟 COM 端口实现,任何应用软件都可以将其视为标准 COM 端口。
下面是我用 C# 创建的一个小控制台应用程序。
请确保添加“使用 System.IO.Ports;”,这可能需要从 Visual Studio 中的 NuGet 包管理器安装同名包(由 Microsoft 发布)。
我建议单步执行此代码,然后您可以在rx_message字符串中看到响应。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
namespace CPX_Console
{
class Program
{
static SerialPort _serialPort;
static void Main(string[] args)
{
string tx_message;
string rx_message;
_serialPort = new SerialPort();
// configure the serial port to use the sesired COM port
// Note, you dont have to configure the baud rate or any of the other default serialPort settings
_serialPort.PortName = "COM7";
// open the COM port
_serialPort.Open();
// query the CPX identification string
tx_message = "*IDN?";
_serialPort.WriteLine(tx_message);
// get the response
rx_message = _serialPort.ReadLine();
// set channel 1 output to 1.23V
tx_message = "V1 1.23";
_serialPort.WriteLine(tx_message);
// enable channel 1
tx_message = "OP1 1";
_serialPort.WriteLine(tx_message);
// query the measured output voltage on channel 1
tx_message = "V1O?";
_serialPort.WriteLine(tx_message);
// get the response
rx_message = _serialPort.ReadLine();
// close the COM port
_serialPort.Close();
}
}
}
评论
0赞
Adriaan
1/9/2023
欢迎来到 Stack Overflow!感谢您的回答。但是,请不要提及场外帮助。Stack Overflow 应该是一个知识数据库,即所有答案都应该独立存在。OP在需要解释时可以发表评论。您可以参加导览,了解 Stack Overflow 是关于什么的。
0赞
St3althPatchin
2/15/2023
感谢您的帮助,它看起来像在手册中。通过使用 V1 表示电压 1 和相同的安培数,我能够通过 C# 发送命令,既控制输出又发送开/关命令。唯一给我带来麻烦的是串行端口,我是通过 USB 连接的,所以它给了我一些问题,包括我必须声明 Mbsession 才能写入它。撇开这些不谈,我很成功,我很感激你的帮助!
评论