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 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()
-
-
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()
-
-
End Sub
1 870
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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....
|
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.
...
|
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...
|
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...
|
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 :)
| |
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
...
|
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:
|
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
|
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
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |