Hello all,
I have a strange problem with the .NET serialPort class.
When I write some data to the serialport, not all the data is
immediately send: every once in a while, only ~50 characters of the 64
characters I'm sending gets send.
Then, when I do a write() again, the data gets send. This is
unacceptable behavior for my program.
With only a console version, the problem occurs once every 100 times.
But with a UI with some events, this rate goes up to ~10%.
Are there any explanations for this?
The console-code:
static internal SerialPort Serial;
static void Main(string[] args)
{
Console.WriteLi ne("Welcome to this testapplication !");
Serial = new SerialPort("COM 4");
Serial.BaudRate = 9600;
Serial.Handshak e = Handshake.Reque stToSend;
Serial.Parity = Parity.None;
Serial.StopBits = StopBits.One;
//Serial.RtsEnabl e = true;
Serial.Encoding = System.Text.Enc oding.Default;
Serial.DataBits = 8;
Serial.NewLine = "\r";
Serial.Received BytesThreshold = 20;
Serial.Open();
byte[] values = new byte[256];
for (int j = 0; j < values.Length; j++)
{
values[j] = Convert.ToByte( j);
}
while (true)
{
for (int i = 0; i <= 192; i += 64)
{
send(values, i, 64);
Thread.Sleep(75 0);
Console.WriteLi ne("Another 64 bytes send..");
}
Console.WriteLi ne("----256 bytes send..");
Thread.Sleep(10 00);
}
}
static internal int send(byte[] p, int o, int c)
{
if ((o + c) p.Length)
{
c = p.Length - o;
}
try
{
Serial.Write(p, o, c);
}
catch (Exception e)
{
Console.WriteLi ne(e.Message);
}
return c;
}
}
The equipment I'm writing to uses CTS/RTS handshaking..
Kind Regards,
Arjan 3 10560
On Sep 18, 11:10 am, arjan...@gmail. com wrote:
Hello all,
I have a strange problem with the .NET serialPort class.
When I write some data to the serialport, not all the data is
immediately send: every once in a while, only ~50 characters of the 64
characters I'm sending gets send.
Then, when I do a write() again, the data gets send. This is
unacceptable behavior for my program.
With only a console version, the problem occurs once every 100 times.
But with a UI with some events, this rate goes up to ~10%.
Did you try Serial.BaseStre am.Flush() (don't know if it will work,
just a suggestion).
On Sep 18, 8:56 pm, Doug Semler <dougsem...@gma il.comwrote:
On Sep 18, 11:10 am, arjan...@gmail. com wrote:
Hello all,
I have a strange problem with the .NET serialPort class.
When I write some data to the serialport, not all the data is
immediately send: every once in a while, only ~50 characters of the 64
characters I'm sending gets send.
Then, when I do a write() again, the data gets send. This is
unacceptable behavior for my program.
With only a console version, the problem occurs once every 100 times.
But with a UI with some events, this rate goes up to ~10%.
Did you try Serial.BaseStre am.Flush() (don't know if it will work,
just a suggestion).
Calling the Flush() function has the same effect as calling
writeLine(""): it'll transmit the buffers, most of the time..
Still, both ways are a work around for a problem that shouldn't be
there in the first place. Or do I have too high expections of serial
communication?
On Sep 19, 9:13 am, arjan...@gmail. com wrote:
On Sep 18, 8:56 pm, Doug Semler <dougsem...@gma il.comwrote:
On Sep 18, 11:10 am, arjan...@gmail. com wrote:
Hello all,
I have a strange problem with the .NET serialPort class.
When I write some data to the serialport, not all the data is
immediately send: every once in a while, only ~50 characters of the 64
characters I'm sending gets send.
Then, when I do a write() again, the data gets send. This is
unacceptable behavior for my program.
With only a console version, the problem occurs once every 100 times.
But with a UI with some events, this rate goes up to ~10%.
Did you try Serial.BaseStre am.Flush() (don't know if it will work,
just a suggestion).
Calling the Flush() function has the same effect as calling
writeLine(""): it'll transmit the buffers, most of the time..
Still, both ways are a work around for a problem that shouldn't be
there in the first place. Or do I have too high expections of serial
communication?
Problem solved.. the hardware was holding data back.. Fixed the
hardware so the problem is gone :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andrea Judge |
last post by:
Hi there,
I'm developing an application to catch OBD sensors' data from my car.
I connect it via a RS232 interface.
Now.
with HyperTerminal I can connect and send/receive data, but I'd like to do
this from inside my C# program.
Anyone can write down a very small (or tell how to do it myself) application
containing methods like WriteToSerialPort(string what) and
ReadFromSerialPort(what).
|
by: Jean Paul Mertens |
last post by:
Hello,
Someone can tell me why I dont get serial port events in a Service, I
created a separate Thread to open the port but no events are coming up (the
same happens when I use the timer component, using the System.Timers.Timer
it works fine)
tnx in advance
Jean Paul
|
by: nmsreddi |
last post by:
Hi friends
I am working on serialport in c# ,i am using C#2005 i have successfully done the serial communication with GSM modem and able to send and receive data ,
the main problem ,the serial port class in C# is accepting only ASCII values upto 127 only, the values those greater than 127 ,is automatically converted to value 63(?) ,ihave searched alot in the net and finally found from MSDN that ,serialport class accepts only ASCII values...
|
by: ndtang |
last post by:
Hi,
I am trying to convert a legacy rs232 application to vb2005. The
legacy app was written in pascal and runs in full DOS. I have
successfully rewrote the app to communicate with the device using
SerialPort component in .NET 2.0. It works wonderful with a desktop
PC.
When I installed the program to the laptop it fails, though the
original DOS app works in the same configuration. Somehow, the data is
|
by: Adriano |
last post by:
Hello,
I'm developing an application in VB.NET 2005 that communicates with a device
through RS232,
and need to send the following sequence of hexadecimal data to the device:
0xFF, 0x01, 0xC3, 0xE3, 0xFF, 0xFF.
That's the configuration:
| |
by: Squeamizh |
last post by:
Hi,
I am experiencing the exact same problem described in this post:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/a2b6c200d3eb03a6/55664b95cd2e0fdb
Sometimes my SerialPort.Write() calls are being interrupted before
completion. This problem occurs much more frequently in a GUI program
than in a console program. Calling SerialPort.BaseStream.Flush() does
not alleviate the problem.
|
by: grappeggia |
last post by:
Hi everybody, I`m doing a project in which a microcontroller realises an A/D conversion of 8 channels and send then to the computer using the USB, over one serialport interface.
On the PC, I`m using a VB software that receives and store the data from the microcontroller. On this program, the user
enters with the sampling time and the name of the storage file. So, to start the pickup, the user must click on the "Coletar"
button. Then the...
|
by: Ryan Liu |
last post by:
Hi,
I have a 100 clients/ one server application, use ugly one thread pre client
approach. And both side user sync I/O.
I frequently see the error on server side(client side code is same, but I
don't see the error):
"System.IO.IOException: Unable to read data from the transport connection:A
blocking operation was interrupted by a call to WSACancelBlockingCall"
|
by: jensa |
last post by:
Hi,
I am currently writing a simple form application in C# that uses the SerialPort class (C# 3.5). But I have put my head in the wall several times to solve a simple problem.
I have a datagridview and each time the event on row added is run I need to send some stuff out on the serialport. I am using the SerialPort write method to write byte data.
Each times several rows are added (more than one), in the same time frame (or very near in...
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |