473,385 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to control USB port in C#

Hello everybody

I'm developing application using visual C#, and also using Barcode reader connected to USB port, some time i need to stop the barcode reader from reading when the cursor will be in another TextBox, for example when it is inside the price TextBox i don't want it to work.
Please if you have any information it will be helpful to me.
thanks in advance to all of you.
Jan 15 '08 #1
5 31727
Frinavale
9,735 Expert Mod 8TB
The manufacturers of the Barcode Reader should provide you with the drivers necessary to control it.

To connect to a usb you should use the System.IO class...

For example, the following code snippet will connect to a USB key (thumb drive), read it's information and create a text file on the USB key containing the USB key's information.
Expand|Select|Wrap|Line Numbers
  1. Try
  2.             'Making sure to demand permission to access USB
  3.             Dim myPerm As New FileIOPermission(PermissionState.Unrestricted)
  4.             myPerm.Demand()
  5.  
  6.             Dim ValidDriveLetters As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  7.             Dim info As System.IO.DriveInfo
  8.             Dim sb As New StringBuilder
  9.             Dim i As Integer
  10.             Dim len As Integer = ValidDriveLetters.Length - 1
  11.             For i = 0 To len
  12.                 info = New System.IO.DriveInfo(ValidDriveLetters(i))
  13.                 If info.IsReady Then
  14.                     If String.Compare(info.VolumeLabel, "NameOfMyUsbKey", True) = 0 Then
  15.                         sb.Append(info.DriveFormat)
  16.                         Dim wr As IO.StreamWriter = IO.File.AppendText(info.Name + "test.txt")
  17.                         wr.WriteLine("AvailableFreeSpace: " + info.AvailableFreeSpace.ToString)
  18.                         wr.WriteLine("DriveFormat: " + info.DriveFormat)
  19.                         wr.WriteLine("DriveType: " + info.DriveType.ToString)
  20.                         wr.WriteLine("Name: " + info.Name)
  21.                         wr.WriteLine("TotalFreeSpace: " + info.TotalFreeSpace.ToString)
  22.                         wr.WriteLine("TotalSize: " + info.TotalSize.ToString)
  23.                         wr.WriteLine("VolumeLabel: " + info.VolumeLabel)
  24.                         wr.Flush()
  25.                         wr.Close()
  26.                     End If
  27.                 End If
  28.             Next
  29.         Catch ex As Exception
  30.             LBL_Error.Text = "Failed to get permissions: " + ex.Message + " " + ex.StackTrace
  31.         End Try
I doubt you are going to access your reader in this manner.
You're going to have to use the drivers to control your Barcode reader...contact the manufacturer for any software development kits available.

-Frinny
Jan 15 '08 #2
Thank you Frinavale for your replay.

The barcode reader is working properly like a keyboard without any driver software, immediatly after i connected to the computer, i need only to stop it from working through my application using VC#.

The manufactory didn't give me any details about this.
from this website you can see the barcode reader which i purchased.

http://www.svbinternational.com/bar_code_scanners/bar_code_scannerusb.htm

model: SVB-0006
Jan 15 '08 #3
nmsreddi
366 256MB
Hello

I dint get your question properly,

when ever you are reading a barcode then the details related to that will be retrived from the existing database, when you are using the barcode for your purpose why you need to enter text again .can you give some more clarification about your application.


Thank you Frinavale for your replay.

The barcode reader is working properly like a keyboard without any driver software, immediatly after i connected to the computer, i need only to stop it from working through my application using VC#.

The manufactory didn't give me any details about this.
from this website you can see the barcode reader which i purchased.

http://www.svbinternational.com/bar_code_scanners/bar_code_scannerusb.htm

model: SVB-0006
Jan 16 '08 #4
Frinavale
9,735 Expert Mod 8TB
Hello everybody

I'm developing application using visual C#, and also using Barcode reader connected to USB port, some time i need to stop the barcode reader from reading when the cursor will be in another TextBox, for example when it is inside the price TextBox i don't want it to work.
Please if you have any information it will be helpful to me.
thanks in advance to all of you.
A barcode reader is an external device that will do it's own thing when certain events trigger it to process things (like when it is presented with a barcode).

I don't think that you'll be able to stop this from happening.

-Frinny
Jan 16 '08 #5
Plater
7,872 Expert 4TB
If the barcode acts like a keyboard, you need to research ways to disable keyboards(perferably a desired keyboard and not all keyboard) or look for ways to disable USB-DEVICES in general.
I would guess that it sends windows messages with the key strokes just the way the real keyboard does, so it would be hard to tell the difference.


On the DriveInfo class, I was unaware of that (DriveInfo.GetDrives() might be better then polling through a letter array). I would be interested to see if this recognizes drives that are mounted to a directory and not a drive letter.
Jan 16 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
7
by: Kevin | last post by:
Hi all I am having a problem reading from a serial port, first of all I have now resorted to using the MSComm ActiveX control on my Windows Forms to provide me with the interface to my serial...
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
23
by: Marco | last post by:
Could anyone please tell me why the program has the following error? I copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ...
25
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's...
0
by: 14Dallas | last post by:
Hi, I have been working with another programmer to write this code. I haven't written code in years - DBase III and Pascal - anyways, back to my code question. The program opens a file and...
7
by: davetelling | last post by:
I'm a newbie that is still struggling with OOP concepts & how to make things work they way I want. Using Visual C# Express, I have a form in which I added a user control to display a graph, based...
2
by: evle | last post by:
haw to read data from an Infrared Infrared Remote Control
3
by: Frank Swarbrick | last post by:
We are just starting to use DB2. I have a question about Control Center and port 523. Our DBA set up a database that listens on port 30280 (I have no idea where that port number came from...). ...
3
AaronL
by: AaronL | last post by:
Hello, I am currently working on a project that has me in sort of a bind. What I want to do is retrieve web pages from the internet, and strip them down to just text. I'll get using Regular...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.