vb 2008 express control serial port relay

Thread Starter

bn4al

Joined Apr 7, 2012
9
hi,

i would like to control up to 10 relays via serial port using visual basic express 2008.

i would like to have a circuit diagram and the vb code.

i have already started designing the interface, i need now to have the code?

thanks to help me out..
 

Attachments

Thread Starter

bn4al

Joined Apr 7, 2012
9
hi, is this is impossible then please do send me the code for the following pins:
pin 7 , TRS
pin 4, DTR

i have already mount the circuit and using a free software i found on the net, but i would like to have my own software thats why i need help for the code.
 

panic mode

Joined Oct 10, 2011
1,777
no, both are DotNet. But the project may be older and need conversion. That is ok, just let the converter do it's job when you open code sample first time. Converter works reasonably well even for VB classic code (not DotNet, here we talk about VB6, or VB5), but on DotNet it is just a formality.
 

bluebrakes

Joined Oct 17, 2009
245
using a serial port to do the job your asking is going to be a larger task than using a parallel port, which would be best suited for a job such as this.

Especially as you're probably going to need to program a pic to understand the serial commands you intend to send.
 

bluebrakes

Joined Oct 17, 2009
245
classic vb6 is a lot easier to program serial/parallel ports with than .net in my opinion.
 

panic mode

Joined Oct 10, 2011
1,777
i used both VB6 or VB.NET to interface to RS232 devices. Both are very straight forward when it comes to using serial port.

it is preferred that target circuit is intelligent (MCU) but it does not have to be.
it could be replaced by simple shift (and latch) register like 74HC565. adding driver like ULN2803 gives you a lot of freedom in terms of type of load.

there are many chips that combine shift/latch/driver function into single chip (L9822N for example). they can be cascaded to get 8, 16, 24 or more outputs - all individually addressable.
 

Thread Starter

bn4al

Joined Apr 7, 2012
9


here's what am planning to do.

i have already mount the circuit and works well with free software i found on the net.

but i would like to have to write the codes so that i can do some modification.
 

panic mode

Joined Oct 10, 2011
1,777
here's the pic of the program i actually want as
you mean this is what you want finished program to look like? good luck with that...

1. unless you have computer with built in comport, and cable permanently attached to it, you need (at very least) option to select com port. most computer these days don't have serial port and usually one is added in form of USB to RS232 converter.

2. next thing you need to have is controls to open and close connection.

3. interface should be both ways, you need fields (text box, label, whatever) to show you what comes in and what you are sending. you only show buttons to manually force control lines (outputs on PC port).
 

Felo

Joined Feb 20, 2012
91
What kind of electronics do you have?, I have made this very same thing you are trying to do.

Good Luck
 

Thread Starter

bn4al

Joined Apr 7, 2012
9
this is the circuit i done and works well.

i'll have to control these pins through some codes now.

am actually using a USB to serial converter.

need to assign a combo box for the com port. i.e com1, com 2.....
 

Attachments

Felo

Joined Feb 20, 2012
91
Thas is just a driver, I don't feel like you are trying hard enough, Do you have anything else? or you believe that someone is going to do all the work for you?
 

Thread Starter

bn4al

Joined Apr 7, 2012
9
the first pic was when i was working with paralell port, i could control 8 outputs and 5 inputs with that.

i thought of doing the same with serial port and i was wrong unless i use a PIC.

thats why now am doing it with 2 outputs.
 

Thread Starter

bn4al

Joined Apr 7, 2012
9
here's the code till far i have reached


Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com4"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.DtrEnable = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Open()
SerialPort1.RtsEnable = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.Close()
SerialPort1.DtrEnable = False

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
SerialPort1.RtsEnable = False
SerialPort1.Close()
End Sub
........................................................................................................

there's still some bug in it which i have to amend.

as panic mode said, i'll have to add an option to select com port, which i really dont know how to do now. i have already add the combo box and add the com port names, i.e com1 till com9. but to make it works......
 

panic mode

Joined Oct 10, 2011
1,777
try this:

Rich (BB code):
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close()
      '  SerialPort1.PortName = "com4"
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        Dim i As Integer
        For i = 1 To 15 ' create Com1..Com15
            Me.ComboBox1.Items.Add("Com" & i)
        Next
        Me.ComboBox1.SelectedIndex = 3 ' preselect Com4
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SerialPort1.PortName = Me.ComboBox1.SelectedItem
        SerialPort1.Open()
        SerialPort1.DtrEnable = True
    End Sub
 

Thread Starter

bn4al

Joined Apr 7, 2012
9
Thanks a lot Panic Mode

so sorry for the delay,

well i have been able to complete it by your help.

thanks a lot.

there's only one thing, when i scroll down for the com port, it repeats the com port, means i can see from com port 1 to com port 15 twice.

here's the code


Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
' SerialPort1.PortName = "com4"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
Dim i As Integer
For i = 1 To 15 ' create Com1..Com15
Me.ComboBox1.Items.Add("Com" & i)
Next
Me.ComboBox1.SelectedIndex = 3 ' preselect Com4

End Sub

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

SerialPort1.DtrEnable = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.PortName = Me.ComboBox1.SelectedItem
SerialPort1.Open()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.DtrEnable = False
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
SerialPort1.Close()
End Sub

Private Sub AboutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
MsgBox("Welcome")
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
SerialPort1.RtsEnable = True
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
SerialPort1.RtsEnable = False
End Sub
End Class
 
Top