473,614 Members | 2,487 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.         '****************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
3 1358
RedSon
5,000 Recognized Expert Expert
Might be better to post this in the VB forum.
Feb 12 '07 #2
Killer42
8,435 Recognized Expert Expert
Might be better to post this in the VB forum.
Someone must have moved it. Where was it originally?
Feb 13 '07 #3
RedSon
5,000 Recognized Expert Expert
Someone must have moved it. Where was it originally?
Where else? c/c++
Feb 13 '07 #4

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. ...
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 :)
1
870
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 Inherits...
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
8642
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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
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...
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.