473,614 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a pause in stream.read?

7 New Member
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 870
Killer42
8,435 Recognized Expert Expert
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
14325
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? Basically: "Press any key to continue..." I beleive that I am looking for is something along the lines of a....
7
4536
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 printing both lines with no pause between. Can someone please explain why it behaves that way. I know in the case of "setTimeout" the only thing affected is the function, etc. appearing as "setTimeout" arguments. But, this is just straight code. ...
5
3050
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 outer loop and the first StreamReader is still where I left it. I have been trying to do this using this code: StreamReader sr2 = sr1 //Where sr1 is the existing StreamReader This seems to work just fine, so I guess this is a supported way...
23
7394
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
8
2225
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 small example to do it? thx a lot men :)
3
1358
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 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. Public Class Form1 ...
10
3321
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 '<<' and '>>' operators to stream out and stream in data, respectively. So far this is what I have: class filestream:
4
6901
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 function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
5
6860
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 again in to word object. If some one has some brilliant idea please share. In a nutshell this is what I'm currently doing ByteArray --File Stream --Word Object and this I want to do
0
8198
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8294
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5549
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.