Public Class Geigerzaehler01b
Private Declare Sub MessageBeep Lib "User32" (ByVal N As Integer)
Private Declare Function OPENCOM Lib "RSCOM" (ByVal OpenString$) As Integer
Private Declare Sub TIMEOUTS Lib "RSCOM" (ByVal b%)
Private Declare Sub BUFFERSIZE Lib "RSCOM" (ByVal b%)
Private Declare Sub CLOSECOM Lib "RSCOM" ()
Private Declare Sub SENDBYTE Lib "RSCOM" (ByVal Dat%)
Private Declare Function READBYTE Lib "RSCOM" () As Integer
Private Declare Sub SENDSTRING Lib "RSCOM" (ByVal Dat$)
Private Declare Function READSTRING Lib "RSCOM" () As String
Private Declare Sub CLEARBUFFER Lib "RSCOM" ()
Private Declare Function INBUFFER Lib "RSCOM" () As Integer
Private Declare Function OUTBUFFER Lib "RSCOM" () As Integer
Private Declare Sub DTR Lib "RSCOM" (ByVal b%)
Private Declare Sub RTS Lib "RSCOM" (ByVal b%)
Private Declare Sub TXD Lib "RSCOM" (ByVal b%)
Private Declare Function CTS Lib "RSCOM" () As Integer
Private Declare Function DSR Lib "RSCOM" () As Integer
Private Declare Function RI Lib "RSCOM" () As Integer
Private Declare Function DCD Lib "RSCOM" () As Integer
Private Declare Function INPUTS Lib "RSCOM" () As Integer
Private Declare Sub TIMEINIT Lib "RSCOM" ()
Private Declare Function TIMEREAD Lib "RSCOM" () As Double
Private Declare Sub DELAY Lib "RSCOM" (ByVal ms As Double)
Private Declare Sub REALTIME Lib "RSCOM" ()
Private Declare Sub NORMALTIME Lib "RSCOM" ()
Dim Zustand
Dim Clicks As Long
Dim CPM As Decimal
Dim Minute(59) As Long 'Wird automatisch mit Nullen initialisiert
Dim SecCount As Long
Dim CPM_select As Boolean
Dim CP_multiplier As Double
Dim GMZ As Integer
Dim GMZ_sensitivity(2) As Double
Private Sub Geigerzaehler01b_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim msg As String
Dim OpenString As String
Dim i As Integer
Dim IniFilename As String
Dim fileReader As System.IO.StreamReader
Dim stringReader As String
AddHandler Application.ApplicationExit, AddressOf OnApplicationExit
If PrevInstance() = True Then
msg = "Programm wurde bereits gestartet "
MessageBeep(0)
MsgBox(msg, 48)
End
End If
IniFilename = "G:\MSR\install\MSR.ini"
If My.Computer.FileSystem.FileExists(IniFilename) = False Then
TextBox1.Text = "1"
GoTo KeinIniFile
End If
fileReader = My.Computer.FileSystem.OpenTextFileReader(IniFilename)
stringReader = fileReader.ReadLine()
If stringReader = "[Franzis MSR COM]" Then
stringReader = fileReader.ReadLine()
TextBox1.Text = stringReader
Else
TextBox1.Text = "1"
End If
KeinIniFile:
OpenString = "COM" + TextBox1.Text + ":9600,N,8,1"
i = OPENCOM(OpenString)
If i = 0 Then
MessageBeep(0)
MsgBox("Schnittstelle nicht verfügbar")
End If
'Timer1.Enabled = False
Clicks = 0
CPM = 0.0
RTS(1)
Zustand = CTS
SecCount = 0
CPM_select = True
CP_multiplier = 60.0
GMZ = 0
GMZ_sensitivity = New Double() {7.5, 1.5, 999999999999999.87}
'GMZ_sensitivity(0) = 7.5
'GMZ_sensitivity(1) = 1.5
'GMZ_sensitivity(2) = 999999999999999.87
End Sub
Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
Timer1.Enabled = True
End Sub
Private Sub stopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopButton.Click
Timer1.Enabled = False
End Sub
Private Sub resetButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetButton.Click
Clicks = 0
CPM = 0.0
For count As Integer = 0 To 59
Minute(count) = 0
Next
clicksTextBox.Text = Str$(Clicks)
cpmTextBox.Text = (CPM * CP_multiplier / 60.0).ToString("F1")
SecCount = 0
End Sub
Private Sub opencomButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opencomButton.Click
Dim OpenString As String
Dim i As Integer
OpenString = "COM" + TextBox1.Text + ":9600,N,8,1"
i = OPENCOM(OpenString)
If i = 0 Then
MsgBox("Schnittstelle nicht verfügbar")
End If
RTS(1)
End Sub
Private Sub cpmRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cpmRadioButton.CheckedChanged
If cpmRadioButton.Checked = True Then
CPM_select = True
CP_multiplier = 60.0
cpmLabel.Text = "Clicks/min"
Else
CPM_select = False
CP_multiplier = 1.0
cpmLabel.Text = "Clicks/sec"
End If
End Sub
Private Sub cpsRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cpsRadioButton.CheckedChanged
If cpsRadioButton.Checked = True Then
CPM_select = False
CP_multiplier = 1.0
cpmLabel.Text = "Clicks/sec"
Else
CPM_select = True
CP_multiplier = 60.0
cpmLabel.Text = "Clicks/min"
End If
End Sub
Private Sub zp1320RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zp1320RadioButton.CheckedChanged
If zp1320RadioButton.Checked = True Then
GMZ = 0
ElseIf zp1310RadioButton.Checked = True Then
GMZ = 1
Else
GMZ = 2
End If
End Sub
Private Sub zp1310RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zp1310RadioButton.CheckedChanged
If zp1310RadioButton.Checked = True Then
GMZ = 1
ElseIf zp1320RadioButton.Checked = True Then
GMZ = 0
Else
GMZ = 2
End If
End Sub
Private Sub externRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles externRadioButton.CheckedChanged
If externRadioButton.Checked = True Then
GMZ = 2
ElseIf zp1320RadioButton.Checked = True Then
GMZ = 0
Else
GMZ = 1
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim alt
Dim Clicks_old As Long
alt = CTS()
REALTIME()
TIMEINIT()
While TIMEREAD < 1000
Zustand = CTS()
If Zustand > alt Then
Clicks = Clicks + 1
End If
alt = Zustand
End While
NORMALTIME()
SecCount = SecCount + 1
clicksTextBox.Text = Str$(Clicks)
If SecCount < 60 Then
For count As Integer = SecCount To 1 Step -1
Minute(count) = Minute(count - 1)
Next
Minute(0) = Clicks
cpmTextBox.Text = (Clicks / SecCount * CP_multiplier).ToString("F1") 'cpmTextBox.Text = Str$(Clicks / SecCount * 60)
dosageTextBox.Text = (Clicks * 10.0 / SecCount / GMZ_sensitivity(GMZ)).ToString("F3")
Else
Clicks_old = Minute(59)
For count As Integer = 59 To 1 Step -1
Minute(count) = Minute(count - 1)
Next
Minute(0) = Clicks
cpmTextBox.Text = ((Clicks - Clicks_old) * CP_multiplier / 60.0).ToString("F1")
dosageTextBox.Text = ((Clicks - Clicks_old) / 6.0 / GMZ_sensitivity(GMZ)).ToString("F3")
End If
End Sub
Private Sub OnApplicationExit(ByVal sender As System.Object, ByVal e As System.EventArgs)
' When the application is exiting, write the application data to the
' user file and close it.
Try
'Ignore any errors that might occur while closing the file handle.
'MsgBox("Closecom now executed", 48)
NORMALTIME()
CLOSECOM()
Catch
End Try
End Sub
'Visual Basic .NET: Ersatz für App.PrevInstance
Function PrevInstance() As Boolean
Dim procname As String
Dim count As Integer
procname = Diagnostics.Process.GetCurrentProcess.ProcessName
count = UBound(Diagnostics.Process.GetProcessesByName(procname))
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function
End Class