Click here to Skip to main content
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 Dave432.5K
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 CPallini 405
1 Sergey Alexandrovich Kryukov 272
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,890
2 CPallini 5,175
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2014
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