Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Data input trough a COM port

2 views
Skip to first unread message

Hertsen Eric

unread,
Mar 25, 1997, 3:00:00 AM3/25/97
to

I'm trying to figure out how to read serial data from a com port and
display it in Excel.

Any help would be appreciated.

Thanks.

Maelstrom

unread,
Mar 26, 1997, 3:00:00 AM3/26/97
to

You could do it a number of ways. Either write the code in VB / C /
Delphi or similar and put it in Excel via DDE, or write it into an Excel
macro. It's quite a fiddly process to do it in Excel.

You need to put the following in, to declare the DCB data type and the
WinAPI comms functions. Note that this is using Windows 3.x.

'*********************************************
'* LIBRARY FUNCTIONS *
'*********************************************

Declare Function opencomm Lib "USER" (ByVal LPCOMNAME$, ByVal WINQUEUE%,
ByVal woutqueue%) As Integer
Declare Function closecomm Lib "USER" (ByVal NCID%) As Integer
Declare Function readcomm Lib "USER" (ByVal NCID%, ByVal lpbuf$, ByVal
nsize%) As Integer
Declare Function buildcommdcb Lib "USER" (ByVal LPSZDEF$, WDCB As
tagDCB) As Integer
Declare Function setcommstate Lib "USER" (WDCB As tagDCB) As Integer
Declare Function getcommerror Lib "USER" (ByVal NCID%, LPSTAT As
tagCOMSTAT) As Integer

'*********************************************
'* TYPE DECLARATIONS *
'*********************************************

Type tagDCB
id As Integer
baudrate As Long
bytesize As Integer
parity As Integer
stopbits As Integer
rlstimeout As Long
ctstimeout As Long
dsrtimeout As Long
fbinary As Long
frtsdisable As Long
fparity As Long
outxctsflow As Long
foutxdsrflow As Long
fdummy As Long
fdtrdisable As Long
foutx As Long
finx As Long
fpechar As Long
fnull As Long
fchevt As Long
fdtrflow As Long
ftrsflow As Long
fdummy2 As Long
xonchar As Integer
xoffchar As Integer
xonlim As Long
xofflim As Long
pechar As Integer
eofchar As Integer
evtchar As Integer
txdelay As Long
End Type ' tagDCB

Type tagCOMSTAT
status As Integer
cbinq As Integer
cboutq As Integer
End Type ' tagCOMSTAT


The essential usage of the functions is:


To close an open com port:

Function close_port() As Integer
close_port = closecomm(Port_Num)
End Function ' close_port


To open a com port:

Sub open_port()
Dim dcbstr As String
outstr$ = "com2" + Chr(0)
Port_Num = opencomm(outstr$, 1024, 128)
Debug.Print Port_Num
dcbstr = "com2:1200,n,8,1" & Chr$(0) '<--- change to your protocol
Debug.Print buildcommdcb(dcbstr, mydcb)
Debug.Print setcommstate(mydcb)
End Sub ' open_port

'*********************************************
'* READ COMM PORT *
'*********************************************
Function read_port() As String

Dim outstr$
Dim port_str$
Dim qcl%

port_str$ = Space$(100)
outstr$ = ""
qcl% = 0

Do
qerr% = readcomm(Port_Num, port_str$, 1)
...
loop
End Function

This will read one character at a time from the com port. What you do
with the characters is then up to you.

HTH

--
Maelstrom

0 new messages