VERSION 5.00 Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX" Begin VB.Form frmDCMotorServer BackColor = &H00FF0000& Caption = "8255 DC Motor Server" ClientHeight = 2580 ClientLeft = 60 ClientTop = 345 ClientWidth = 5220 LinkTopic = "Form1" ScaleHeight = 2580 ScaleWidth = 5220 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdExit Caption = "Close Server" Height = 375 Left = 3600 TabIndex = 2 Top = 120 Width = 1215 End Begin VB.TextBox txtOutput Height = 1695 Left = 120 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 600 Width = 4695 End Begin MSWinsockLib.Winsock tcpServer Left = 1920 Top = 120 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End Begin VB.Label lblStatusWindow BackColor = &H00FF0000& Caption = "Status Window" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H0000FFFF& Height = 375 Left = 120 TabIndex = 1 Top = 240 Width = 1575 End End Attribute VB_Name = "frmDCMotorServer" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' FILE: LEDServer2_0 ' DATE: 08/22/04 ' AUTH: C.Yilmaz ' DESC: An 8255-controlled DC motor Control Sever 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 Private Sub cmdExit_Click() 'Bring the motor to 0 RPM speed Dummy = Out8255(PortA, 128) Form_Terminate End End Sub Private Sub Form_Load() ' Set up addresses for 8255 BaseAddress = 608 PortA = BaseAddress PortB = BaseAddress + 1 PortC = BaseAddress + 2 Cntrl = BaseAddress + 3 Dummy = Out8255(Cntrl, 128) ' 8255 Ports A, B and C as output ' Set up local port and wait for connection tcpServer.LocalPort = 5000 Call tcpServer.Listen End Sub Private Sub Form_Terminate() Call tcpServer.Close End Sub Private Sub tcpServer_Close() 'Bring the motor to 0 RPM speed Dummy = Out8255(PortA, 128) Call tcpServer.Close ' Client closed, server should too txtOutput.Text = txtOutput.Text & "Client closed connection." & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) Call tcpServer.Listen ' listen for next connection End Sub Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long) ' Ensure that tcpServer is closed ' before accepting a new connection If tcpServer.State <> sckClosed Then Call tcpServer.Close End If Call tcpServer.Accept(requestID) ' Accept connection ' Display following message on Server Status window txtOutput.Text = "Client from IP Address: " & _ tcpServer.RemoteHostIP & " is successful" & vbCrLf & _ "Port #: " & tcpServer.RemotePort & vbCrLf End Sub Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long) Dim messageFromClient As String ' The button Client clicked Dim RPM As Integer ' The numeric value entered by the user as the desired RPM of string Dim numericValue As Integer Call tcpServer.GetData(messageFromClient) ' Get Client's button click ' Convert Client's button click value to a numerica value RPM = Val(messageFromClient) ' Display which button client clicked in Server's Status window txtOutput.Text = txtOutput.Text & "Client entered" & messageFromClient & "RPM button" & vbCrLf txtOutput.SelStart = Len(txtOutput.Text) numericValue = (RPM - 15996) / 93.759 'rpm vs. digitalowrd calibration values between 3000 and 8000 runs well ' run the binary equivalent of client's button click on LEDs Dummy = Out8255(PortA, numericValue) ' Set acknowledgement message back to client Call tcpServer.SendData("The server has commanded " & numericValue & " RPM" + vbCrLf) 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 End Sub