473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.

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. tClient.ReceiveBufferSize = (256)
  16. tClient.ReceiveTimeout = 3000
  17. tClient.SendTimeout = 1000
  18. 'Create a TcpClient. 
  19. tClient.Connect(IP_Address, Port_Number)
  20.  
  21. ' Get a client stream for reading and writing.
  22. stream = tClient.GetStream()
  23.  
  24. 'get the information from the device
  25. i_Read_Device_xmitB()
  26.  
  27. 'Delete the recordstore and close the connection to the field device
  28. i_delete_recordstore()
  29. i_Close_Connection()
  30.  
  31. End Sub
  32.  
  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()
  60.  
  61. End Sub
Feb 12 '07 #1
1 865
Killer42
8,435 Expert 8TB
I'd suggest a quick search of TheScripts (see search box at top right) for the Sleep API call. It has been discussed at least once or twice, and allows you to wait for a specified number of milliseconds without tying up the cpu.
Feb 13 '07 #2

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

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
7
by: arajunk | last post by:
I was looking around for some code for a special purpose and found this. Seems it should print "here we go" , pause 5 seconds, print "now we are back". Instead, it pauses 5 seconds before...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
8
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a...
3
by: markclinn | last post by:
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...
10
by: Robert Dailey | last post by:
Hi, I'm trying to create a Python equivalent of the C++ "ifstream" class, with slight behavior changes. Basically, I want to have a "filestream" object that will allow you to overload the...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
5
by: Nitin Mahajan | last post by:
Guys Is there a way in C# to create a word object directly from a memory stream without passing that to hard disk (file stream). I think it doesn't makes sense to create a file just to read it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.