Hi,
I am using MSComm32.ocx to develop a Call Accounting Software, which
communicate with Pbx via Serial port. MsComm is ActiveX, it is easy to use.
You can search document for MsComm from Microsoft or VC++ 6.0 CD.
' Declare some contanst
'Constant of Handshaking
Const comNone = 0 ' No handshaking.
Const comXonXoff = 1 ' XOn/XOff
handshaking.
Const comRTS = 2 '
Request-to-send/clear-to-send handshaking.
Const comRTSXOnXOff = 3 ' Both
request-to-send and XOn/XOff handshaking.
'Constant of OnComm
Const comEvSend = 1 ' Send event.
Const comEvReceive = 2 ' Receive event.
Const comEvCTS = 3 ' Change in
clear-to-send line.
Const comEvDSR = 4 ' Change in data-set
ready line.
Const comEvCD = 5 ' Change in carrier
detect line.
Const comEvRing = 6 ' Ring detect.
Const comEvEOF = 7 ' End of file.
Function to initialize a Com port like below. I don't copy the code to get
parameter into variables:
' Set which serial port will be used
Me.msComm.CommPort = 1 ' 1 is COM 1, 2 is COM 2...
'Set communication parameter for that port
strPortSetting = strBaudRate & "," & Mid(strParityBit, 1, 1) & "," _
& strByteSize & "," & strStopBits
Me.msComm.Settings = strPortSetting
' Tell the control to read 1 byte
Me.msComm.InputLen = 0
' Set InputMode
Me.msComm.InputMode = 0 ' 0 input as text, 1 input as binary
' Causes the MSComm control to generate the OnComm event every time a
single character is placed in the receive buffer.
Me.msComm.RThreshold = 1
' Set HandShaking
Select Case strFlowControl
Case "None"
Me.msComm.Handshaking = comNone
Case "Hardware"
Me.msComm.Handshaking = comRTS
Case "Xon/Xoff"
Me.msComm.Handshaking = comXonXoff
Case "Xon/Xoff + Hardware"
Me.msComm.Handshaking = comRTSXOnXOff
End Select
' Open the port.
Me.msComm.PortOpen = True
When data coming, OnComm procedure will be called. Write some code like this
inside OnComm event-procedure:
if (Me.msComm.CommEvent = comEvReceive) then
' Get data
debug.print Me.msComm.Input
end if
Regards
Quang