Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2010, 08:43 AM
Registered User
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation How to open and close ports with mscomm

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 /





Similar Threads
Thread Thread Starter Forum Replies Last Post
Open/Close Multiple Forms dzisaacs C# 2 August 20th, 2006 05:25 PM
I can open a new window but can't close it camelius ASP.NET 2.0 Basics 0 March 16th, 2006 06:26 AM
Open and close windows skicrud Javascript How-To 1 August 17th, 2004 04:03 PM
open close db mikeuk PHP Databases 3 July 19th, 2004 11:58 AM
Open/Close SQL Connection within every method? flyin ADO.NET 8 May 18th, 2004 07:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.