mscomm vb6 --> vs2005
I have a very simple vb6 program I want to convert to VS2005. MSComm is nolonger available and I don't understand how to receive data without the mscomm_OnComm() event.
Please advise.
Also, can this be implemented so that the code is exposed to MSAccess 2000 ? Ultimately I need to communicate to a piece of Lab equipment connected to the serial port using a production application written in MSAccess.
Thanks
*VB6 Code*Dim Buffer As String
Private Sub MSComm1_OnComm()
If Me.MSComm1.CommEvent = 2 Then
Buffer$ = Me.MSComm1.Input
Me.Text1.Text = Me.Text1.Text & Buffer$
End If
End Sub
Private Sub cmdSend_Click()
On Error GoTo errorHandler
If Me.MSComm1.PortOpen = True Then
Me.MSComm1.PortOpen = False
End If
Select Case Trim(Me.Combo1.Text)
Case "Com1", "Com2", "Com3", "Com4"
Me.MSComm1.CommPort = Right(Trim(Me.Combo1.Text), 1)
Case Else
Me.MSComm1.CommPort = Trim(Me.Combo1.Text)
End Select Me.MSComm1.Settings = Me.Combo3 + "," + Left(Trim(Me.Combo5.Text), 1) + "," + Trim(Me.Combo4.Text) + "," + Trim(Me.Combo6.Text)
Select Case Me.Combo7
Case "None"
Me.MSComm1.Handshaking = comNone
Case "Hardware"
Me.MSComm1.Handshaking = comRTS
Case Else
Me.MSComm1.Handshaking = comXOnXoff
End Select
Me.MSComm1.RThreshold = 1 ' Activates the OnComm event
Me.MSComm1.PortOpen = True
Me.MSComm1.Output = Chr(13)
Me.MSComm1.Output = Trim(Me.Combo2.Text) + Chr(13)
exitNormal:
On Error Resume Next
Exit Sub
errorHandler:
Buffer$ = CStr(Err.Number) + " " + Err.Description
If Me.MSComm1.PortOpen = True Then
Me.MSComm1.PortOpen = False
End If
Resume exitNormal
End Sub
Private Sub cmdReset_Click()
Text1.Text = ""
If Me.MSComm1.PortOpen = True Then
Me.MSComm1.PortOpen = False
End If
End Sub
Private Sub cmdEnd_Click()
End
End Sub
Private Sub Form_Load()
Combo1.AddItem "Com1"
Combo1.AddItem "Com2"
Combo2.AddItem "Calibrate"
Combo2.AddItem "Read"
Combo2.AddItem "Screen"
Combo2.AddItem "Version"
Combo2.AddItem "Ping"
Combo2.AddItem "Time"
Combo2.AddItem "Date"
Combo2.AddItem "Help"
Combo3.AddItem "115200"
Combo3.AddItem "38000"
Combo3.AddItem "19200"
Combo3.AddItem "9600"
Combo4.AddItem "8"
Combo4.AddItem "7"
Combo4.AddItem "67"
Combo4.AddItem "5"
Combo5.AddItem "Even"
Combo5.AddItem "Odd"
Combo5.AddItem "None"
Combo5.AddItem "Mark"
Combo5.AddItem "Space"
Combo6.AddItem "1"
Combo6.AddItem "1.5"
Combo6.AddItem "2"
Combo7.AddItem "Hardware"
Combo7.AddItem "Xon / Xoff"
Combo7.AddItem "None"
End Sub
Hello
I am interested in the follow up to this question:
"Also, can this be implemented so that the code is exposed to MSAccess 2000 ? Ultimately I need to communicate to a piece of Lab equipment connected to the serial port using a production application written in MSAccess."
I am currently working on an MSAccess 2000 database that communicates to a piece of Lab equipment using MSComm. I am currently using a timer on a form to poll the input buffer before reading and processing the output from the meter. I was able to set up a VB6 routine to use the OnComm event to collect data from this meter, but I cannot get the OnComm event to fire in MSAccess 2000. Could you offer any help with this? Thank you for your help!!
VB6 code that works:
Private Sub cmdTrigger_Click()
MSComm1.Output = "MEAS?" & vbCr
End Sub
Private Sub Form_Load()
Form1.Caption = "App1"
'set up port
With MSComm1
.CommPort = 1
.Handshaking = 0
.InputLen = 0
.RThreshold = 16
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
' Leave all other settings as default values.
'set up some meter settings
.Output = "REMS;OHMS;RANGE 4;TRIGGER 1" & vbCr
End With
Text1.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
'MsgBox "EVENTS? " & MSComm1.CommEvent
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
Text1.Text = MSComm1.Input
'MsgBox "got it"
End Select
End Sub
VBA Code that does not work:
This connects to the meter sets it up but the trigger command will trigger the meter causing it to send back a reading, but the OnComm events are never called.
Option Compare Database
Public MSComm1 As MSComm
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
Me!txtSystemStatus.Value = MSComm1.Input
MsgBox "got it"
End Select
End Sub
Private Sub ActiveXCtl7_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
Me!txtSystemStatus.Value = MSComm1.Input
MsgBox "got it"
End Select
End Sub
Private Sub Form_Open(Cancel As Integer)
Me!txtSystemStatus.Value = "Form Open"
Set MSComm1 = New MSComm
MSComm1.CommPort = 1
MSComm1.Handshaking = 0
MSComm1.InputLen = 0
MSComm1.RThreshold = 16
MSComm1.RTSEnable = True
MSComm1.Settings = "9600,n,8,1"
MSComm1.SThreshold = 1
MSComm1.PortOpen = True
MSComm1.Output = "REMS;OHMS;RANGE 4;TRIGGER 1" & vbCr
Me!txtSystemStatus.Value = "Meter Ready"
End Sub
Sub cmdTrigger_Click()
'sent the command to meter to take reading
MSComm1.Output = "MEAS?" & vbCr
End Sub