简体   繁体   English

创建多设备可控软件

[英]Creating multi-device controllable software

I do not know how to title my question but the first thing that came into my mind is this "multi-device software" thing. 我不知道如何为我的问题加上标题,但是我想到的第一件事就是这种“多设备软件”。

I'm an electronics engineering student and interested in instrument control. 我是一名电子工程专业的学生,​​对仪器控制感兴趣。 Using C# for this purpose and have a basic knowledge of C# form applications. 为此使用C#并具有C#表单应用程序的基本知识。 Besides, there is a standart command set developed by IVI Foundation named "SCPI Commands". 此外,还有一个由IVI Foundation开发的标准命令集,名为“ SCPI Commands”。 It's an easy approach for instrument control and you can't write some SCPI code for fully functional instrument control system. 这是一种简单的仪器控制方法,您无法为功能齐全的仪器控制系统编写一些SCPI代码。 In here "drivers" take role. 在这里,“驾驶员”扮演角色。 Most of the manufacturers provide device drivers when you buy their product. 购买产品时,大多数制造商会提供设备驱动程序。 With this driver file you can create fully functional and responsive softwares. 使用此驱动程序文件,您可以创建功能全面且响应迅速的软件。 Also you can develop your own driver for your own needs. 您也可以根据自己的需要开发自己的驱动程序。 But although SCPI is standart for all kind of instruments, some multi commands are starts to create problem for you. 但是,尽管SCPI对于所有类型的仪器都是标准的,但是一些多命令却开始给您带来麻烦。 For example you write a code for A brand, but that code does not work for the B brand's same device that does exactly the same thing with A brand's. 例如,您为A品牌编写了代码,但是该代码不适用于B品牌与A品牌完全相同的设备。

The main goal is creating a cable loss calculation software for several coaxial cables. 主要目标是为多条同轴电缆创建电缆损耗计算软件。 You must use a spectrum analyzer and an RF signal generator to perform this task. 您必须使用频谱分析仪和RF信号发生器来执行此任务。 We have a couple of spectrum analyzers and lots of signal generators in use. 我们有几个频谱分析仪和许多信号发生器在使用中。

With one program we have to control all of our devices. 使用一个程序,我们必须控制所有设备。 This is my problem. 这是我的问题。

I want to create a responsive software that works for all of our spectrum analyzers and signal generators. 我想创建一个适用于我们所有频谱分析仪和信号发生器的响应式软件。 How can I do that ? 我怎样才能做到这一点 ? First, I think I can create a driver for each device and the main program choose the correct driver by asking user with a prompt or something like that. 首先,我想我可以为每个设备创建一个驱动程序,并且主程序通过向用户询问提示或类似内容来选择正确的驱动程序。 But I don't know how to achieve this. 但我不知道如何实现这一目标。 Second, I can write the software's main part for each combination of devices and include that part with a .txt file to main software in runtime. 其次,我可以为每种设备组合编写软件的主要部分,并在运行时将该部分与.txt文件一起包含到主要软件中。 I know this is a noob approach but I think I can do this without hassle. 我知道这是一个菜鸟方法,但我想我可以毫不费力地做到这一点。 And I don't know anything about the first approach. 我对第一种方法一无所知。 Third, I can write all of the devices' commands for each one in the program and use if conditionals to choose between cases. 第三,我可以在程序中为每个设备编写所有设备的命令,并使用if条件来在情况之间进行选择。 Or switch-case structure. 或开关盒结构。 This is the only way If I can't do this with other options. 如果我无法通过其他选项执行此操作,则这是唯一的方法。

You may not understand me until here because I can't describe the problem exactly that's because I'm an amateur software developer. 您可能直到这里都不了解我,因为我无法确切描述问题是因为我是一名业余软件开发人员。

Assume that you have a signal generator. 假设您有一个信号发生器。 You want to select frequency 10 MHZ. 您要选择频率10 MHZ。 This is an Agilent 33120A. 这是Agilent 33120A。 To achieve this with computer you need to send this command to device. 要使用计算机实现此目的,您需要将此命令发送到设备。

SOUR:FREQ 10 MHZ

After this, device sets the frequency to 10 MHZ. 此后,设备将频率设置为10 MHZ。 Let's assume you have another manufacturer's signal generator and to achieve exactly the same thing with this device you may have to send this; 假设您有另一个制造商的信号发生器,并且要使用此设备实现完全相同的操作,则可能必须发送此信号。

SENS:FREQ 10 MHZ

This two performs the same thing but SOUR and SENS part depends on the device. 这两个执行相同的操作,但SOUR和SENS部分取决于设备。

To create a program with C# we use an API to communicate with devices. 要使用C#创建程序,我们使用API​​与设备进行通信。 If you use GPIB protocol the API's name is NI488.2. 如果使用GPIB协议,则API的名称为NI488.2。 If you use RS232 you may use VISA API etc. Our protocol is GPIB by the way. 如果您使用RS232,则可以使用VISA API等。顺便说一下,我们的协议是GPIB。 With GPIB we use wrappers to easily integrate SCPI commands with C# environment. 使用GPIB,我们可以使用包装器轻松地将SCPI命令与C#环境集成在一起。 For example after you add GPIB libraries to references you can use this to send command over C# forms interface; 例如,在将GPIB库添加到引用之后,您可以使用它通过C#表单界面发送命令;

ibwrt("SOUR:FREQ 10 MHZ", "SOUR:FREQ 10 MHZ".Length);

Now I came to my biggest problem. 现在我遇到了最大的问题。 How can I make this part of code to create a successful responsive program ? 如何使这部分代码创建成功的响应程序? For example operator using Agilent Signal Generator and Rohde&Schwarz spectrum analyzer. 例如,使用安捷伦信号发生器和罗德与施瓦茨频谱分析仪的操作员。 Another operator is using IFR Signal Generator and HP Spectrum Analyzer. 另一位操作员正在使用IFR Signal Generator和HP Spectrum Analyzer。 But they use the same software. 但是他们使用相同的软件。 IFR signal generator may use "SENS:FREQ" for the operation. IFR信号发生器可以使用“ SENS:FREQ”进行操作。

Before the operation start a prompt can pop-up and ask for the devices' drivers. 在开始操作之前,会弹出提示并询问设备的驱动程序。 I don't know. 我不知道。 These came to my mind first. 这些首先浮现在我的脑海。 But If you were me, how you achieve this ? 但是,如果您是我,您将如何实现这一目标? And if you choose an option please tell me how to do that. 如果您选择一个选项,请告诉我该怎么做。 I'm stuck with this. 我坚持这一点。 And right now program has about 2000 lines of code. 现在程序有大约2000行代码。 "ibwrt" is not the only part of the program, neither "SENS:FREQ"... There is also "SENS:BAND:RES", "INIT:CONT" etc. for other tasks. “ ibwrt”不是程序的唯一部分,也不是“ SENS:FREQ” ...也有“ SENS:BAND:RES”,“ INIT:CONT”等用于其他任务。 This is not important. 这并不重要。

I hope you understand my question because I know I could not tell correctly. 希望您能理解我的问题,因为我知道我无法正确判断。

If you have any question about the problem feel free to comment. 如果您对此问题有任何疑问,请随时发表评论。

Thanks. 谢谢。

TL;DR TL; DR

I need to send commands for each devices through C# Forms interface. 我需要通过C#Forms接口为每个设备发送命令。 I mean devices have their special commands and I need to create one software that can control every device with user selection instead of creating a software for each device. 我的意思是设备具有其特殊的命令,我需要创建一个可以通过用户选择来控制每个设备的软件,而不是为每个设备创建一个软件。

Implement interface IDevice with all that you need (like SelectFrequency(...) ), and implement classes Abrand : IDevice , Bbrand ... And so on. 使用所需的所有功能(例如SelectFrequency(...) )实现接口IDevice ,并实现类Abrand : IDeviceBbrand ...等等。 This is the only way. 这是唯一的方法。 Then you can use the factory to get the current device, like var myDevice = DeviceFactory.GetCurrent(); 然后,您可以使用工厂获取当前设备,例如var myDevice = DeviceFactory.GetCurrent(); - of course, you have to implement it yourself -当然,您必须自己实施

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM