I need to open and close different ports using mscomm.
When I look at examples of mscomm it looks very complicated.
Is there a simple way to do this?
This is what I have so far but it still dosn't work right:
/Private Sub Load_Program_Click()
'If Motor1 = True Then Port = 7
'If Motor2 = True Then Port = 2
Port = 7
On Error Resume Next
'Stop
' clear ports and close previous comm ports
For increment = 0 To 7
If (mComm(increment)) Then
If (Comm.PortOpen) Then
Comm.PortOpen = False
End If
End If
mComm(increment) = False
Next increment
Comm.CommPort = Port
Comm.PortOpen = True
If (Err) Then
MsgBox Error
Err = 0
Else
mComm(Port) = True
End If
On Error GoTo 0
Text2 = ""
'CP$ = "CP" & Chr$(13): Comm.Output = CP$ 'Clear Program
Call Delay1
PG$ = "PG 1" & Chr$(13): Comm.Output = PG$ 'enter program mode
Call Delay
MS$ = "MS=512" & Chr$(13): Comm.Output = MS$ 'Set microstep resolution
Call Delay
EE$ = "Ee=1" & Chr$(13): Comm.Output = EE$ 'Enable Encoder
Call Delay
VI$ = "VI=500" & Chr$(13): Comm.Output = VI$ 'Set Initial Velocity at 500
Call Delay
VM$ = "VM=5000" & Chr$(13): Comm.Output = VM$ 'Set Maximum Velocity at 5,000
Call Delay
A$ = "A=1000" & Chr$(13): Comm.Output = A$ 'Set Acceleration at 1,000
Call Delay
MRneg$ = "MR -20000" & Chr$(13): Comm.Output = MRneg$ 'Move Rel -20,000
Call Delay
Text2 = "Moving Relative -20,000"
PR$ = "
PR" & " Moving Relative -20,000" & Chr$(13): Comm.Output =
PR$
Call Delay1
H$ = "H" & Chr$(13): Comm.Output = H$ 'Hold while motion is in progress
Call Delay
H$ = "H 1000" & Chr$(13): Comm.Output = H$ 'Hold for 1 sec
Call Delay
MRpos$ = "MR 20000" & Chr$(13): Comm.Output = MRpos$ 'Move Rel 20,000
Call Delay
Text2 = "Moving Relative +20,000"
H$ = "H" & Chr$(13): Comm.Output = H$ 'Hold while motion is in progress
Call Delay
H$ = "H 1000" & Chr$(13): Comm.Output = H$ 'Hold for 1 sec
Call Delay
MRneg$ = "MR -20000" & Chr$(13): Comm.Output = MRneg$ 'Move Rel -20,000
Call Delay
Text2 = "Moving Relative -20,000"
H$ = "H" & Chr$(13): Comm.Output = H$ 'Hold while motion is in progress
Call Delay
H$ = "H 1000" & Chr$(13): Comm.Output = H$ 'Hold for 1 sec
Call Delay
MRpos$ = "MR 20000" & Chr$(13): Comm.Output = MRpos$ 'Move Rel 20,000
Call Delay
Text2 = "Moving Relative +20,000"
H$ = "H" & Chr$(13): Comm.Output = H$ 'Hold while motion is in progress
Call Delay
H$ = "H 1000" & Chr$(13): Comm.Output = H$ 'Hold for 1 sec
Call Delay
PG$ = "PG" & Chr$(13): Comm.Output = PG$ 'exit program mode
Call Delay
End Sub /