Resumen Puertos serie

Option Explicit
Declare Function WriteFile& Lib "kernel32" _
        (ByVal hFile As Long, lpBuffer As Any, _
        ByVal nNumberOfBytesToWrite&, _
        lpNumberOfBytesWritten&, ByVal lpOverlapped&)
Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA" _
        (ByVal lpFileName$, ByVal dwDesiredAccess&, _
        ByVal dwShareMode&, ByVal lpSecurityAttributes&, _
        ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, _
        ByVal hTemplateFile&)
Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&)
Declare Function FlushFileBuffers& Lib "kernel32" (ByVal hFile&)


Function OCD(Mensaje As String, CommPort As String) As Boolean
Dim bModemCommand(256) As Byte
Dim OpenPort As Long
Dim RetVal As Long, RetBytes As Long, i As Integer

OCD = False
OpenPort = CreateFile(CommPort, &HC0000000, 0, 0, 3, 0, 0)
If OpenPort = -1 Then
   MsgBox "Error al abrir el puerto " & CommPort
   Exit Function
End If
For i = 0 To Len(Mensaje) - 1
   bModemCommand(i) = Asc(Mid(Mensaje, i + 1, 1))
Next
RetVal = WriteFile(OpenPort, bModemCommand(0), Len(Mensaje), RetBytes, 0)
If RetVal = 0 Then
   MsgBox "Error al escribir en " & CommPort
Else
   RetVal = FlushFileBuffers(OpenPort)
   OCD = True
End If
RetVal = CloseHandle(OpenPort)
End Function



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com