Jump to content

Recommended Posts

Posted
Hello All, I have FX-3U-ENET-ADP Ethernet module connected to FX3U PLC. I have followed the ENET ADP document and i am trying to execute the sample VB code provided in the document. I get the error as "Connection with the server failed the following code was returned:No connection could be made because the target machine actively refused it:192.168.1.250:10000" Can someone please help me if any specific steps need to be followed or any setting which i am missing. Below is the VB code: Option Explicit On Option Strict On Imports System.Net.Sockets Public Class Form 1 Inherits System.Windows.Forms.Form #Region " Windows Code created by Form Designer " Public Sub New() MyBase.New() ' This call is necessary for Windows Form Designer. InitializeComponent() ' InitializeComponent() Initialization is added after the call. End Sub ' The Form overwrites dispose to execute post-processing in the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Necessary for Windows Form Designer. Private components As System.ComponentModel.IContainer 'Memo: The following procedure is necessary for Windows Form Designer. 'Change by using Windows Form Designer. 'Do not use code editor to change. 'Friend WithEvents components As System.ComponentModel.IContainer Friend WithEvents Start As System.Windows.Forms.Button Friend WithEvents lstOutput As System.Windows.Forms.ListBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Start() = New System.Windows.Forms.Button Me.lstOutput = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'Start ' Me.Start.Location = New System.Drawing.Point(16, 16) Me.Start.Name = "Start" Me.Start.Size = New System.Drawing.Size(88, 32) Me.Start.TabIndex = 0 Me.Start.Text = "Start" 'lstOutput ' Me.lstOutput.ItemHeight = 12 Me.lstOutput.Location = New System.Drawing.Point(16, 64) Me.lstOutput.Name = "lstOutput" Me.lstOutput.Size = New System.Drawing.Size(264, 196) Me.lstOutput.TabIndex = 1 ' 'Form 1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(296, 273) Me.Controls.Add(Me.lstOutput) Me.Controls.Add(Me.Start) Me.Name = "Form 1" Me.Text = "Form 1" Me.ResumeLayout(False) End Sub #End Region Private Sub Start_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click Dim IpAddress As String Dim PortNum As Integer Dim Client As TcpClient Dim Buffer() As Byte Dim InBuff(1532) As Byte Dim TxCommand As String Dim RxResponse As String Dim Temp As String Dim j As Integer Dim Dreg(5) As Double Dim DregStr$ Dim SubHeader$ ' IP Address specification IpAddress = "192.168.1.250" ' Port Number specification PortNum = 10000 Client = New TcpClient 'Line connection processing Try Client.Connect(IpAddress, PortNum) Catch ex As Exception MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error") Exit Sub End Try 'Read D0 to D4 (5 points) with the A-compatible 1E frame command. TxCommand = "01ff000a4420000000000500" Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray) 'Sending a read command Client.GetStream().Write(Buffer, 0, Buffer.Length) 'Waiting for a response from an Ethernet adapter While Not Client.GetStream().DataAvailable() Application.DoEvents() End While If Client.GetStream().DataAvailable() Then Client.GetStream().Read(InBuff, 0, InBuff.Length) RxResponse = System.Text.Encoding.Default.GetString(InBuff) SubHeader = Mid$(RxResponse, 3, 2) If SubHeader = "00" Then 'Normal response Temp = "" 'Initialization of an output character string For j = 0 To 4 DregStr$ = Mid(RxResponse, j * 4 + 5, 4) Dreg(j) = Val("&H" + DregStr$) Temp = Temp + Format(Dreg(j), "#####0") + " " Next lstOutput.Items.Insert(lstOutput.Items.Count, Temp) ElseIf SubHeader = "5B" Then ' In an abnormal response, an abnormal code is added. Temp = "Terminate Code = " & SubHeader & " Error Code = " & Mid$(RxResponse, 5, 2) lstOutput.Items.Insert(lstOutput.Items.Count, Temp) Else Temp = "Terminate Code = " & SubHeader lstOutput.Items.Insert(lstOutput.Items.Count, Temp) End If lstOutput.SelectedIndex = lstOutput.Items.Count - 1 End If ' Line disconnection processing Client.GetStream().Close() Client.Close() End Sub End Class

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...