Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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]
Posted
Updated 9-May-22 2:05am
v3
Comments
Dalek Dave 20-May-11 2:55am    
Edited for Grammar and Readability.

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);
    }
 
Share this answer
 
Comments
Dalek Dave 20-May-11 2:55am    
Good Answer.
Samuel_Tandibua 20-May-11 15:54pm    
Nice...
Member 3232428 5-Oct-15 1:50am    
my printer uses USB001 NOT COM, and when I try to use that port it says: The given port name does not start with COM/com or does not resolve to a valid serial port. what should I do?
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).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900