Public Sub Open(ByVal iPort As Int16, ByVal ioSpeed As Integer, ByVal ioData As Int16, ByVal ioParity As Int16, _
ByVal iostop As Int16, ByVal comBufferSize As Integer)
Dim uDCB As DCB
Dim iResult As Int32
hCOMM = CreateFile("COM" & iPort.ToString, &H80000000 Or &H40000000, 0, 0, 3, 0, 0)
Try
If hCOMM <> -1 Then
Dim sCOMSettings As String
iResult = ClearCommError(hCOMM, iErrCode, 0&) ' Fehler löschen
iResult = PurgeComm(hCOMM, PurgeBuffers.RXClear Or PurgeBuffers.TxClear)
'Buffer löschen
iResult = GetCommState(hCOMM, uDCB) 'Setting von COM`?
' Port Settings
sCOMSettings = ioSpeed & "," & ioParity & "," & ioData.ToString & "," & CInt(iostop).ToString
iResult = BuildCommDCB(sCOMSettings, uDCB)
iResult = SetCommState(hCOMM, uDCB)
iResult = SetupComm(hCOMM, comBufferSize, comBufferSize) 'Buffer setzen
comSetTimeout(100) 'Timeout Struktur sezen
Else
MessageBox.Show("Schnittstelle zum Kassendisplay ließ sich nicht öffnen!", "Fehler beim Öffnen!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch Ex As Exception
Errorhandling(sFehlerLogPfad, Ex, "Fehler beim Öffnen der Schnittstelle")
End Try
End Sub
<DllImport("kernel32.dll")> Private Shared Function SetCommState(ByVal hCommDev As Int32, ByRef lpDCB As DCB) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function GetCommState(ByVal hCommDev As Int32, ByRef lpDCB As DCB) As Int32
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> Private Shared Function BuildCommDCB(<MarshalAs(UnmanagedType.LPStr)> ByVal lpDef As String, ByRef lpDCB As DCB) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function SetupComm(ByVal hFile As Int32, ByVal dwInQueue As Int32, ByVal dwOutQueue As Int32) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function SetCommTimeouts(ByVal hFile As Int32, ByRef lpCommTimeouts As COMMTIMEOUTS) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function GetCommTimeouts(ByVal hFile As Int32, ByRef lpCommTimeouts As COMMTIMEOUTS) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function ClearCommError(ByVal hFile As Int32, ByVal lpErrors As Int32, ByVal l As Int32) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function PurgeComm(ByVal hFile As Int32, ByVal dwFlags As Int32) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function EscapeCommFunction(ByVal hFile As Integer, ByVal ifunc As Long) As Boolean
End Function
<DllImport("kernel32.dll")> Private Shared Function WaitCommEvent(ByVal hFile As Integer, ByRef Mask As Integer, ByRef lpOverlap As System.Threading.Overlapped) As Int32
End Function
<DllImport("kernel32.dll")> Private Shared Function CreateFile(<MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer
End Function