Reading and Writing to a Com Port

theberry

The Berry
Local time
Today, 18:29
Joined
Jun 17, 2008
Messages
7
:oI posted a previous thread about trapping events from an external keypad, but the Keypad company half solved my problem by mapping the USB keypad to a com port. However, now I need to learn to do communication with a com port.

I found the following code for that:

Private Declare Function WriteFile& Lib "kernel32" _
(ByVal hFile As Long, lpBuffer As Any, _
ByVal nNumberOfBytesToWrite&, _
lpNumberOfBytesWritten&, ByVal lpOverlapped&)

Private Declare Function ReadFile& Lib "kernel32" _
(ByVal hFile As Long, lpBuffer As Any, _
ByVal nNumberOfBytesToRead&, _
lpNumberOfBytesRead&, ByVal lpOverlapped&)

Private Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName$, ByVal dwDesiredAccess&, _
ByVal dwShareMode&, ByVal lpSecurityAttributes&, _
ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, _
ByVal hTemplateFile&)

Private Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&)

Private Declare Function FlushFileBuffers& Lib "kernel32" (ByVal hFile&)

The problem is that when I try to read from the pad, the whole Access program freezes and waits for a byte to come in. Is there any way to generate an event when a byte is ready to read? Right now I poll the keypad every 100ms using the form timer, but it freezes.

I've been told I need an asynchronus read, but how do I do that?

Thanks in advance.
An old fogie rapidly advancing toward geezerhood.
 
I am trying another function in the kernel32.dll - ReadFileEx. I'll keep you posted.
The Comm1 statement in VB does not work in Access and the slowdown is not due to repeated use. If I just try to read one byte from the keypad the program will stop and wait for input.:(
 
Problem may be solved. I wrote a program in VB5 that does the port control and creates a text file of what was input. It uses the Comm1 control. The Access will then read that file. In fact it works so well I am going to try to do the same thing in Access. If we have trouble with Commctl32.ocx or Commctl32.dll not being present on machines that do not have VB we can copy them on with the software.

Thanks for the help. I'll probably be seeing you again.

The Old Fogie - rapid advancing toward Geezerhood:D
 

Users who are viewing this thread

Back
Top Bottom