How to operate USB port
-
HI, guys I am interested in operating USB port in C# . But I don't konw how to do that. Anybody have some idea about it. Thank you vigorous
-
HI, guys I am interested in operating USB port in C# . But I don't konw how to do that. Anybody have some idea about it. Thank you vigorous
The .Net framework doesn't allow you to manipulate hardware. You would have to use C++ to accomplish what you want. Aaron Eldreth TheCollective4.com My Articles While much is too strange to be believed, Nothing is too strange to have happened. - T. Hardy
-
HI, guys I am interested in operating USB port in C# . But I don't konw how to do that. Anybody have some idea about it. Thank you vigorous
You'd have to be ALOT more specific about what you want to do. On top of that, how to do it will be vendor and device dependent because you'll be interacting with the driver for that device. Also, since all the NT kernel versions of Windows (NT, 2000, XP, 2003) abstract the hardware, you can't get to the hardware directly. You have to go through either the device driver for the device you want, or write your own device driver that exposes an interface to your managed code (C#). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
The .Net framework doesn't allow you to manipulate hardware. You would have to use C++ to accomplish what you want. Aaron Eldreth TheCollective4.com My Articles While much is too strange to be believed, Nothing is too strange to have happened. - T. Hardy
-
HI, guys I am interested in operating USB port in C# . But I don't konw how to do that. Anybody have some idea about it. Thank you vigorous
-
In the future, I will need get data from a usb port connected with a bar scanner. The bar scanner will scan a bar graph and send them to the PC by usb. At the moment, I still not know more details about the scanner. So I just want to know some idea about operating usb port. For example, I know we can use MSCom control or API to control serial port. But how can I use usb port? If you can provide some code, I will feel very very grateful for your help. Thank you very much. vigorous
-
In the future, I will need get data from a usb port connected with a bar scanner. The bar scanner will scan a bar graph and send them to the PC by usb. At the moment, I still not know more details about the scanner. So I just want to know some idea about operating usb port. For example, I know we can use MSCom control or API to control serial port. But how can I use usb port? If you can provide some code, I will feel very very grateful for your help. Thank you very much. vigorous
Alright, I think I have the idea... I know microsft already provides generic drivers for scanners, so you can use that instead of the one that comes with the scanner (which is probably proprietry and not documented). SO, you wont' have to write your own driver, thats good. Um, I suggest you maybe get a development kit, EZ-USB[^]. This will give you some visual results. although it's not necessary. These kits though, come with external memory, a UART and serial connector, a set of push buttons, and an LED readout to facilitate development and debugging of your software. SO, that will help alot in your learning process. Next you need to learn the fundamentals of USB, like writing to a bus, etc. It's much different then the serial port. So just wrap the usb functions in c++ and then you can simply call the methods in your c# app/gui. It's a little more complicated then that though.... I have some code if you want to see it. Actually, everything is in that kit. It's too hard to type all this with one hand. (my wrist is broken.) /\ |_ E X E GG
-
Alright, I think I have the idea... I know microsft already provides generic drivers for scanners, so you can use that instead of the one that comes with the scanner (which is probably proprietry and not documented). SO, you wont' have to write your own driver, thats good. Um, I suggest you maybe get a development kit, EZ-USB[^]. This will give you some visual results. although it's not necessary. These kits though, come with external memory, a UART and serial connector, a set of push buttons, and an LED readout to facilitate development and debugging of your software. SO, that will help alot in your learning process. Next you need to learn the fundamentals of USB, like writing to a bus, etc. It's much different then the serial port. So just wrap the usb functions in c++ and then you can simply call the methods in your c# app/gui. It's a little more complicated then that though.... I have some code if you want to see it. Actually, everything is in that kit. It's too hard to type all this with one hand. (my wrist is broken.) /\ |_ E X E GG
This complies into a nice .net library with 2 main methods (bulk read, write) that I can seamsly use in my C# app. Actually with no pinvoking.
// This is the main DLL file.
#include "stdafx.h"
#include "csusb.dll" //simple error handler
#include "ezusbsys.h" //comes with the cypress board
#include "usb100.h" //found in windows DDK; contains USB definitions for constants & structures.using namespace System;
using namespace System::Text;
using namespace System::Runtime::InteropServices;namespace EzUsb
{
[StructLayout(LayoutKind::Explicit, Size=18, CharSet=CharSet::Auto)]
public __gc class UsbDeviceDescriptor
{
public:
[FieldOffset(0)] System::Byte bLength;
[FieldOffset(1)] System::Byte bDescriptorType;
[FieldOffset(2)] System::UInt16 bcdUSB;
[FieldOffset(4)] System::Byte bDeviceClass;
[FieldOffset(5)] System::Byte bDeviceSubClass;
[FieldOffset(6)] System::Byte bDeviceProtocol;
[FieldOffset(7)] System::Byte bMaxPacketSize0;
[FieldOffset(8)] System::UInt16 idVendor;
[FieldOffset(10)] System::UInt16 idProduct;
[FieldOffset(12)] System::UInt16 bcdDevice;
[FieldOffset(14)] System::Byte iManufacturer;
[FieldOffset(15)] System::Byte iProduct;
[FieldOffset(16)] System::Byte iSerialNumber;
[FieldOffset(17)] System::Byte bNumConfigurations;
};public \_\_gc class Usb { private: HANDLE \_hEzUsb; void ReportError( String\* msg ) { if( OnErrorMessage ) { OnErrorMessage( this, new ErrorEventArgs( msg ) ); } } void CheckWin32Error() { int errCode = GetLastError(); if( errCode != 0 ) { char msg\[256\]; FormatMessage( FORMAT\_MESSAGE\_FROM\_SYSTEM, NULL, errCode, 0, msg, 256, NULL ); ReportError( msg ); } } public: static const int MaxBlkSize = 64; \_\_delegate void ErrorMessage( Object\* sender, ErrorEventArgs\* e ); \_\_event ErrorMessage\* OnErrorMessage; Usb() { \_hEzUsb = INVALID\_HANDLE\_VALUE; } ~Usb() { if( \_hEzUsb != INVALID\_HANDLE\_VALUE ) { CloseHandle( \_hEzUsb ); } } bool Open( String\* driverName ) { char\* lpFileName = new char\[driverName->Length + 10\]; sprintf( lpFileName, "\\\\\\\\.\\\\%s", driverName ); \_hEzUsb = CreateFile( lpFileName, GENERIC\_WRITE, FILE\_SHARE\_WRITE, NULL, OPEN\_EXISTING, 0, NULL); if( \_hEzUsb == INVALID\_HANDLE\_VALUE ) { CheckWin32Error(); } delete lpFileName; return( \_hEzUsb != INVALID\_HANDLE\_VAL
-
Alright, I think I have the idea... I know microsft already provides generic drivers for scanners, so you can use that instead of the one that comes with the scanner (which is probably proprietry and not documented). SO, you wont' have to write your own driver, thats good. Um, I suggest you maybe get a development kit, EZ-USB[^]. This will give you some visual results. although it's not necessary. These kits though, come with external memory, a UART and serial connector, a set of push buttons, and an LED readout to facilitate development and debugging of your software. SO, that will help alot in your learning process. Next you need to learn the fundamentals of USB, like writing to a bus, etc. It's much different then the serial port. So just wrap the usb functions in c++ and then you can simply call the methods in your c# app/gui. It's a little more complicated then that though.... I have some code if you want to see it. Actually, everything is in that kit. It's too hard to type all this with one hand. (my wrist is broken.) /\ |_ E X E GG
Thank you very much. I am sure your words are very useful and helpful. And I am so sorry to hear about your wrist and hope you will be well quickly. Best regards vigorous