VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Communicate / Retreive data from the communication port

by Arun Sharma (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 18th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Communicate / Retreive data from the communication port

Rate Communicate / Retreive data from the communication port




' Send a command to the port to retrieve data
    MSComm1.Output = Chr$(5) & vbCrLf

End Sub

Private Sub Form_Load()

' Set the port number
    
    MSComm1.CommPort = 1

' Other settings

    MSComm1.Settings = "2400,e,7,1"
    MSComm1.InBufferSize = 1024
    MSComm1.OutBufferSize = 512
    MSComm1.RThreshold = 15
    MSComm1.SThreshold = 1
    MSComm1.InputLen = 15
    MSComm1.ParityReplace = "?"
    MSComm1.RTSEnable = True
    MSComm1.DTREnable = True
    MSComm1.NullDiscard = False
    MSComm1.Handshaking = comNone

' Open the port    

    MSComm1.PortOpen = True

End Sub

Private Sub Form_Unload(Cancel As Integer)

' Close the port on form unload

    MSComm1.PortOpen = False

End Sub

Private Sub MSComm1_OnComm()

' variable to store fetched data

    Static strData As String

    With MSComm1
        Select Case .CommEvent
            Case comEventBreak
                MsgBox "Error", "1comEventBreak"
            Case comEventFrame
                MsgBox "Error", "1comEventFrame"
            Case comEventOverrun
                MsgBox "Error", "1comEventOverrun"
            Case comEventRxOver
                MsgBox "Error", "1comEventRxOver"
            Case comEventRxParity
                MsgBox "Error", "1comEventRxParity"
            Case comEventTxFull
                MsgBox "Error", "1comEventTxFull"
            Case comEventDCB
                MsgBox "Error", "1comEventDCB"
            Case comEvReceive

                ' store fetched data in the variable
                strData = strData & MSComm1.Input

                ' reinitialze strData for next fetch
                strData = ""
        End Select
    End With
    
End Sub

Download this snippet    Add to My Saved Code

Communicate / Retreive data from the communication port Comments

No comments have been posted about Communicate / Retreive data from the communication port. Why not be the first to post a comment about Communicate / Retreive data from the communication port.

Post your comment

Subject:
Message:
0/1000 characters