Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial port using vb6

Status
Not open for further replies.

xanseviera

Junior Member level 3
Joined
Jun 22, 2010
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,434
im doing simulation traffic light project using VB whereby hardware can be controlled by VB using serial port.
my project consist of 4 junction... any changes in VB can cause changes in my hardware as well.
im already program my PIC as follows:

Junction 1
"a"=green
"b"=yellow
"c"=red

Junction 2
"d"=green
"e"=yellow
"f"=red

Junction 3
"g"=green
"h"=yellow
"i"=red

Junction 4
"j"=green
"k"=yellow
"l"=red

"m"=all light turn off

Below is coding regarding my project...

Code:
Private Sub LampuMerahNyala(Index As Integer)
    Select Case Index
    Case 0
        MSComm1.Output = "c"
    Case 1
        MSComm1.Output = "f"
    Case 2
        MSComm1.Output = "i"
    Case 3
        MSComm1.Output = "l"
    End Select
    
    shpLampuMerah(Index).BackColor = vbRed
End Sub

Private Sub LampuMerahMati(Index As Integer)
    Select Case Index
    Case 0
        MSComm1.Output = "m"
    Case 1
        MSComm1.Output = "m"
    Case 2
        MSComm1.Output = "m"
    Case 3
        MSComm1.Output = "m"
    End Select
    shpLampuMerah(Index).BackColor = RGB(50, 0, 0)
End Sub

Private Sub LampuKuningNyala(Index As Integer)
    Select Case Index
    Case 0
        MSComm1.Output = "b"
    Case 1
        MSComm1.Output = "e"
    Case 2
        MSComm1.Output = "h"
    Case 3
        MSComm1.Output = "k"
    End Select
    shpLampuKuning(Index).BackColor = vbYellow
End Sub

Private Sub LampuKuningMati(Index As Integer)
    
    Select Case Index
    Case 0
        MSComm1.Output = "m"
    Case 1
       MSComm1.Output = "m"
    Case 2
       MSComm1.Output = "m"
    Case 3
        MSComm1.Output = "m"
    End Select
    shpLampuKuning(Index).BackColor = RGB(50, 50, 0)
End Sub

Private Sub LampuHijauNyala(Index As Integer)
    Select Case Index
    Case 0
        MSComm1.Output = "a"
        idxLampuHijau = 0
    Case 1
        MSComm1.Output = "d"
        idxLampuHijau = 1
    Case 2
        MSComm1.Output = "g"
        idxLampuHijau = 2
    Case 3
        MSComm1.Output = "j"
        idxLampuHijau = 3
    End Select
    shpLampuHijau(Index).BackColor = vbGreen
    tmrArah.Enabled = True
End Sub

Private Sub LampuHijauMati(Index As Integer)
    tmrArah.Enabled = False
    ResetArahAnim
    
    Select Case Index
    Case 0
    MSComm1.Output = "m"
    Case 1
    MSComm1.Output = "m"
    Case 2
    MSComm1.Output = "m"
    Case 3
    MSComm1.Output = "m"
    End Select
    shpLampuHijau(Index).BackColor = RGB(0, 50, 0)
End Sub

Private Sub tmrLampu_Timer()
    Static Index As Integer
    Static intLampu As Integer
    Dim intNum As Integer
    
    Select Case intLampu
    Case 0 'Hijau
        LampuMati
        tmrLampu.Interval = Val(txtHijau(Index).Text) * 1000
        LampuHijauNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 1
    Case 1 'Kuning
        LampuMati
        tmrLampu.Interval = 3000
        LampuKuningNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 0
        Index = Index + 1
        If Index = 4 Then Index = 0
   End Select
End Sub

Private Sub cmdRun_Click(Index As Integer)
    Dim intNum As Integer
    LampuMati
    tmrLampu.Interval = 1
    tmrLampu.Enabled = True
    
        ' Fire Rx Event Every single Bytes
    MSComm1.RThreshold = 1
    
    ' When Inputting Data, Input 1 Byte at a time
    MSComm1.InputLen = 1
    
    ' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
    MSComm1.Settings = "9600,N,8,1"
    ' Disable DTR
    MSComm1.DTREnable = False
    
    ' Open COM3
    MSComm1.CommPort = 3
    MSComm1.PortOpen = True

   
End Sub

can sum1 help me out..
TQ
 

xanseviera said:
im doing simulation traffic light project using VB whereby hardware can be controlled by VB using serial port.
my project consist of 4 junction... any changes in VB can cause changes in my hardware as well.

........

can sum1 help me out..
TQ

Your problem is not clear.
 

im tried using hyper-terminal... everything works fine based on below:

Junction 1
"a"=green
"b"=yellow
"c"=red

Junction 2
"d"=green
"e"=yellow
"f"=red

Junction 3
"g"=green
"h"=yellow
"i"=red

Junction 4
"j"=green
"k"=yellow
"l"=red

my problem occur when going to VB part.
when im running my project only green light(Junction 1) light on & remain the same for the entire process.
 

Still confused your problem

Anyway

you may check this part

Code:
Private Sub tmrLampu_Timer()
    Static Index As Integer
    Static intLampu As Integer
    Dim intNum As Integer
   
    Select Case intLampu
    Case 0 'Hijau
        LampuMati
        tmrLampu.Interval = Val(txtHijau(Index).Text) * 1000
        LampuHijauNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum '<---- Check this
        Next
        intLampu = 1
    Case 1 'Kuning
        LampuMati
        tmrLampu.Interval = 3000
        LampuKuningNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum '<---- Check this
        Next
        intLampu = 0
        Index = Index + 1
        If Index = 4 Then Index = 0
   End Select
End Sub

I guess that your made a mistake within the Case statement.

Check procedure "LampuMerahNyala" called in both case statement
 

is it my case statement was wrong?
 

I guess "Sub tmrLampu_Timer()" may be the problem

you may check this and post your comment

Code:
Static Index As Integer '<-- take out this two variables
Static intLampu As Integer

Private Sub tmrLampu_Timer()
    
    Dim intNum As Integer
   
    tmrLampu.Enabled = False'<-- Add this line

    Select Case intLampu
    Case 0 'Hijau
        LampuMati
        tmrLampu.Interval = Val(txtHijau(Index).Text) * 1000
        LampuHijauNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 1
    Case 1 'Kuning
        LampuMati
        tmrLampu.Interval = 3000
        LampuKuningNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 0
        Index = Index + 1
        If Index = 4 Then Index = 0
   End Select

tmrLampu.Enabled = True '<-- Add this line

End Sub
 

i try another method whereby, i put another dependent button & hit it.
my circuit changed accordingly.

Code:
Private Sub Command6_Click()
    MSComm1.PortOpen = True
    MSComm1.Output = "a"
    MSComm1.Output = "b"
    MSComm1.Output = "c"
    MSComm1.PortOpen = False      'Close the COMM port
End Sub

Private Sub Command1_Click()
              
    MSComm1.PortOpen = True
    MSComm1.Output = "d"
    MSComm1.Output = "e"
    MSComm1.Output = "f"
    
    MSComm1.PortOpen = False      'Close the COMM port

End Sub

when im combine everything... it cant work.
below is coding that related to the timer(tmrLampu_Timer)
please correct me if im wrong.

Code:
Private Sub LampuMerahNyala(Index As Integer)
    Select Case Index
    Case 0
    MSComm1.PortOpen = True
        MSComm1.Output = "c"
        MSComm1.PortOpen = False
    Case 1
    MSComm1.PortOpen = True
        MSComm1.Output = "f"
        MSComm1.PortOpen = False
    Case 2
    MSComm1.PortOpen = True
        MSComm1.Output = "i"
        MSComm1.PortOpen = False
    Case 3
    MSComm1.PortOpen = True
        MSComm1.Output = "l"
        MSComm1.PortOpen = False
    End Select

    shpLampuMerah(Index).BackColor = vbRed
End Sub

Private Sub LampuMerahMati(Index As Integer)
    Select Case Index
    Case 0
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    Case 1
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    Case 2
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    Case 3
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    End Select
    shpLampuMerah(Index).BackColor = RGB(50, 0, 0)
End Sub

Private Sub LampuKuningNyala(Index As Integer)
    Select Case Index
    Case 0
    MSComm1.PortOpen = True
        MSComm1.Output = "b"
        MSComm1.PortOpen = False
    Case 1
    MSComm1.PortOpen = True
        MSComm1.Output = "e"
        MSComm1.PortOpen = False
    Case 2
    MSComm1.PortOpen = True
        MSComm1.Output = "h"
        MSComm1.PortOpen = False
    Case 3
    MSComm1.PortOpen = True
        MSComm1.Output = "k"
        MSComm1.PortOpen = False
    End Select
    shpLampuKuning(Index).BackColor = vbYellow
End Sub

Private Sub LampuKuningMati(Index As Integer)

    Select Case Index
    Case 0
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    Case 1
    MSComm1.PortOpen = True
       MSComm1.Output = "m"
       MSComm1.PortOpen = False
    Case 2
    MSComm1.PortOpen = True
       MSComm1.Output = "m"
       MSComm1.PortOpen = False
    Case 3
    MSComm1.PortOpen = True
        MSComm1.Output = "m"
        MSComm1.PortOpen = False
    End Select
    shpLampuKuning(Index).BackColor = RGB(50, 50, 0)
End Sub

Private Sub LampuHijauNyala(Index As Integer)
    Select Case Index
    Case 0
        MSComm1.PortOpen = True
        MSComm1.Output = "a"
        MSComm1.PortOpen = False
        idxLampuHijau = 0
    Case 1
        MSComm1.PortOpen = True
        MSComm1.Output = "d"
        MSComm1.PortOpen = False
        idxLampuHijau = 1
    Case 2
        MSComm1.PortOpen = True
        MSComm1.Output = "g"
        MSComm1.PortOpen = False
        idxLampuHijau = 2
    Case 3
        MSComm1.PortOpen = True
        MSComm1.Output = "j"
        MSComm1.PortOpen = False
        idxLampuHijau = 3
    End Select
    shpLampuHijau(Index).BackColor = vbGreen
    tmrArah.Enabled = True
End Sub

Private Sub LampuHijauMati(Index As Integer)
    tmrArah.Enabled = False
    ResetArahAnim

    Select Case Index
    Case 0
    MSComm1.PortOpen = True
    MSComm1.Output = "m"
    MSComm1.PortOpen = False
    Case 1
    MSComm1.PortOpen = True
    MSComm1.Output = "m"
    MSComm1.PortOpen = False
    Case 2
    MSComm1.PortOpen = True
    MSComm1.Output = "m"
    MSComm1.PortOpen = False
    Case 3
    MSComm1.PortOpen = True
    MSComm1.Output = "m"
    MSComm1.PortOpen = False
    End Select
    shpLampuHijau(Index).BackColor = RGB(0, 50, 0)
End Sub


Private Sub tmrLampu_Timer()
    Static Index As Integer
    Static intLampu As Integer
    Dim intNum As Integer
    
    Select Case intLampu
    Case 0 'Hijau
        LampuMati
        tmrLampu.Interval = Val(txtHijau(Index).Text) * 1000
        LampuHijauNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 1
    Case 1 'Kuning
        LampuMati
        tmrLampu.Interval = 3000 'yellow delay for 3sec
        LampuKuningNyala Index
        For intNum = 0 To 3
            If intNum <> Index Then LampuMerahNyala intNum
        Next
        intLampu = 0
        Index = Index + 1
        If Index = 4 Then Index = 0
   End Select
   
   End Sub

TQ.
 

xanseviera

can u attach your soure code??
it is more easy if i can see the interface...
 

u mean the whole project?

Added after 1 hours 49 minutes:

lockman_akim said:
xanseviera

can u attach your soure code??
it is more easy if i can see the interface...

i've attached my source code...
plz take a look.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top