VERSION 5.00 Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX" Begin VB.Form Form1 Caption = "Send Alpha Protocol over Ethernet" ClientHeight = 1455 ClientLeft = 60 ClientTop = 345 ClientWidth = 3630 LinkTopic = "Form1" ScaleHeight = 1455 ScaleWidth = 3630 StartUpPosition = 3 'Windows Default Begin VB.Timer Timer1 Enabled = 0 'False Left = 1680 Top = 840 End Begin VB.CommandButton cmdClear Caption = "Clear Sign" Height = 375 Left = 2520 TabIndex = 2 Top = 360 Width = 975 End Begin VB.CommandButton cmdSend Caption = "Send" Height = 375 Left = 1320 TabIndex = 1 Top = 360 Width = 975 End Begin VB.CommandButton cmdConnect Caption = "Connect" Height = 375 Left = 120 TabIndex = 0 Top = 360 Width = 975 End Begin MSWinsockLib.Winsock Winsock1 Left = 2280 Top = 840 _ExtentX = 741 _ExtentY = 741 _Version = 393216 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim TIMER_FLAG As Boolean Dim SOCKETERROR As Boolean 'Define a flag that is set if there is a socket error Private Sub cmdClear_Click() Dim DataString As String 'Define string that contains the data to send DataString = Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) 'Nulls for Autobauding DataString = DataString & Chr$(1) & "Z00" & Chr$(2) 'Packet header - All Signs, All Addresses DataString = DataString & "E$" & Chr$(4) 'Clear Memory Winsock1.SendData (DataString) 'Send data End Sub Private Sub cmdConnect_Click() If cmdConnect.Caption = "Connect" Then 'It connected to the socket SOCKETERROR = False 'Set socket error flag to false Winsock1.Connect 'Connect to IP Address and Port Timer1.Enabled = True 'Start the Connection Timeout timer Do While Winsock1.State <> sckConnected And SOCKETERROR = False 'Wait for it to connect or timeout DoEvents Loop If Winsock1.State = sckConnected Then 'It connected so enable the Send and Clear buttons cmdSend.Enabled = True 'Enable the Send button cmdClear.Enabled = True 'Enable the Clear button cmdConnect.Caption = "Disconnect" 'Change the caption of the connect button Else Winsock1.Close 'Disconnect from IP Address and Port Exit Sub End If Else 'It didn't connect to the socket Winsock1.Close 'Disconnect from IP Address and Port cmdSend.Enabled = False 'Disable the Send button cmdClear.Enabled = False 'Disable the Clear button cmdConnect.Caption = "Connect" 'Change the caption of the connect button End If End Sub Private Sub cmdSend_Click() Dim DataString As String 'Define string that contains the data to send DataString = Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) 'Nulls for Autobauding DataString = DataString & Chr$(1) & "Z00" & Chr$(2) 'Packet header - All Signs, All Addresses DataString = DataString & "E$AAU0100FF00" & Chr$(4) 'Config table for 1 text file Winsock1.SendData (DataString) 'Send data DataString = Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) 'Nulls for Autobauding DataString = DataString & Chr$(1) & "Z00" & Chr$(2) 'Packet header - All Signs, All Addresses DataString = DataString & "A" 'Write text file command DataString = DataString & "A" 'Text file label "A" DataString = DataString & Chr$(27) 'ESC character DataString = DataString & " " 'Position code - middle DataString = DataString & "a" 'Mode - rotate DataString = DataString & Chr$(28) 'Color code DataString = DataString & "1" 'Color = red DataString = DataString & "This is a test over the Ethernet" 'This is the text to be displayed DataString = DataString & Chr$(4) 'EOT character Winsock1.SendData (DataString) 'Send data End Sub Private Sub Form_Load() cmdSend.Enabled = False 'Disable the Send button cmdClear.Enabled = False 'Disable the Clear button Timer1.Interval = 10000 'Set Connection Timeout to 10 seconds Timer1.Enabled = False 'Disable Connection Timeout timer Winsock1.RemoteHost = "207.67.12.251" 'Set the IP Address to connect to Winsock1.RemotePort = "3001" 'Set the TCP Port to connect to - Use 3001 for Lantronix MSS1, MSS100, MSS485, and Alpha Ethernet Adatpers SOCKETERROR = False 'Set socket error flag to false End Sub Private Sub Form_Unload(Cancel As Integer) If Winsock1.State <> 0 Then Winsock1.Close 'Disconnect from IP Address and Port End If Unload Me 'Unload this program End Sub Private Sub Timer1_Timer() Dim iRetval As Integer 'Define an integer to hold the return value from the message box Timer1.Enabled = False 'Stop the Connection Timeout timer If Winsock1.State = sckError Then 'There was an error connecting to the socket iRetval = MsgBox("Error connecting to IP Address and/or Port", vbCritical + vbOKOnly, "Socket Error") SOCKETERROR = True 'Set socket error flag to true End If If Winsock1.State = sckConnecting Then 'It timed out while trying to connect iRetval = MsgBox("Timeout occurred while attempting to connect to IP Address and/or Port", vbCritical + vbOKOnly, "Connection Timeout") SOCKETERROR = True 'Set socket error flag to true End If End Sub