Public Class AutoTiming
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Integer) As Integer
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function Version Lib “k8055d.dll” () As Integer
Private Declare Function SearchDevices Lib “k8055d.dll” () As Integer
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Integer) As Integer
Private Declare Function ReadAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib “k8055d.dll” (ByRef Data1 As Integer, ByRef Data2 As Integer)
Private Declare Sub OutputAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib “k8055d.dll” (ByVal Data1 As Integer, ByVal Data2 As Integer)
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib “k8055d.dll” ()
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()
Private Declare Sub SetAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Integer
Private Declare Function ReadCounter Lib “k8055d.dll” (ByVal CounterNr As Integer) As Integer
Private Declare Sub ResetCounter Lib “k8055d.dll” (ByVal CounterNr As Integer)
Private Declare Sub SetCounterDebounceTime Lib “k8055d.dll” (ByVal CounterNr As Integer, ByVal DebounceTime As Integer)
Dim ci As CultureInfo = CultureInfo.InvariantCulture
Dim stopWatchCar1 As New Stopwatch()
Dim stopWatchCar2 As New Stopwatch()
Dim StopwatchNextCar As New Stopwatch()
Dim stopwatchStartDelay As New Stopwatch
Dim stopwatchFinishDelay As New Stopwatch
Dim tsCar1 As TimeSpan
Dim tsCar2 As TimeSpan
Dim MyNextCar As TimeSpan = StopwatchNextCar.Elapsed
Dim tStart As TimeSpan = stopwatchStartDelay.Elapsed
Dim tFinish As TimeSpan = stopwatchFinishDelay.Elapsed
Dim elapsedTimeCar1 As String
Dim elapsedTimeCar2 As String
Dim elapsedTimeNextCar As String
Dim elapsedTimeGap As String
Dim elapsedTimeStart As String
Dim elapsedTimeFinish As String
Dim Mypanelcount As Integer = 0
Dim xS As Integer = 0
Dim xF As Integer = 0
Dim MyTotalRuns As Integer = 0
Dim MyTriggerS As Boolean = False
Dim MyTriggerF As Boolean = False
Dim WaitingCarNumber As String = ""
Dim cn As SqlConnection
Dim cmd As SqlCommand
Private Sub AutoTiming_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintDocument1.PrinterSettings.PrinterName = "EPSON TM-T20 Log"
' TestConeect()
MyConnect()
Me.EntryListTableAdapter.FillByEventID(Me.ResultsDataSet1.EntryList, GetEventID)
Me.RunDataTableAdapter.Fill(Me.ResultsDataSet1.RunData)
cn = New SqlConnection(MySQLString)
Me.Slider1.Value = GetStartGap()
' Me.btnSwoopInputs.Image = Global.MotorSportResults_v1.My.Resources.RightRedArow2
Me.lblDelaySlider.Text = Slider1.Value.ToString
MyEventID = GetEventID()
MyLastRunUsed = GetLastRunID()
MyRunID = GetLastRunID()
Me.GridLookUpEdit1.EditValue = MyLastRunUsed
MyRedFromStartDelay = GetFromStarDelay()
'TODO: This line of code loads data into the 'MotorSportResulstsDataSet.RunData' table. You can move, or remove it, as needed.
Me.RunDataTableAdapter.Fill(Me.ResultsDataSet1.RunData)
Dim iRowCount As Integer = Me.ResultsDataSet1.RunData.Rows.Count
MyTotalRuns = iRowCount.ToString
Me.lblTotalRuns.Text = GetTotalRuns(GetEventID)
Me.lblVersion.Text = MyVersion
Me.GridLookUpEdit1.EditValue = MyLastRunUsed
Me.lblStartedToStop.Text = GetStartToStop()
Me.lblEventID.Text = GetEventID()
Me.lblEventName.Text = GetEventName(MyEventID)
' Me.PictureBoxInput1.Image = My.Resources.StartButton
' Me.PictureBoxInput4.Image = My.Resources.StopButton
MyStartBounceDelay = GetStartDelay()
MyFinishBounceDelay = GetFinishDelay()
Me.lblStartDelay.Text = MyStartBounceDelay & " Sec"
Me.lblFinishDelay.Text = MyFinishBounceDelay & " Sec"
' MyConnect()
ShowBeam()
ShowInputSetting()
' Me.btnSwoopInputs.Image = Global.MotorSportResults_v1.My.Resources.RightRedArow2
' ============================ On Screen Lights =======================================
Me.lblStop.BackColor = Color.Red
Me.lblReady.BackColor = Color.Transparent
Me.lblStarted.BackColor = Color.Transparent
Me.lblfinished.BackColor = Color.Transparent
' =====================================================================================
MyLoadIamge()
' PrtStartHearder(GetLastRunID)
GetStill2Run()
If GetUsePOSPrinter() = True Then
DoMyHeader()
End If
End Sub
Private Sub TestConeect()
MsgBox("This Is Just inside MyConnect ")
Dim CardAddress As Integer = 3
Dim h As Integer
h = OpenDevice(CardAddress)
Select Case h
Case 0
MsgBox("This 0 ")
Case 1
MsgBox("This 1 ")
Case 2
MsgBox("This 2 ")
Case 3
MsgBox("This is 3 Connected")
Case -1
MsgBox("This is NOT Connected")
End Select
End Sub
Private Sub MyConnect()
MsgBox("This Is Just inside MyConnect ")
Dim CardAddress As Integer = 3
Dim MyResult As String = ""
Dim h As Integer
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
MyResult = "Card Is connected"
Me.lblCard.BackColor = Color.LightGreen
Me.lblCard.ForeColor = Color.Black
ClearDigitalChannel(1) ' ready
ClearDigitalChannel(2) ' Started
ClearDigitalChannel(3) ' Finished
ClearDigitalChannel(4) ' stop
Me.TimerInputs.Enabled = True
Case -1
Me.lblCard.BackColor = Color.Yellow
Me.lblCard.ForeColor = Color.Red
MyResult = "Card was Not found"
Me.TimerInputs.Enabled = False
End Select
Me.lblCard.Text = MyResult
End Sub
I checked your code.
I didn’t get the code running if the MyConnect() call occurs outside a procedure.
Instead this seems to work fine: [size=85] Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MyConnect()
End Sub[/size]In other case I got error message “Declaration expected”.
Here is the whole code I tested:
[size=85][code]Public Class Form1
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Integer) As Integer
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function Version Lib “k8055d.dll” () As Integer
Private Declare Function SearchDevices Lib “k8055d.dll” () As Integer
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Integer) As Integer
Private Declare Function ReadAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib “k8055d.dll” (ByRef Data1 As Integer, ByRef Data2 As Integer)
Private Declare Sub OutputAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib “k8055d.dll” (ByVal Data1 As Integer, ByVal Data2 As Integer)
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib “k8055d.dll” ()
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()
Private Declare Sub SetAnalogChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Integer
Private Declare Function ReadCounter Lib “k8055d.dll” (ByVal CounterNr As Integer) As Integer
Private Declare Sub ResetCounter Lib “k8055d.dll” (ByVal CounterNr As Integer)
Private Declare Sub SetCounterDebounceTime Lib “k8055d.dll” (ByVal CounterNr As Integer, ByVal DebounceTime As Integer)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MyConnect()
End Sub
Private Sub MyConnect()
MsgBox("This Is Just inside MyConnect ")
Dim CardAddress As Integer = 3
Dim MyResult As String = ""
Dim h As Integer
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
MyResult = "Card Is connected"
Me.lblCard.BackColor = Color.LightGreen
Me.lblCard.ForeColor = Color.Black
ClearDigitalChannel(1) ' ready
ClearDigitalChannel(2) ' Started
ClearDigitalChannel(3) ' Finished
ClearDigitalChannel(4) ' stop
'Me.TimerInputs.Enabled = True
Case -1
Me.lblCard.BackColor = Color.Yellow
Me.lblCard.ForeColor = Color.Red
MyResult = "Card was Not found"
'Me.TimerInputs.Enabled = False
End Select
Me.lblCard.Text = MyResult
End Sub