Click here to Skip to main content
11,705,763 members (53,404 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET USB
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 19-May-11 19:49pm
Edited 19-May-11 20:55pm
Dalek Dave433.2K
v3
Comments
Dalek Dave at 20-May-11 2:55am
   
Edited for Grammar and Readability.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
    }
  Permalink  
Comments
Dalek Dave at 20-May-11 2:55am
   
Good Answer.
Samuel_Tandibua at 20-May-11 15:54pm
   
Nice...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 170
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100