Link to home
Start Free TrialLog in
Avatar of pentacost
pentacostFlag for Philippines

asked on

VB 6 Receive Data from USB Port

Hi everyone..

Can anyone help me..i'm going to make an improvise optical sensor by using the sensor of an optical mouse..
i want it to act like a counter
can anyone teach me on how to do this..if it is possible

btw im using visual basic 6

Thanks in advance..
Avatar of JigglyD
JigglyD

Pentacost, are you looking at making some sort of motion detector?
Avatar of pentacost

ASKER

yes i do..actually im looking for a device that could act as a counter..
Well, here's a strange possibility for you...

By leaving the optical mouse connected via USB, you could simply respond to a MouseMove event (which would automatically be fired whenever the optical sensor is tripped).  I would also put in some sort of minor delay timer so you didn't record the same person more than once.

Of course, this means that you would have to create an application that was complete keyboard (or touch screen) driven.

Jiggle On ! ! !
hmm..may i ask for some sample codes on how to do this..

coz i this is my first time to USB port..can u give me some tips?

thank you very much i appreciate your help..
this'll help me alot in my thesis..coz im doing a prototype project of a filler machine downtime
I have to take off now, but I will post some code later tonight.

Jiggle On ! ! !
Will this mouse count people?, tickets? other objects?

I dont think a mouse can detect motion if is not close enough to the object.

btw, if you use a mouse following pentacost's advice, you don't need to interact with usb ports, vb can handle the device as a standard mouse
the mouse will count canned goods..
i think retitiseert is right..it should be close enough, but i'll think of some better way later on..my only concern by now is how to take control it's events.. btw rettiseert im going to use an optical mouse and i'm going to remove it's optical sensor and make an improvised motion sensor that's why i want it to interact with the usb port..

is controlling a standard mouse in vb the same when controlling an optical mouse.. because i want it to trigger when a canned good pass through it and make a count in vb..

thanks for advices guys..
god bless
oooops.. i think im going to have another problem..because by setting the mouse Event it will restrict the movement of the cursor..

is there any other way to do this? coz i still want to control the cursor of the mouse..
pentacost - Using an optical mouse for this purpose is an excellent idea. Cheap and reliable.

Setting the MouseMove event should not restrict the mouse movement at all. However, the event fires only in the active form or control - so basically, if you move the good over the mouse sensor, this is interpreted as a mouse movement. Therefore, the cursor moves in one direction until it's at the border of the form or screen. You could prevent this by setting your application to full screen.

Another option would be to write a filter for windows events ("hook"). Check out this article: http://www.vbaccelerator.com/home/VB/Code/Libraries/Hooks/Mouse_Gestures/article.asp - it explains how to create a filter which will trigger any movement of the mouse irrespective of the active window. You wan't need most of the code (it's for detecting gestures), but it shows the idea.

The third option would be to actually catching the mouse movements at the USB port. A mouse is generally a serial device, so mouse movements translate into a stream of data into the serial port. Unfortunately, Windows seems to know that a mouse is a mouse and not another serial device...

Jan
fulscher:
is there any way i can catch the binary data sent by the movement of the mouse?
I'm not sure - look to me that you would have to write your own mouse driver to catch that data. In addition, you'd have to interprete the data coming from the mouse. I think it might be easier to go the hook way (at least for me, it would be easier).

Or you try to find an optical mouse which connects to the serial port. You could then catch the data coming from the serial port (after telling Windows that it's not supposed to treat that device as a mouse). This probably would be easier than trying to fetch data from the USB port (to be honest, I've no idea how to do this).

Jan
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial