Read/write a Serial Port

  • Thread starter Thread starter Wal
  • Start date Start date
W

Wal

Is it possible to use VBA read and write to a serial port
for use in/from Excel?
Where can I look at sample code to learn how it is done?
 
Hi Wal,
Not directly but you can use API functions:
API Function: Description:

CreateFile() opens a specific communications port.

SetCommState() sets the state of the serial port in question (baud rate,
parity, stop bits etc.)

GetCommState() retrieves the state of the serial port in question (baud
rate, parity, stop bits etc.)

ReadFile() reads data from a port. Can be specified to return
immediately or wait for incoming data.

WriteFile() writes data to the serial port.



MP
 
Thanks MP, but I don't understand what you mean.

Could you please explain a bit more simply or tell me
where I could read up on how to do this. I can't find any
help in VBA about the functions you suggest.

If it can't be done directly in VAB do I need to write and
run code outside Excel's VBA?

I have read serial port data on an Apple II computer many
years ago so I know a tiny bit, but I don't where to start
with VBA for use in or with Excel.
 
Hi Wal,
You can use specific component MSCOMM32.OCX:
1. Open Excel
2. Open Visual Basic Editor
3. RightClick somewhere on Project tree (usually on the left) -> Insert ->
UserForm
4. From the menu - Tools -> References -> Microsoft Com Control 6.0
(MSCOMM32.OCX) - or click browse and point the file.
5. RightClick somewhere on Project tree (usually on the left) -> Insert ->
Module
6. write sub or func that declare variable from type MSCommLib.MSComm.

Regards,
MP

"Wal" <[email protected]> a écrit dans le message de
Thanks MP, but I don't understand what you mean.

Could you please explain a bit more simply or tell me
where I could read up on how to do this. I can't find any
help in VBA about the functions you suggest.

If it can't be done directly in VAB do I need to write and
run code outside Excel's VBA?

I have read serial port data on an Apple II computer many
years ago so I know a tiny bit, but I don't where to start
with VBA for use in or with Excel.
 
Excel does not come with the MSComm ActiveX control- it is provided
with Visual Studio 6. If you have it on your system but do not have
Visual Studio 6 installed, it also will not work because you do not
have a license to use it.

The easiest way to get serial data into an Excel spreadsheet would be
to use a 3rd party tool like WinWedge from TALtech.
WinWedge is an executable program that runs in the background and
feeds serial data directly to other programs either by stuffing the
keyboard buffer or by passing the data to other programs using Dynamic
Data Exchange (DDE). It also supports sending data out a serial port
as well.
For more information about WinWedge please visit:
http://www.taltech.com/products/winwedge.html
 
Another option is to use the ActiveX control CheapComm. You can
download the installer at:

http://ourworld.compuserve.com/homepages/jacksilver/software.htm

I've put it on Excel 2000 and it seems to work OK so far, but I'm
still struggling with deciphering the code from the GPS download sheet
that is also available at the above site to make it work for my
application.

If any of the groups gurus have any insights or sample code, any
feedback would be appreciated.
 
Back
Top