By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,226 Members | 1,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,226 IT Pros & Developers. It's quick & easy.

Create a pause in stream.read?

P: 7
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.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4.     'Setup up a new socket
  5.     Public tClient As New System.Net.Sockets.TcpClient()
  6.  
  7.     ' Get a client stream for reading and writing.
  8.     Public stream As NetworkStream
  9.     Public str_Output_message As String
  10.     Public IP_Address As String = xxx.xxx.xxx.xxx
  11.     Public Port_Number As Integer = xxxxx
  12.  
  13.     Public Sub i_Comm_Initilization()
  14.  
  15.         '****************Should these be set by the Database?****************
  16.         tClient.ReceiveBufferSize = (256)
  17.         tClient.ReceiveTimeout = 3000
  18.         tClient.SendTimeout = 1000
  19.         'Create a TcpClient. 
  20.         tClient.Connect(IP_Address, Port_Number)
  21.  
  22.         ' Get a client stream for reading and writing.
  23.         stream = tClient.GetStream()
  24.  
  25.         'get the information from the device
  26.         i_Read_Device_xmitB()
  27.  
  28.         'Delete the recordstore and close the connection to the field device
  29.         i_delete_recordstore()
  30.         i_Close_Connection()
  31.  
  32.     End Sub
  33.     Public Sub i_Read_Device_xmitB()
  34.  
  35.         'Set the Output message
  36.         str_Output_message = "b"
  37.  
  38.         Dim byt_receive_buffer(tClient.ReceiveBufferSize) As Byte
  39.  
  40.         ' Translate the message to be transmitted into ASCII and store it as a Byte array.
  41.         byt_array_data = Encoding.ASCII.GetBytes(str_Output_message)
  42.  
  43.         str_returndata = ""
  44.  
  45.         If stream.CanWrite And stream.CanRead Then
  46.  
  47.             ' Do a simple write.
  48.             ' Send the message to the connected TcpServer. 
  49.             stream.Write(byt_array_data, 0, byt_array_data.Length)
  50.  
  51.             stream.Read(bytes, 0, CInt(tClient.ReceiveBufferSize))
  52.  
  53.             ' Output the data received from the host to the console.
  54.             str_returndata = Encoding.ASCII.GetString(bytes)
  55.  
  56.             stream.Write(byt_array_data, 0, byt_array_data.Length)
  57.  
  58.             'Call the Data Breakout Routine
  59.             i_Data_Breakout()
Feb 12 '07 #1
Share this Question
Share on Google+
3 Replies


RedSon
Expert 5K+
P: 5,000
Might be better to post this in the VB forum.
Feb 12 '07 #2

Expert 5K+
P: 8,434
Might be better to post this in the VB forum.
Someone must have moved it. Where was it originally?
Feb 13 '07 #3

RedSon
Expert 5K+
P: 5,000
Someone must have moved it. Where was it originally?
Where else? c/c++
Feb 13 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.