'FILE: Final Project 'DESC: Controlling a DC Motor through the Server Option Explicit 'Declare use of the DLL Private Declare Function Out8255 Lib "8255.dll" (ByVal PortAddress As Integer, ByVal PortData As Integer) As Integer Private Declare Function In8255 Lib "8255.dll" (ByVal PortAddress As Integer) As Integer 'Declare variables Dim BaseAddress As Integer: ' 8255 Base Address Dim dummy As Integer: ' Dummy variable used with DLL Dim PortA As Integer: ' 8255 Port A address Dim PortB As Integer: ' 8255 Port B address Dim PortC As Integer: ' 8255 Port C address Dim Cntrl As Integer: ' 8255 Control Address 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 PortSelected As Integer Dim Volt As Double, Gain As Double Dim a Private Sub btnEnd_Click() Beep dummy = Out8255(PortA, 0) dummy = Out8255(PortB, 0) dummy = Out8255(PortC, 0) End End Sub Private Sub Form_Load() ' Set up local port and wait for connection tcpServer.LocalPort = 5000 Call tcpServer.Listen txttransfer.Text = " Waiting for connection !!" & vbCrLf txt8255.Text = Str(608) BaseAddress = Val(txt8255.Text) PortA = BaseAddress PortB = BaseAddress + 1 PortC = BaseAddress + 2 Cntrl = BaseAddress + 3 dummy = Out8255(Cntrl, 128) Start = 0 dummy = Out8255(PortA, 0) dummy = Out8255(PortB, 0) dummy = Out8255(PortC, 0) Number = 0: optPortA.Value = True txtInputWindow.Text = "128" End Sub Private Sub Form_Terminate() Call tcpServer.Close End Sub Private Sub tcpServer_Close() Call tcpServer.Close ' client closed, server should too End Sub Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long) If tcpServer.State <> sckClosed Then Call tcpServer.Close End If Call tcpServer.Accept(requestID) ' Accept connection ' Display following message on Server Status window txttransfer.Text = "Client from IP Address: " & _ tcpServer.RemoteHostIP & " is successful" & vbCrLf & _ "Port #: " & tcpServer.RemotePort & vbCrLf Start = 1: btnGo.Caption = "Running" If optPortA.Value = True Then PortSelected = PortA Print PortSelected End If If optPortB.Value = True Then PortSelected = PortB Print PortSelected End If If optPortC.Value = True Then PortSelected = PortC Print PortSelected End If End Sub Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long) Dim message As String Call tcpServer.GetData(message) ' get data from client Number = Val(message) dummy = Out8255(PortSelected, Number) Gain = 0.039 Volt = Number * Gain - 128 * Gain axPanel1.Text = Str(Volt) txttransfer.Text = "Send motor speed to Client : " + Str(Number) txtInputWindow.Text = Number txttransfer.Text = "Client requested motor speed :" + Str(Number) End Sub Private Sub tcpServer_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) Dim result As Integer result = MsgBox(Source & ": " & Description, _ vbOKOnly, "TCP/IP Error") End Sub