473,799 Members | 3,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SerialPort Class too slow & CPU Hog?

Does anyone out there happen to have experience using VC# (or any .NET
really) to control the serial port for demanding use? My ultimate
goal would be to stream an arbitrarily large size (MB+) file out over
the serial port with zero down time at speeds ranging from 9600 to
480600 baud.

While using the SerialPort Control, I cannot come up with an
implimentation that doesn't A) hog the CPU at 100% and B) is able to
continually fill the TX buffer before it empties itself.

If anyone has done this, or even come close, I'd be very appreciative
of your help and suggestions. Thanks!

- Kevin
Dec 6 '07 #1
2 2626

"Kevin" <ke********@gma il.comwrote in message
news:89******** *************** ***********@n20 g2000hsh.google groups.com...
Does anyone out there happen to have experience using VC# (or any .NET
really) to control the serial port for demanding use? My ultimate
goal would be to stream an arbitrarily large size (MB+) file out over
the serial port with zero down time at speeds ranging from 9600 to
480600 baud.

While using the SerialPort Control, I cannot come up with an
implimentation that doesn't A) hog the CPU at 100% and B) is able to
continually fill the TX buffer before it empties itself.

If anyone has done this, or even come close, I'd be very appreciative
of your help and suggestions. Thanks!
I'm not doing large data transfer like that, but I'm managing ~8 UARTs
connected over USB with little or no CPU used at rates from 9600-115200
each. I found other problems with the BCL SerialPort class, so I wrote the
serial comm code against the Win32 API using overlapped I/O with ReadFileEx
and WriteFileEx.

Using OVERLAPPED operations, each write should complete when the data is
transferred completely into the kernel buffers (possibly into the UART FIFO)
and you can then post the next write operation. But that's complicated and
not easy to accomplish with p/invoke, I used C++/CLI to integrate .NET and
Win32.

Have you tried just dedicating a thread to a blocking write operation?
Something along the lines of always submitting a 16k chunk should work
really well, and be very CPU efficient.
>
- Kevin

Dec 6 '07 #2
<qoute>
Have you tried just dedicating a thread to a blocking write
operation?
</quote>

I tried a little while back, but it didn't work. After your
suggestion, I re-evaluated my approach, found I wasn't really doing
the processing in the dedicated thread. After fixing it, I think its
working and the dedicated thread did the trick! Thanks a bunch,

- Kevin
On Dec 6, 12:11 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Kevin" <kevinwo...@gma il.comwrote in message

news:89******** *************** ***********@n20 g2000hsh.google groups.com...
Does anyone out there happen to have experience using VC# (or any .NET
really) to control the serial port for demanding use? My ultimate
goal would be to stream an arbitrarily large size (MB+) file out over
the serial port with zero down time at speeds ranging from 9600 to
480600 baud.
While using the SerialPort Control, I cannot come up with an
implimentation that doesn't A) hog the CPU at 100% and B) is able to
continually fill the TX buffer before it empties itself.
If anyone has done this, or even come close, I'd be very appreciative
of your help and suggestions. Thanks!

I'm not doing large data transfer like that, but I'm managing ~8 UARTs
connected over USB with little or no CPU used at rates from 9600-115200
each. I found other problems with the BCL SerialPort class, so I wrote the
serial comm code against the Win32 API using overlapped I/O with ReadFileEx
and WriteFileEx.

Using OVERLAPPED operations, each write should complete when the data is
transferred completely into the kernel buffers (possibly into the UART FIFO)
and you can then post the next write operation. But that's complicated and
not easy to accomplish with p/invoke, I used C++/CLI to integrate .NET and
Win32.

Have you tried just dedicating a thread to a blocking write operation?
Something along the lines of always submitting a 16k chunk should work
really well, and be very CPU efficient.


- Kevin- Hide quoted text -

- Show quoted text -
Dec 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3233
by: DraguVaso | last post by:
Hi, I'm experimenting with the Serial Port in VB.NET 2005. Although it isn't that easy to get any feedback from my COM-port as I thought it would be... How can I read all the Data that the port sends back? I tryed with SerialPort1.ReadLine, but that blocks the application and takes a lot of time (10 seconds!), I tryed SerialPort1.Read, but I have to read it into a buffer and has to indicate the count, but how do I know this?
1
3656
by: Richie Carey | last post by:
Here's my problem. I'm using Visual C# 2005 Express for a small project that requires simple AT modem commands to be sent to an external serial device. The device requires 2400 baud, no parity, 8 data bits, and 1 stop bit. Should be easy enough, except that I cannot get the SerialPort component included with C# Express to talk with this box. I know the box itself is working correctly because a Visual Basic 6.0 application that I...
4
29288
by: Ben Kim | last post by:
Hello all, Does anyone have an example on how to implement the new SerialPort Class in VB.NET? I have been able to create the class, send (.WriteLine) to the port and Read from the port but cannot figure out how to use the Events to tell my program that data is available in the serial port buffer. I have searched the internet and MSDN and there doesn't appear to be any full example on how to do this simple task.
5
2260
by: herbert | last post by:
back in 1978 (!) the VAX/VMS serial line driver offered everything a developer needs to develop protocols of all kinds: - read x bytes - read to end of line - read to special character - read to one in a set of special characters - and of course synchronous and asynchronous using events and including timeouts. And even before RSX-11 could do this out of the box.
2
1806
by: Jay | last post by:
Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx... public static void Main() { string name; string message; StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; Thread readThread = new Thread(Read); // Create a new SerialPort object with default settings.
0
3172
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...
2
2872
by: Kevin | last post by:
Does anyone out there happen to have experience using VC# (or any .NET really) to control the serial port for demanding use? My ultimate goal would be to stream an arbitrarily large size (MB+) file out over the serial port with zero down time at speeds ranging from 9600 to 480600 baud. While using the SerialPort Control, I cannot come up with an implimentation that doesn't A) hog the CPU at 100% and B) is able to continually fill the...
10
18269
by: sklett | last post by:
I'm trying to send some printer commands (ZPLII) to an attached USB printer using the SerialPort component. I didn't get very far at all. In fact I haven't gotten anywhere. The first problem I encountered is that a call to SerialPort.GetPortNames() returns an empty string. In other words, NO port names are returned. I'm not terribly knowledgable about ports but from the Hardware Manager I did notice that I don't have the Ports and...
0
2498
by: cronusf | last post by:
I set up two virtual COM ports 3 and 4 using com0com. I tried to test it with the following program. However, the DataReceived event handlers never get called. Can anyone with SerialPort class experience double check my code so I can narrow it down to com0com not being setup correctly? using System; using System.Collections.Generic; using System.IO.Ports; using System.IO;
9
8488
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...
0
10491
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...
0
10268
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 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...
1
10247
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
10031
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
9079
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...
0
5467
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
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.