Question
In Visual Basic/VB.net, I am sending a command to another device. The command is :POWER? This command asks for the power reading on the device.
In Visual Basic/VB.net, I am sending a command to another device. The command is ":POWER?" This command asks for the power reading on the device. I am wondering, how can I get the reading for POWER displayed in a textbox in my GUI? I am able to perform the task in the windows command prompt, but I need to do this in the visual studio environment.
Imports System.Net.Sockets Imports System.Threading Imports System.IO Public Class Form1 Dim Listener As New TcpListener(23) 'telnet port number Dim Client As New TcpClient Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim ListThread As New Thread(New ThreadStart(AddressOf Listening)) ListThread.Start() End Sub Private Sub Listening() Listener.Start() 'open communication End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Client = New TcpClient("IP", Port) Dim Writer As New StreamWriter(Client.GetStream()) Writer.Write(":POWER?") Writer.Flush()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Listener.Stop() 'close communication End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started