如何将VB.Net应用程序与USB端口连接 [英] How to interface VB.Net Application with USB Port

查看:490
本文介绍了如何将VB.Net应用程序与USB端口连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想在VB.Net中开发一个应用程序,该应用程序使用USB端口捕获数据(温度和压力)并在屏幕上显示值.
再次使用USB端口,这些值可用于生成图形或控制其他设备.

但是,我在.Net中找不到用于与USB端口接口的任何方法.

我该如何进行?

Preetinder Singh
[DELETED] @ yahoo.com

[edit]除非您真的喜欢垃圾邮件,否则请不要在任何论坛中发布您的电子邮件地址!如果有人回复您,您将收到一封电子邮件,通知您-OriginalGriff [/edit]

Hello,

I want to develop an application in VB.Net that captures data (temperature and pressure) using USB port and displays the values on Screen.
The values may then be used to generate Graphs or for controlling other devices, again using USB Port.

However, I have not found any method in .Net for interfacing with USB Port.

How do I proceed?

Preetinder Singh
[DELETED]@yahoo.com

[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]

推荐答案

您将USB端口视为标准串行端口港口.创建 SerialPort类的实例 [
You treate the USB port as it is was a standard serial port. Create an instance of the SerialPort class[^], and handle the incoming data:
    SerialPort sensor = new SerialPort("COM6");
    sensor.BaudRate = 9600;
    sensor.Parity = Parity.None;
    sensor.StopBits = StopBits.One;
    sensor.DataBits = 8;
    sensor.Handshake = Handshake.None;
    sensor.DataReceived += new SerialDataReceivedEventHandler(Sensor_DataReceived);
    sensor.Open();
    Console.WriteLine("Press any key to continue...");
    Console.WriteLine();
    Console.ReadKey();
    sensor.Close();
    ....


private static void Sensor_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
    SerialPort sensor = (SerialPort)sender;
    string data = sensor.ReadExisting();
    Console.Write(data);
    }


那是因为您试图像对待串行端口或并行端口一样将USB端口视为端口.看看USB代表什么:通用串行总线. USB不是端口,而是BUS,与计算机内部的扩展槽不同.

您与连接到端口的设备进行交互,而不是与端口本身进行交互.您如何执行此操作取决于设备公开的接口.该设备很可能将自己作为串行端口仿真公开,您可以像使用SerialPort类的任何其他串行端口设备一样使用它.

但是,如果您的设备不这样做,则必须从设备制造商那里获取SDK,以使您的代码与之交互. Phidg​​ets设备(http://www.phidgets.com)就是这种情况.
That''s because you''re trying to treat the USB port as a port like you would a serial or parallel port. Look at what USB stands for: Universal Serial BUS. A USB is not a port, but a BUS, not unlike the expansion slots inside your computer.

You interface with the device attached to the port, not the port itself. How you do this depends on what interface the device exposes. It''s entirely possible that the device exposes itself as serial port emulation and you can get at it just like any other serial port device using the SerialPort class.

However, if your device doesn''t do that, you''ll have to get an SDK from the manufacturer of the device to let your code interface with it. This is the case with Phidgets devices (http://www.phidgets.com).


这篇关于如何将VB.Net应用程序与USB端口连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆