Port access in VB 2005

cjk2, Sun Feb 19 2006, 02:41AM

Hi all, I would like to try interfacing my TV with my computer and I would like to use a VB program to do it.
My question is: Is it possible to make a serial/parallel port I/O line high and low on command? If so how can I do this in VB 2005 express?
Re: Port access in VB 2005
Bjørn, Sun Feb 19 2006, 03:22AM

The most important question is, what do you want to interface to the ports? A relay or an IR LED?

You can open a serial port like this:
Dim myPort As IO.Ports.SerialPort = New IO.Ports.SerialPort("COM1", 19200, False, 8, 1)

You then have two pins you can control like this:
myPort.RtsEnable = True
myPort.DtrEnable = False
Re: Port access in VB 2005
cjk2, Sun Feb 19 2006, 03:33AM

I would like to be able to use my computer as a remote if it's not too hard to do. I would probably end up using an optoisolator and battery to turn an IR sender module (38khz or 40khz carrier frequency) on and off to send the signals for power, mute, channels, volume, etc.
Re: Port access in VB 2005
Bjørn, Sun Feb 19 2006, 03:38AM

To control the LED with perfect timing you need to shut down multitasking and disable interrupts, it is generally a bad idea. Instead of the IR module, use a microcontroller that does all the timing. If you really want to make an all software solution then it is possible but it is ugly and rather involved.
Re: Port access in VB 2005
Carbon_Rod, Sun Feb 19 2006, 04:34AM

As easy as hit "play" on a sound card...
Link2
Prep your wav files and just use sound player OLE. ( 10 min or less )

The sniffer is easy to make this way too (Line in.) And gives a nice wav to study. Many projects you will find on the net will not work with the hardware. This way is the only 100% sure fire way to get your times and codes right (unless you have a nice digital scope at home.)

Tip: Sony IR units are very easy to code. Where as Sharp etc. may need a bit more work.

There are also a few GPL apps (only linux and old PalmOS last I checked) that trick an irda port into reading the codes.


Or one could always link the LPT port to a working remote button pads with some simple driver logic and some jumpers.

B)
Cheers,
Re: Port access in VB 2005
cjk2, Sun Feb 19 2006, 04:48AM

Well the code seens to be good but I still cant seem to make it work. I checked voltages on all the pins of the port as I clicked the buttons, and no voltages changed.
Heres what I used:
Public Class Form1
    Dim myPort As IO.Ports.SerialPort = New IO.Ports.SerialPort("COM1", 19200, False, 8, 1)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        myPort.RtsEnable = True

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        myPort.RtsEnable = False

    End Sub
End Class



Edit: I may try that as well. Thanks Carbon Rod. I would still like to see if I can use a serial port as the audio line is already in use.
Re: Port access in VB 2005
Bjørn, Sun Feb 19 2006, 05:21AM

Hardware handshaking may be turned on by default and overriding your code. Try to turn it off.
Re: Port access in VB 2005
Carbon_Rod, Sun Feb 19 2006, 06:12AM

This is some very old MS VB5 code.
(it uses the MSCOMM control)

A small test app...

]1140329549_65_FT1457_serial.zip[/file]