Serial communication using VB

A

Thread Starter

anibee

I hope someone out there can help me with my new project. I'm completely a baby to VB, and my new project is about sending and receiving data to/from a device to the PC so that I can do the simulation. I also need to work with serial communication and all the problems now must be done in VB.

I'm working with the source code, and it seems like I'm totally lost. The due date is just around the corner and I'll completely appreciate it if someone can help me.

Thank you,
baby_shinoda @ yahoo. com
 
<p>I tried becoming a new member but the proxy failed. Will try at home if I get time.

<p>Some code and an inf file from a past project.

<p>Don't have time to explain much at this time.

<p>Later,

<p>Clint

<pre>
Sub initQuadComm(Comm As MSComm, iPort%, sCommSetting$)
Dim dummyBuf$

'If gbRanEditor Then
If Comm.PortOpen = True Then Comm.PortOpen = False
gbQuad = False

'End If
On Error Resume Next
If Not Comm.PortOpen Then
Comm.CommPort = iPort%
Comm.Settings = sCommSetting$
Comm.InputLen = 0
Comm.OutBufferSize = 8
Comm.PortOpen = True
gbQuad = True

Else
'clear buffer
If Comm.InBufferCount > 0 Then
dummyBuf$ = Comm.Input
End If
End If

End Sub

Sub Main()
Dim abbrVer$, msg$
Dim abbrDate$

Call setGlobals
gIniFile$ = getIniFile$(InfFile$)
If Not isfile%(gIniFile$) Then
msg$ = "Quad Information File Not Found, " & vbCrLf
msg$ = msg$ & "Advise Your System Administrator. That the [quad.inf] file is missing."
msg$ = msg$ & "This file should be located in the [Data] folder next to this application's folder." & vbCrLf & vbCrLf
msg$ = msg$ & "The application should proceed with default settings only. 1200 bps, port 2 ect."
MsgBox msg$, 16
'End
Else
Call getIniSettings
Call SetHelpFile(gProgDrive$, gProgPath$)
End If
abbrVer$ = Mid(CurVer$, 1, InStr(InStr(CurVer$, ".") + 1, CurVer$, ".") - 1)
abbrDate$ = Mid(VerDate$, InStr(VerDate$, " ") + 1)
QuadSwitcher.Show 1
End Sub

Sub setGlobals()

App.Title = "Quad Switcher"

ReDim gWarnings$(7)

'\\\\\\\\\\\\\\\\\\Default settings for FIO-8007 Color Quad///////////////////////////////
' Settings read in from inf. file will overwrite these values.

With Q1
.Quad = "GE"
.Zoom1 = "GA"
.Zoom2 = "GB"
.Zoom3 = "GC"
.Zoom4 = "GD"
End With

With Q2
.Quad = "GE"
.Zoom1 = "GA"
.Zoom2 = "GB"
.Zoom3 = "GC"
.Zoom4 = "GD"
End With

'/////////////////////////////////////////////////////////////////////////////////////////
End Sub


Option Explicit

Public gProgDrive$
Public gProgPath$
Public gAddressFile$
Public gbDualQuads As Boolean


Sub getIniSettings()
Dim arrayTemp$(), dataTemp$() 'getIniSettings
Dim i As Integer 'getIniSettings
Dim j As Integer
Dim u As Integer
Dim strTemp As String
Dim striniSection As String


On Error GoTo ErrSkip ' If we don't have quad.inf to read we don't want to mess up the defaults.
'gProgDrive$ = getinisetting("COMMON", "ProgDrive", gIniFile$)
gbDualQuads = getinisetting("COMMON", "DualQuads", gIniFile$)
Q1.Name = getinisetting("COMMON", "Quad1Name", gIniFile$)
Q2.Name = getinisetting("COMMON", "Quad2Name", gIniFile$)

Q1.CommSettings = getinisetting("MECH INTERFACE", "CommSettingsQuad1", gIniFile$)
Q2.CommSettings = getinisetting("MECH INTERFACE", "CommSettingsQuad2", gIniFile$)
DoEvents
Q1.PortNumber = CInt(getinisetting("MECH INTERFACE", "CommQuad1Port", gIniFile$))
Q2.PortNumber = CInt(getinisetting("MECH INTERFACE", "CommQuad2Port", gIniFile$))

If Q1.PortNumber = Q2.PortNumber Then
If MsgBox("Both Quads using the same port number. Please edit file.", vbYesNo, "Error in port assignments!") = vbYes Then
infEditor
End If
End If

With Q1
.Quad = getinisetting("QUAD1 SWITCHING", "gotoQUAD", gIniFile$)
.Zoom1 = getinisetting("QUAD1 SWITCHING", "gotoZOOM1", gIniFile$)
.Zoom2 = getinisetting("QUAD1 SWITCHING", "gotoZOOM2", gIniFile$)
.Zoom3 = getinisetting("QUAD1 SWITCHING", "gotoZOOM3", gIniFile$)
.Zoom4 = getinisetting("QUAD1 SWITCHING", "gotoZOOM4", gIniFile$)
End With

With Q2
.Quad = getinisetting("QUAD2 SWITCHING", "gotoQUAD", gIniFile$)
.Zoom1 = getinisetting("QUAD2 SWITCHING", "gotoZOOM1", gIniFile$)
.Zoom2 = getinisetting("QUAD2 SWITCHING", "gotoZOOM2", gIniFile$)
.Zoom3 = getinisetting("QUAD2 SWITCHING", "gotoZOOM3", gIniFile$)
.Zoom4 = getinisetting("QUAD2 SWITCHING", "gotoZOOM4", gIniFile$)
End With



Exit Sub

ErrSkip:
MsgBox "An error took place while loading settings from " & gIniFile$, vbExclamation, "Information reading error."

End Sub


Option Explicit

Sub getIniArray(iniSection$, searchString$, arrayIn$())
Dim i As Integer
Dim strInitemp() As String
Dim strmsgtxt As String

ReDim strInitemp(0)
ReDim arrayIn$(0)
i = 1
Do
ReDim Preserve strInitemp(i)
strInitemp(i - 1) = getinisetting(iniSection$, searchString$ & Format(i, "0"), gIniFile$)
i = i + 1
Loop While strInitemp(i - 2) <> "Item Not Found"

If i = 2 Then 'no settings
strmsgtxt = "There are no " & searchString$ & "s defined." & vbCrLf
strmsgtxt = strmsgtxt & "They must be defined in the inf file." & vbCrLf
strmsgtxt = strmsgtxt & "This Program will now terminate."
MsgBox strmsgtxt, 16
End If

For i = 0 To UBound(strInitemp) - 2
ReDim Preserve arrayIn$(i)
arrayIn$(i) = strInitemp(i)
Next i

End Sub

Option Explicit

Public gProgDrive$
Public gProgPath$
Public gAddressFile$
Public gbDualQuads As Boolean


Sub getIniSettings()
Dim arrayTemp$(), dataTemp$() 'getIniSettings
Dim i As Integer 'getIniSettings
Dim j As Integer
Dim u As Integer
Dim strTemp As String
Dim striniSection As String


On Error GoTo ErrSkip ' If we don't have quad.inf to read we don't want to mess up the defaults.
'gProgDrive$ = getinisetting("COMMON", "ProgDrive", gIniFile$)
gbDualQuads = getinisetting("COMMON", "DualQuads", gIniFile$)
Q1.Name = getinisetting("COMMON", "Quad1Name", gIniFile$)
Q2.Name = getinisetting("COMMON", "Quad2Name", gIniFile$)

Q1.CommSettings = getinisetting("MECH INTERFACE", "CommSettingsQuad1", gIniFile$)
Q2.CommSettings = getinisetting("MECH INTERFACE", "CommSettingsQuad2", gIniFile$)
DoEvents
Q1.PortNumber = CInt(getinisetting("MECH INTERFACE", "CommQuad1Port", gIniFile$))
Q2.PortNumber = CInt(getinisetting("MECH INTERFACE", "CommQuad2Port", gIniFile$))

If Q1.PortNumber = Q2.PortNumber Then
If MsgBox("Both Quads using the same port number. Please edit file.", vbYesNo, "Error in port assignments!") = vbYes Then
infEditor
End If
End If

With Q1
.Quad = getinisetting("QUAD1 SWITCHING", "gotoQUAD", gIniFile$)
.Zoom1 = getinisetting("QUAD1 SWITCHING", "gotoZOOM1", gIniFile$)
.Zoom2 = getinisetting("QUAD1 SWITCHING", "gotoZOOM2", gIniFile$)
.Zoom3 = getinisetting("QUAD1 SWITCHING", "gotoZOOM3", gIniFile$)
.Zoom4 = getinisetting("QUAD1 SWITCHING", "gotoZOOM4", gIniFile$)
End With

With Q2
.Quad = getinisetting("QUAD2 SWITCHING", "gotoQUAD", gIniFile$)
.Zoom1 = getinisetting("QUAD2 SWITCHING", "gotoZOOM1", gIniFile$)
.Zoom2 = getinisetting("QUAD2 SWITCHING", "gotoZOOM2", gIniFile$)
.Zoom3 = getinisetting("QUAD2 SWITCHING", "gotoZOOM3", gIniFile$)
.Zoom4 = getinisetting("QUAD2 SWITCHING", "gotoZOOM4", gIniFile$)
End With



Exit Sub

ErrSkip:
MsgBox "An error took place while loading settings from " & gIniFile$, vbExclamation, "Information reading error."

End Sub







;quad.inf file located in the data folder next to bin folder where program resides.



[COMMON]

; If running two quads on one PC then set DualQuads="True" else "False"

DualQuads="True"

; If not DualQuads then the CommQuad1Port is used below.
; Quad1Name is used for one Quad, ie. DualQuads="False"

Quad1Name="Quad 6"
Quad2Name="Quad 7"


[MECH INTERFACE]
CommSettingsQuad1="1200,N,8,1"
CommSettingsQuad2="1200,N,8,1"

; Do not assign same port number to each.
CommQuad1Port=2
CommQuad2Port=1

[QUAD1 SWITCHING]
gotoZOOM1="GA"
gotoZOOM2="GB"
gotoZOOM3="GC"
gotoZOOM4="GD"
gotoQUAD="GE"

[QUAD2 SWITCHING]
gotoZOOM1="GA"
gotoZOOM2="GB"
gotoZOOM3="GC"
gotoZOOM4="GD"
gotoQUAD="GE"
</pre>
 
Top