'FILE: Motor Client 'DESC: Motor Client Controlling Motor Speed Option Explicit 'Declare variables Dim Number As Integer: ' decimal number to count from 1 to 255 Dim Start As Integer: ' Start flag Dim Msg As String Dim Style As Integer Dim Response As Integer Dim Volt As Double, Gain As Double Dim message As String Private Sub btnconnect_Click() Start = 1 - Start If Start = 1 Then btnconnect.Caption = "Running" Else btnconnect.Caption = "Connect" End If tcpClient.RemoteHost = txtIP.Text If tcpClient.RemoteHost = "" Then tcpClient.RemoteHost = "localhost" End If tcpClient.RemotePort = 5000 ' server port Call tcpClient.Connect ' connect to RemoteHost address End Sub Private Sub btnEnd_Click() Beep End End Sub Private Sub Form_Load() txtIP.Text = "129.25.18.130" ' Net connection ' Set up local port and wait for connection Start = 0: Number = 0: hsbspeed.Max = 255 hsbspeed.Min = 128 hsbspeed.Value = 128 End Sub Private Sub Form_Terminate() Call tcpServer.Close End Sub Sub pause(ByVal nSecond As Single) Dim t0 As Single t0 = Timer Do While Timer - t0 < nSecond Dim dummy As Integer dummy = DoEvents() ' if we cross midnight, back up one day If Timer < t0 Then t0 = t0 - CLng(24) * CLng(60) * CLng(60) End If Loop End Sub Private Sub tcpClient_Close() Call tcpClient.Close End Sub Private Sub tcpClient_Connect() txttransfer.Text = "Connected to IP address: " + tcpClient.RemoteHostIP hsbspeed.Value = 128 End Sub 'Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long) 'Call tcpClient.GetData(message) ' get data from server 'hsbspeed.Value = Val(message) 'txttransfer.Text = " Server sent motor speed : " + message 'Number = Val(txtInputWindow.Text) 'dummy = Out8255(PortSelected, Number) 'Gain = 0.039 'Volt = Number * Gain - 128 * Gain 'axPanel1.Text = Str(Volt) 'End Sub Private Sub tcpClient_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) ' If the client fails to connect to server, then this code executes Dim result As Integer result = MsgBox(Source & ": " & Description & vbCrLf & "Doh! Can't connect to server!", _ vbOKOnly, "TCP/IP Error") ' Source variable is the control (winsock in this case) causing the error ' Description variable cites the error message ' vbOKOnly is the control button ' TCP/IP Error is the MsgBox caption End End Sub Private Sub hsbspeed_Change() txtInputWindow.Text = Str(hsbspeed.Value) Number = hsbspeed.Value Gain = 0.039 Volt = Number * Gain - 128 * Gain axPanel1.Text = Str(Volt) If Start <> 0 Then Call tcpClient.SendData(Str(Number)) txttransfer.Text = "Send motor speed to Server : " + Str(Number) End If End Sub