Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NETUSB
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 Dave426.3K
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
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 446
1 Sergey Alexandrovich Kryukov 360
2 Shai Vashdi 318
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 9,109
1 OriginalGriff 5,290
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid