Solved

usb c++

Posted on 2008-06-12
8
557 Views
Last Modified: 2013-12-14
hi
can anyone have some ideas about writing and reading on usb ports using visual c++ or C#
thanks
0
Comment
Question by:klay8
8 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What kind of USB devices are you thinking of? Storage devices can be accessed transparently liek regular hard drives through their drive letter, and other USB devices usually are available via a virtual COM port, see http://www.codeproject.com/KB/system/serial.aspx ("Serial library for C++") for more on the latter.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
It is not common to read usb ports directly, this will require to read the raw packets, not a trivial task.
Usually it is done by reading the underlying driver: serial port, mass storage, video codecs (for cameras), printer driver, human input drivers (for keyboard and mice).
Please specify
0
 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
In any USB solution there has to be a

- target
- host

Today most PCs support the EHCI on the host side...On the target side you need to identify what type of a device it is.
Is the target device a HID device(USB mouse, keyboard...) or a Mass stporage device(USB Hard Disk) ....

You will anyway need to have some firmware application running on the target USB device depending on the type of device and a correspondng host application running on the Windows host side. The host usually initiates connections...

Usually the class driver/application has to be written by you. Check and let me knwo..
0
 

Author Comment

by:klay8
Comment Utility
i have a usb to serial port device, and i would like to write a code to detect when remove or plug that one..
i can program in visual studio(any language),..
do this make  a diffrence
thanks
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
if you want to detect just insertion/extraction, you don't need specific usb programming, just use the Windows Management Instrumentation library (WMI).
Are you working with managed or unmanaged C++?
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
in C# is quiet easy:

using System.Management;

class SomeClass
{
        private static ManagementEventWatcher MySerialMonitor;

        public void SomeInitializerMethod()
       {
            MySerialMonitor= new ManagementEventWatcher(@"root\CIMV2", "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_USBControllerDevice'");
            MySerialMonitor.EventArrived += new EventArrivedEventHandler(MySerialMonitor_EventArrived);
            MySerialMonitor.Start();
             // etcetera
        }

        private static void MySerialMonitor_EventArrived(object sender, EventArrivedEventArgs e)
        {
            if (e.NewEvent.ClassPath.ClassName == "__InstanceDeletionEvent")
            {   // this event name can be different
                 // try to discriminate your specific hardware here, there can be other usb devices
                 // Check the 'e' object members carefully
            }
        }

0
 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
you can write a simple C program to do this. Use the datasheet of your USB to Serial converter to figure out the pins.

There will be vendor provided header files which will tell you which line to set to high or low.

I suggest you use the Keil C compiler to do the same.

Using Visual Studio is an overkill for embedded system programming.
0
 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
what happened?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now