I have a device in the field that I access by the stream method.
I open the Stream and do the following:
1. stream.write a character to the device.
2. stream.read the information from the device.
The problem is that when I am debugging and step through the code there is a long enough pause that I recieve the entire string. If I just run it, I only get the 1st character. I have attached the code below.
I open the Stream and do the following:
1. stream.write a character to the device.
2. stream.read the information from the device.
The problem is that when I am debugging and step through the code there is a long enough pause that I recieve the entire string. If I just run it, I only get the 1st character. I have attached the code below.
Code:
Public Class Form1 Inherits System.Windows.Forms.Form 'Setup up a new socket Public tClient As New System.Net.Sockets.TcpClient() ' Get a client stream for reading and writing. Public stream As NetworkStream Public str_Output_message As String Public IP_Address As String = xxx.xxx.xxx.xxx Public Port_Number As Integer = xxxxx Public Sub i_Comm_Initilization() tClient.ReceiveBufferSize = (256) tClient.ReceiveTimeout = 3000 tClient.SendTimeout = 1000 'Create a TcpClient. tClient.Connect(IP_Address, Port_Number) ' Get a client stream for reading and writing. stream = tClient.GetStream() 'get the information from the device i_Read_Device_xmitB() 'Delete the recordstore and close the connection to the field device i_delete_recordstore() i_Close_Connection() End Sub Public Sub i_Read_Device_xmitB() 'Set the Output message str_Output_message = "b" Dim byt_receive_buffer(tClient.ReceiveBufferSize) As Byte ' Translate the message to be transmitted into ASCII and store it as a Byte array. byt_array_data = Encoding.ASCII.GetBytes(str_Output_message) str_returndata = "" If stream.CanWrite And stream.CanRead Then ' Do a simple write. ' Send the message to the connected TcpServer. stream.Write(byt_array_data, 0, byt_array_data.Length) stream.Read(bytes, 0, CInt(tClient.ReceiveBufferSize)) ' Output the data received from the host to the console. str_returndata = Encoding.ASCII.GetString(bytes) stream.Write(byt_array_data, 0, byt_array_data.Length) 'Call the Data Breakout Routine i_Data_Breakout() End Sub
Comment