Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm problem

Status
Not open for further replies.

PatrickIRL

Programmer
Jun 25, 2003
383
I've done extensive research on this but I'm still stumped. I'm using the mscomm control to try to receive data from the serial port, albeit with no luck.

Originally I was using a weighing scales (Hampel) but couldn't get that to work so now I'm using a serial mouse I bought yesterday. Thing is, I've downloaded various OCXs and DLLs and can get them to work fine but when I try to do the same from VB, nada, zip. It seems like the OnComm event is never triggered. What the h**l am I doing wrong??

Thanks in advance, Patrick

Code:
Option Explicit

Private Sub cmdExit_Click()
    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
    End If
    
    Unload Me
End Sub

Private Sub cmdPortClose_Click()
    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
    End If
End Sub

Private Sub cmdPortOpen_Click()
    Dim lPort   As Long
    '''''''''''''''''''''''''''''''''
    On Error GoTo errPort
    '''''''''''''''''''''''''''''''''
    If txtPort.Text <> "" Then
        lPort = CLng(txtPort.Text)
    Else
        lPort = 1
    End If
    '''''''''''''''''''''''''''''''''
    If MSComm1.PortOpen = True Then
        MSComm1.PortOpen = False
    End If
    '''''''''''''''''''''''''''''''''
    With MSComm1
        If .PortOpen = False Then
            .CommPort = lPort
            .Settings = "9600,n,8,1"
            .RThreshold = 1
            .PortOpen = True
        End If
    End With
    
    Exit Sub
    
errPort:
    MsgBox Err.Description
    txtPort.Text = ""
    txtPort.SetFocus
End Sub

Private Sub MSComm1_OnComm()
    Dim sBuffer
    
    sBuffer = sBuffer & MSComm1.Input
    
    Text1.Text = Text1.Text & sBuffer
End Sub
 
I suggest that you get yourself a 'null modem cable'. Hopefully, your computer will have 2 serial ports. If not, purchase an I/O card that will provide you with another serial port.

Having a setup like this will allow you to test your code a lot easier. You would use the null modem cable to connect the 2 serial ports together. You can use HyperTerminal to test your app. You configure hyperterminal to use one of your serial ports. Your app is connect to the other. Then you can test sending and receiving data.

Here are a cuople of links. I've never purchased from either company, and I'm not endorsing them in any way. I provided the link to illustrate the type of hardware I am suggesting. Good Luck.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for the info George.

I knew it couldn't be that hard to do, apparently the scales that I was using needed a dedicated crossover cable, once I put that together it worked like a charm.

Thanks for the input anyway, appreciate it.

Patrick
 
Hy
you say:

" It seems like the OnComm event is never triggered"


Try this:

MSComm1.RThreshold=1


or, in last resort:

me.MSComm1.RTSEnable=true
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top