Hi to all,
I have vb script for accessing instruments (by using of ip address and port number of instrument).when i trying connect the instrument using of window based application it gives error message 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".
Any one help me how to solve this error please...
my vb script is
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 "
ublic Sub New()
MyBase.New()
InitializeComponent()
End Sub
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
Private 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()
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"
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
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$
IpAddress = "192.168.1.250"
PortNum = 10000
Client = New TcpClient
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
TxCommand = "01ff000a4420000000000500"
Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray)
Client.GetStream().Write(Buffer, 0, Buffer.Length)
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
Temp = ""
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
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
Client.GetStream().Close()
Client.Close()
End Sub
End Class
[Edit]Code block added[/Edit]