简体   繁体   English

LabVIEW中的套接字

[英]Sockets in LabVIEW

I am communicating across USB, using a proprietary protocol, with some custom hardware I've built. 我正在使用专有协议通过USB与我构建的一些自定义硬件进行通信。 I have a GUI that handles all the communications/interaction with that hardware and a (C#) DLL which exposes all the relevant USB functionality. 我有一个GUI处理与该硬件的所有通信/交互,还有一个(C#)DLL,它公开了所有相关的USB功能。 I need to write a LabVIEW driver (VI) for communicating with the hardware. 我需要编写一个用于与硬件通信的LabVIEW驱动程序(VI)。 My thought is that I just use LabVIEW to open up my GUI and have a socket with which I expose all the relevant control to LabVIEW with. 我的想法是,我只是使用LabVIEW打开我的GUI,并拥有一个套接字,通过它可以将所有相关控件公开给LabVIEW。 Is it possible to open a socket in LabVIEW and communicate with my GUI? 是否可以在LabVIEW中打开套接字并与我的GUI通信? Is this a bad approach or should I just try and make LabVIEW invoke the DLL and handle the hardware control instead of my GUI (polled communications, solicited/unsolicited commands, etc)? 这是不好的方法吗?还是应该让LabVIEW调用DLL并处理硬件控制而不是GUI(轮询通信,请求/未经请求的命令等)?

IS there a reason you want to use your GUI only? 您是否只想使用GUI是有原因的? In terms of time, I would say build a good front panel in LabVIEW and just communicate to the hardware directly using the DLL. 就时间而言,我想说的是在LabVIEW中构建一个良好的前面板,并且仅使用DLL直接与硬件进行通信。 Adding the GUI is just an added layer of complexity which might be difficult to maintain later on? 添加GUI只是增加了一层复杂性,以后可能很难维护? Why not do everything in LabVIEW if you can? 如果可以,为什么不在LabVIEW中执行所有操作?

Yes, LabVIEW supports sockets using both TCP/IP and UDP. 是的,LabVIEW支持同时使用TCP / IP和UDP的套接字。

You should be able to create a program/service that continually runs acting as TCP/IP server. 您应该能够创建作为TCP / IP服务器连续运行的程序/服务。 You can send commands and receive responses as strings. 您可以发送命令并以字符串形式接收响应。 If you need to pack data, you can use the flatten to string command. 如果需要打包数据,则可以使用flatten to string命令。

Essentially, your application should be structured as a loop running the TCP/IP server, and another loop that actually communicates with the instrument. 本质上,您的应用程序应被构造为一个运行TCP / IP服务器的循环,以及另一个实际上与仪器通信的循环。 This might change if you need to get data back from the devices to your TCP client. 如果您需要将数据从设备传回TCP客户端,则可能会改变。 A producer consumer model, if you will :) 生产者消费者模型,如果您愿意:)

To get you started off, open up the NI Example Finder (Help -> Find Examples) and browse to Networking->TCP and UDP-> Simple Data Server.vi 要开始使用,请打开“ NI示例查找器”(帮助->查找示例),然后浏览至“网络”->“ TCP和UDP”->“简单数据服务器”。vi

It depends who is going to be using the LabVIEW driver and for what. 这取决于谁将使用LabVIEW驱动程序以及使用什么驱动程序。 If you're handing over this hardware to someone else who is going to want to create their own application(s) for it, they would probably prefer to talk directly to the DLL rather than go through your GUI. 如果您要将此硬件移交给要为其创建自己的应用程序的其他人,则他们可能更愿意直接与DLL对话而不是通过您的GUI。 If it's more about automating your existing software from LabVIEW to do testing or repetitive tasks on the hardware, for example, then driving your GUI from LabVIEW might be less work. 例如,如果要从LabVIEW中自动执行现有软件来执行硬件上的测试或重复任务,那么从LabVIEW驱动GUI的工作可能会更少。

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

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