input/output usb con

Blitz3D Forums/Blitz3D Programming/input/output usb con

Heliotrope(Posted 2010) [#1]
I was thinking could you hack a usb cable so it has a swich. Then you type some comand lines so the screen turnes red when you push the swich.


Whats My Face(Posted 2010) [#2]
If you could get windows to see it as a joystick or something of that nature I could see this working.


Oiduts Studios(Posted 2010) [#3]
http://www.trossenrobotics.com/store/Search.aspx?searchTerms=usb&submit=true
I'm kind of sure you could find something on here. Also, maybe you could modify an old joystick?


Heliotrope(Posted 2010) [#4]
thanks,thanks.


Charrua(Posted 2010) [#5]
all usb devices must have some intelligence to read/write apropiate packet's into the bus with some many fields inside, so, a simple cable with a switch doesn't work. I think that using an existing usb device and modifyng it to meet your needs is the best approach. In this way you can use a keypad or joystick just because blitz has already commands to get input from they.

Juan


Heliotrope(Posted 2010) [#6]
Have you found anything yeat blitz monkey.


Charrua(Posted 2010) [#7]
hey, traing to put a switch on a usb cable is like to try to put a switch on a utp (lan) cable or a switch on a fm radio an think that should be read via wi-fi. Don't missunderstandme, is like spoke to a computer that has no mic, and no voice recogn running in it and hope that it respond to our commands.

you have to have a usb controller at one end of the cable that handshake wiht the usb host that is inside the pc.

if you want to read a switch, use the paralel port, on XP systems there are dll to handle io wiht simple In and Out comands provided by the dll
DLPORIO

if you try to do that with a serial port, the same as with ethernet and usb, you have to have a serial device that receives the seiral info and eventualy read switches or whatever and send that info back serially to tha host pc.

for that uses, tipically there will be a Microcontroller at the end side, wiht usb support, or serial suport or ethernet support that with some minimal resources (at least the libs needed to handle the protocols) handshakes with the pc.

but, you have to have some electronics skills or buy an already made module like those in the link apported by BlitzMonkey

(sorry my bad english)

Juan


Midimaster(Posted 2010) [#8]
A easy and cheap way to have a usb-switch is to buy a usb-joystick . For less than 5,oo$ you get upto 8 buttons (signal ways) for free use and dont have to think about the usb-communication logic. On the B3D-side you can code with easy joystick commands to check the status.

the joystick can be opened and you can connect the push-button pins with longer cables and customized switches/buttons. Replace the push-buttons with toggle switches is also allowed.


Serpent(Posted 2010) [#9]
As everyone has already said, the simplest thing to do (if you're doing this for personal applications) is to use the input of a USB device designed for just that. In fact, depending on what you're trying to do, you could just bypass the whole USB device altogether and just use hotkey(s) on the keyboard or mouse to activate your screen-hider (i think that's what it is).


Rroff(Posted 2010) [#10]
Whatever you do... don't wire a switch directly onto a USB cable, it will short the USB hub atleast theres a reasonable bit of amperage involved... and if your unlucky do more damage.


Heliotrope(Posted 2010) [#11]
Charrua, how do I use a .DLL file in Blitz.


Charrua(Posted 2010) [#12]
hi

to use any dll, you have to have the dll in the directory that your application will work (and distribute your application with it) and a .decls file for that dll placed in the UserLibs directory (child of the Blitz3d instalation directory). If you refer to DLPORTIO the .decls file should contain:

.lib "dlportio.dll"

DlPortReadPortUchar%( port% )
DlPortReadPortUshort%( port% )
DlPortReadPortUlong%( port% )

DlPortReadPortBufferUchar( port%, buffer*, count% )
DlPortReadPortBufferUshort( port%, buffer*, count% )
DlPortReadPortBufferUlong( port%, buffer*, count% )

DlPortWritePortUchar( port%, value% )
DlPortWritePortUshort( port%, value% )
DlPortWritePortUlong( port%, value% )

DlPortWritePortBufferUchar( port%, buffer*, count% )
DlPortWritePortBufferUshort( port%, buffer*, count% )
DlPortWritePortBufferUlong( port%, buffer*, count% )



to download dlportio.dll:
http://www.dlldll.com/dlportio.dll_download.html

runs on xp based system, if you have a paralell port, see wich is your parallel port base port (nomally $378, $278 or $3bc) and do an out to that base port. The individual bits ( from 0 to 7 ) are on pins from 2 to 9 and pins 18 to 25 are ground, so to check the value you send to the base port, use a voltimeter (or a led with a 390 ohms in series)
Keep the black tip of the voltimeter on the pin 18 of the paralell port, then scan pins 2 to 9 with the red lead and watch the values.

you will only use 2 functions:

to send a char (byte) to the parallel port use:
DlPortWritePortUchar( port%, value% )

DlPortWritePortUchar( $378, $A5 )
send the binary value: 10100101 to the base port ( $378 in hexadecimal, 888 in decimal )

the (BasePort+1) is the Status Port, is an input port in wich the five mos significant bits are wired to 5 pins of the db25 conector. The most significant bit (bit 7) is inverted.

see Pinout:
http://en.wikipedia.org/wiki/Parallel_port#Pinouts

to read use:
DlPortReadPortUchar%( port% )

ValueReaded% = DlPortReadPortUchar($379) ; use $379 = BasePort+1 to read the status port.

Juan