Create a pause in stream.read?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markclinn
    New Member
    • Feb 2007
    • 7

    #1

    Create a pause in stream.read?

    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.

    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()
    
            '****************Should these be set by the Database?****************
            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()
    Last edited by markclinn; Feb 12 '07, 06:14 PM. Reason: update
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Might be better to post this in the VB forum.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by RedSon
      Might be better to post this in the VB forum.
      Someone must have moved it. Where was it originally?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Originally posted by Killer42
        Someone must have moved it. Where was it originally?
        Where else? c/c++

        Comment

        Working...