Microsoft comm controls

N

NDBC

I am trying to open com1 in vb and get data from a tag reader as the tags are
read. I have started with this

Private Sub Worksheet_Activate()

' Open the serial port
MSComm1.CommPort = 1
MSComm1.Settings = "115200,N,8,1"
MSComm1.PortOpen = True

but it is giving me an error straight up. Do I need to download anything for
the MSComm1 commands to work. I realise I would need to put in loops etc for
it to continually monitor the port but I can't even get it to open the port
yet.

Thanks
 
P

Peter T

I don't know much about MSComm but looks like that should open your com-1,
silly question but do you actually have Com-1 available, try some others.

Someone from this ng sent me this to test a long time ago: with MSComm1 and
a couple of commandbuttons on the sheet -

Private Sub CommandButton1_Click()

' Sets/returns the baud rate, parity, data bit, and stop bit parameters.

MSComm1.CommPort = 4 ' start with comm port
MSComm1.Settings = "57600,N,8,1" ' 57600 baud, no parity, 8 data,
and 1 stop bit.
MSComm1.InputMode = comInputModeBinary ' BINARY MODE
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.EOFEnable = False ' No end of file character
MSComm1.Handshaking = comNone
MSComm1.InputLen = 0 ' read FIFO until empty
MSComm1.RThreshold = 1 ' # of chars to receive before
generates the OnComm event
MSComm1.InBufferSize = 8192 ' 1024 is default

On Error GoTo Errorhandler

MSComm1.PortOpen = True
On Error GoTo 0
MsgBox "MSComm1.PortOpen " & MSComm1.PortOpen
Exit Sub
Errorhandler:
MsgBox "Bad settings", vbOKOnly, "Comm Port Error"
End Sub

Private Sub CommandButton2_Click()
If MSComm1.PortOpen Then
MSComm1.PortOpen = False
End If
MsgBox "MSComm1.PortOpen " & MSComm1.PortOpen
End Sub

The original code included
MSComm1.CommPort = 6
which failed for me because I didn't have 6, but 4 was good for me

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top