Serial Port..
-
I currently have a project regarding com port and i am new to serial port function. Is there anyone with example regarding this area??
-
I currently have a project regarding com port and i am new to serial port function. Is there anyone with example regarding this area??
Start a project in VB, and add the component: MScomm Control. Copy the icon of a telephone onto a form, then write some code to enable the COM port like:
MSComm1.Settings = "9600,n,8,1"
MSComm1.ParityReplace = ""
On Error GoTo COMerr
MSComm1.PortOpen = True
Exit sub
COMerr:
msgbox "A COM error occured:" & err.number & vbcrlf & err.description
End SubTo send data out the COM port use: MSComm1.Output = "This text string will go out the COM port." To trap received data on the serial port, you must add this to the MScomm1.OnComm event:
dim TCin as string
if MSComm1.CommEvent = MSCOMM_EV_RECEIVE then
TCin = MSComm1.Input
msgbox Received: " & TCin
end ifYou should also include these in a declarations file:
'--- MSComm event constants
Global Const MSCOMM_EV_SEND = 1
Global Const MSCOMM_EV_RECEIVE = 2
Global Const MSCOMM_EV_CTS = 3
Global Const MSCOMM_EV_DSR = 4
Global Const MSCOMM_EV_CD = 5
Global Const MSCOMM_EV_RING = 6
Global Const MSCOMM_EV_EOF = 7'--- MSComm error code constants
Global Const MSCOMM_ER_BREAK = 1001
Global Const MSCOMM_ER_CTSTO = 1002
Global Const MSCOMM_ER_DSRTO = 1003
Global Const MSCOMM_ER_FRAME = 1004
Global Const MSCOMM_ER_OVERRUN = 1006
Global Const MSCOMM_ER_CDTO = 1007
Global Const MSCOMM_ER_RXOVER = 1008
Global Const MSCOMM_ER_RXPARITY = 1009
Global Const MSCOMM_ER_TXFULL = 1010