FILENAMES: DESCRIPTION: This Visual Basic program code to run a dividing head. Posted by Terry . The following description was provided: ================================================================= This is the source code for controlling a dividing head in VB. Sorry about the unconventional naming of the controls VERSION 5.00 Begin VB.Form Form1 Caption = "Dividing Head Stepper Control" ClientHeight = 5115 ClientLeft = 165 ClientTop = 735 ClientWidth = 5790 Icon = "DevHead.frx":0000 LinkTopic = "Form1" ScaleHeight = 5115 ScaleWidth = 5790 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command4 Caption = "&Emergency Stop" Height = 495 Left = 1680 TabIndex = 10 Top = 4560 Width = 2055 End Begin VB.CommandButton Command3 Caption = "&Zero Position" Height = 495 Left = 120 TabIndex = 9 Top = 4560 Width = 1215 End Begin VB.CommandButton Command1 Caption = "&Move" Height = 495 Left = 2280 TabIndex = 1 Top = 2760 Width = 1215 End Begin VB.TextBox Text1 Height = 495 Left = 2280 TabIndex = 0 Top = 2280 Width = 1215 End Begin VB.Timer Timer1 Interval = 6 Left = 120 Top = 3840 End Begin VB.CommandButton Command2 Caption = "E&xit" Height = 495 Left = 4080 TabIndex = 3 Top = 4560 Width = 1695 End Begin VB.Label Label7 Alignment = 2 'Center Caption = "HI-TORQUE MODE" Height = 375 Left = 2160 TabIndex = 11 Top = 0 Visible = 0 'False Width = 1215 End Begin VB.Label Label6 Alignment = 2 'Center Caption = "0" Height = 495 Left = 3240 TabIndex = 8 Top = 960 Width = 2535 End Begin VB.Label Label5 Alignment = 2 'Center Caption = "0" Height = 375 Left = 120 TabIndex = 7 Top = 960 Width = 2175 End Begin VB.Label Label4 Caption = "Degrees to move" Height = 495 Left = 2280 TabIndex = 6 Top = 2040 Width = 1215 End Begin VB.Label Label3 Alignment = 2 'Center Caption = "Degrees moved since last move " Height = 375 Left = 3240 TabIndex = 5 Top = 480 Width = 2535 End Begin VB.Label Label2 Caption = "Label2" Height = 15 Left = 1560 TabIndex = 4 Top = 1920 Width = 135 End Begin VB.Label Label1 Alignment = 2 'Center Caption = "Degrees moved since zero" Height = 375 Left = 240 TabIndex = 2 Top = 480 Width = 1935 End Begin VB.Menu mnuFile Caption = "&File" Begin VB.Menu mnuAbout Caption = "&About" End Begin VB.Menu mnuExit Caption = "E&xit" End End Begin VB.Menu munSettings Caption = "&Settings" Begin VB.Menu mnuPortAddress Caption = "&Port Address" Begin VB.Menu mnu956 Caption = "3BCH(&956)" End Begin VB.Menu mnu888 Caption = "378H(&888)" Checked = -1 'True End Begin VB.Menu mnu632 Caption = "278H(&632)" End End Begin VB.Menu mnuLine Caption = "-" End Begin VB.Menu mnuTorqueSettings Caption = "&Torque Settings" Begin VB.Menu mnuNormal Caption = "&Normal" Checked = -1 'True End Begin VB.Menu mnuHi Caption = "&Hi-Torque" End End End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Public gStepCount As Integer Public gStepNum As Integer Public gTemp6 As Integer Public gPort As Integer 'Declare public variable to hold port address Public gMode As Integer 'Declares a variable to hold the step mode,will be 1-normal or 2 Hi-torque Option Explicit Private Sub Command1_Click() If Text1.Text = "" Then MsgBox "You Did Not Enter A Number!", vbCritical, "" 'Reminds user to enter a number Text1.SetFocus Exit Sub End If If IsNumeric(Text1.Text) = False Then MsgBox "You Did Not Enter A Valid Number!", vbCritical, "Enter A Number .045 or Greater" 'Checks for valid # Text1.SetFocus Text1.Text = "" 'deletes invalid entry Exit Sub End If If Text1.Text < 0.045 Then MsgBox "You Did Not Enter A Valid Number!", vbCritical, "Enter A Number .045 or Greater" 'Checks for valid # Text1.SetFocus Text1.Text = "" 'deletes invalid entry Exit Sub End If MsgBox "Make Sure The Clamp Is Unlocked!", vbCritical, "Is The Clamp Locked?" 'A warning not to move deviding head while clamped down Text1.SetFocus gStepCount = gStepCount + CInt(Text1.Text / 0.045) 'Turns degrees into steps (1 step = .045 degrees) gTemp6 = 0 Label6.Caption = 0 End Sub Private Sub Command2_Click() vbOut gPort, 0 'Sends 0 to port swiching all off End 'exits program End Sub Private Sub Command3_Click() gStepCount = 0 gStepNum = 0 Label5.Caption = 0 Label6.Caption = 0 Text1.SetFocus End Sub Private Sub Command4_Click() gStepCount = 0 'Zero's out the variables gStepNum = 0 gTemp6 = 0 End Sub Private Sub Form_Load() gPort = 888 'Sets port address to 888 (default value) vbOut gPort, 1 'Sets the port value to 1 gStepCount = 0 'Zero's out the variables gStepNum = 0 gTemp6 = 0 gMode = 1 'Starts with normal mode End Sub Private Sub mnu632_Click() mnu888.Checked = False mnu956.Checked = False mnu632.Checked = True gPort = 632 'Sets port address to 632 End Sub Private Sub mnu888_Click() mnu888.Checked = True mnu956.Checked = False mnu632.Checked = False gPort = 888 'Sets port address to 888 End Sub Private Sub mnu956_Click() mnu888.Checked = False mnu956.Checked = True mnu632.Checked = False gPort = 956 'Sets port address to 956 End Sub Private Sub mnuAbout_Click() frmAboutDh.Show End Sub Private Sub mnuExit_Click() End End Sub Private Sub mnuHi_Click() mnuNormal.Checked = False mnuHi.Checked = True Label7.Visible = True 'Running in Hi Torque mode so lable is visible gMode = 2 'Sets mode to Hi-Torque End Sub Private Sub mnuNormal_Click() mnuNormal.Checked = True mnuHi.Checked = False Label7.Visible = False 'Running in normal mode so label is not visible gMode = 1 'Sets mode to normal End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) 'First this fools the computer into calling the enter key a null(so it won't beep at the user) 'Then performs the command1 click If KeyAscii = vbKeyReturn Then KeyAscii = 0 Command1_Click End If End Sub Private Sub Timer1_Timer() If gStepNum < gStepCount And gMode = 1 Then Step 'Checks the number off steps moved against 'the number to move, if it still needs to 'move it calls the procedure that steps next 'in sequence 1 phase at a time(I put in the timer to slow it down 'to a speed the motor can handle) If gStepNum < gStepCount And gMode = 2 Then StepHi 'Checks the number off steps moved against 'the number to move, if it still needs to 'move it calls the procedure that steps next 'in sequence 2 phase at a time(I put in the timer to slow it down 'to a speed the motor can handle) End Sub Public Sub Step() Dim PortState As Integer Dim Temp5 As Integer PortState = vbInp(gPort) 'This checks to see what number is being sent out parrellel port now Select Case PortState 'Sends the next binary number out the parrelell port Case 1 vbOut gPort, 2 Case 2 vbOut gPort, 4 Case 4 vbOut gPort, 8 Case Else vbOut gPort, 1 End Select gStepNum = gStepNum + 1 'Counts the number of steps gTemp6 = gTemp6 + 1 'Counts the number of steps since last moved Temp5 = gStepNum * 0.045 'Turns the number of steps into number of degrees and hold it in a temp variable Label5.Caption = CInt(Temp5) 'Rounds off the number of degrees moved since zero and displays Label6.Caption = CInt(gTemp6 * 0.045) 'Turns the number of steps since last moved to degrees, rounds off and displays End Sub Public Sub StepHi() Dim PortState As Integer Dim Temp5 As Integer PortState = vbInp(gPort) 'This checks to see what number is being sent out parrellel port now Select Case PortState 'Sends the next binary number out the parrelell port Case 3 vbOut gPort, 6 Case 6 vbOut gPort, 12 Case 12 vbOut gPort, 9 Case Else vbOut gPort, 3 End Select gStepNum = gStepNum + 1 'Counts the number of steps gTemp6 = gTemp6 + 1 'Counts the number of steps since last moved Temp5 = gStepNum * 0.045 'Turns the number of steps into number of degrees and hold it in a temp variable Label5.Caption = CInt(Temp5) 'Rounds off the number of degrees moved since zero and displays Label6.Caption = CInt(gTemp6 * 0.045) 'Turns the number of steps since last moved to degrees, rounds off and displays End Sub