VERSION 5.00
Begin VB.Form frm940Demo 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "AC Technology SS940 communication Demo"
   ClientHeight    =   8880
   ClientLeft      =   150
   ClientTop       =   720
   ClientWidth     =   9885
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8880
   ScaleWidth      =   9885
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   495
      Left            =   8520
      TabIndex        =   21
      Top             =   7920
      Width           =   975
   End
   Begin VB.Frame TestFrame 
      Caption         =   "Communication tests"
      Height          =   3855
      Left            =   720
      TabIndex        =   20
      Top             =   4680
      Width           =   7095
      Begin VB.CommandButton Command1 
         Caption         =   "Segmented moves >>"
         Height          =   735
         Left            =   2880
         TabIndex        =   25
         Top             =   1680
         Visible         =   0   'False
         Width           =   2055
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Inputs/Outputs >>"
         Height          =   735
         Left            =   360
         TabIndex        =   24
         Top             =   2760
         Visible         =   0   'False
         Width           =   2055
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Trapezoidal moves >>"
         Height          =   735
         Left            =   360
         TabIndex        =   23
         Top             =   1680
         Width           =   2055
      End
      Begin VB.CommandButton CmdVars 
         Caption         =   "Variables read/write >>"
         Height          =   735
         Left            =   360
         TabIndex        =   22
         Top             =   600
         Width           =   2055
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "SS940 Connection"
      Height          =   4095
      Left            =   720
      TabIndex        =   0
      Top             =   480
      Width           =   7095
      Begin VB.OptionButton IFselect 
         Caption         =   "Serial (232/485)"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   19
         Top             =   2280
         Width           =   1455
      End
      Begin VB.CommandButton IPsetCmd 
         Caption         =   "Accept"
         Height          =   375
         Left            =   2880
         TabIndex        =   18
         Top             =   3480
         Width           =   1455
      End
      Begin VB.Frame Frame1 
         Caption         =   "IP properties"
         Height          =   1695
         Left            =   1800
         TabIndex        =   9
         Top             =   240
         Width           =   4455
         Begin VB.TextBox ipadr 
            Height          =   285
            Index           =   0
            Left            =   1560
            TabIndex        =   15
            Text            =   "192"
            Top             =   480
            Width           =   495
         End
         Begin VB.TextBox ipadr 
            Height          =   285
            Index           =   1
            Left            =   2160
            TabIndex        =   14
            Text            =   "168"
            Top             =   480
            Width           =   495
         End
         Begin VB.TextBox ipadr 
            Height          =   285
            Index           =   2
            Left            =   2760
            TabIndex        =   13
            Text            =   "124"
            Top             =   480
            Width           =   495
         End
         Begin VB.TextBox ipadr 
            Height          =   285
            Index           =   3
            Left            =   3360
            TabIndex        =   12
            Text            =   "124"
            Top             =   480
            Width           =   495
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Left            =   1560
            TabIndex        =   11
            Top             =   1080
            Width           =   1575
         End
         Begin VB.CommandButton FindByNameCmd 
            Caption         =   "Find"
            Height          =   375
            Left            =   3240
            TabIndex        =   10
            Top             =   1080
            Width           =   615
         End
         Begin VB.Label Label1 
            Caption         =   "IP address"
            Height          =   255
            Left            =   360
            TabIndex        =   17
            Top             =   480
            Width           =   1095
         End
         Begin VB.Label Label4 
            Caption         =   "Drive's name"
            Height          =   255
            Left            =   360
            TabIndex        =   16
            Top             =   1080
            Width           =   1095
         End
      End
      Begin VB.OptionButton IFselect 
         Caption         =   "Ethernet"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   8
         Top             =   360
         Value           =   -1  'True
         Width           =   975
      End
      Begin VB.Frame Frame2 
         Caption         =   "Serial properties"
         Height          =   1215
         Left            =   1800
         TabIndex        =   1
         Top             =   2160
         Width           =   4455
         Begin VB.TextBox DriveSerialID 
            Height          =   285
            Left            =   2280
            TabIndex        =   4
            Text            =   "0"
            Top             =   840
            Width           =   375
         End
         Begin VB.TextBox COMtxt 
            Height          =   285
            Left            =   1800
            TabIndex        =   3
            Text            =   "1"
            Top             =   360
            Width           =   375
         End
         Begin VB.ListBox BaudList 
            Height          =   255
            Left            =   3360
            TabIndex        =   2
            Top             =   360
            Width           =   855
         End
         Begin VB.Label Label2 
            Caption         =   "Drive number (0-31)"
            Height          =   255
            Left            =   240
            TabIndex        =   7
            Top             =   840
            Width           =   1575
         End
         Begin VB.Label Label3 
            Caption         =   "Computer COM port"
            Height          =   255
            Left            =   240
            TabIndex        =   6
            Top             =   360
            Width           =   1575
         End
         Begin VB.Label Label5 
            Caption         =   "Baud Rate"
            Height          =   255
            Left            =   2520
            TabIndex        =   5
            Top             =   360
            Width           =   855
         End
      End
   End
   Begin VB.Menu mnuExit 
      Caption         =   "Exit"
   End
End
Attribute VB_Name = "frm940Demo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdExit_Click()
 mnuExit_Click    'close interface and end program
End Sub


Private Sub CmdVars_Click()
If Connected Then
    Load frmVars
    frmVars.Show 1          'show modal
Else
    SelectInterfaceWarning
End If
End Sub

Private Sub Command2_Click()
If Connected Then
    Load frmMove
    frmMove.Show 1          'show modal
Else
    SelectInterfaceWarning
End If
End Sub

Private Sub Form_Load()
'Populate listbox with some serial port speed choices

BaudList.AddItem ("38400")
BaudList.AddItem ("115200")

End Sub



Private Sub Form_Terminate()
 If Connected Then
    SS940_CloseInterface (SHANDLE)
    SS940_CloseInterface (SHANDLE2)
 End If
End Sub

Private Sub Frame4_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub IPsetCmd_Click()
Dim I As Integer
Connected = False
If IFselect(0).Value Then
'--------------------------------------------------------------------------------------------
'Below is an example how to open IP port for coneection to the Ethernet using 940control.dll
'drive will be opened for connection over Ethernet...
'--------------------------------------------------------------------------------------------
    For I = 0 To 3
        ip(I) = Val(ipadr(I))
    Next
 'Use DLL function to open Ethernet interface
    SHANDLE = SS940_OpenInterfaceB(ip(0), 3000)
    SHANDLE2 = SS940_OpenInterfaceB(ip(0), 3000)        'Open second handle to use it in the other thread
                                                        'to read the status concurently
    If Not SHANDLE > 0 Then
        MsgBox "Failure to open communication channel", vbCritical + vbOKOnly, "Interface error"
        Exit Sub
    End If
Else

'drive will be opened for connection over Serial port
'if ( SS940_EnableSerialInterface( 1, 115200 ) != EC_OK )
'        { printf( "Failed to open COM port 1\r\n" ); exit( 0 ); }

        'udph = SS940_OpenInterfaceB( ip_serial, 3000 );
        'if ( !udph ) { printf( "Failed to open interface. IP configuration problems\r\n" ); exit( 0 ); }
    If Not (SS940_EnableSerialInterface(Val(COMtxt.Text), Val(BaudList.Text))) Then
         MsgBox "Faild to open COM port", vbCritical + vbOKOnly, Error
         Exit Sub
    End If
 'Form IP adress to use with serial port.First three bytes are fixed
 'but last byte represents drive ID number on RS485/232 network.
    ip_serial(0) = 127
    ip_serial(1) = 0
    ip_serial(2) = 0
    ip_serial(3) = Val(DriveSerialID.Text)
    
    SHANDLE = SS940_OpenInterfaceB(ip_serial(0), 3000)
    If Not SHANDLE Then
       MsgBox "Failure to open communication channel", vbCritical + vbOKOnly, "Interface error"
       Exit Sub
    End If
End If
frm940Demo.Caption = frm940Demo.Caption + "[Connected]"
Connected = True

End Sub


Private Sub mnuExit_Click()
 Unload frm940Demo  'this will call Form_Terminate where interface is closed if it was opened.
End Sub

Private Sub SelectInterfaceWarning()
 MsgBox "Please select interface first", vbExclamation + vbOKOnly, "Warning"
End Sub
