473,414 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Com ports

}{
I have an app that reads a character string on com 1, waits for a signal
(any ascii char) on com 2, then outputs the string on com 2.

I seem to have a problem with the timing. It just so happens that the signal
from com2 arrives at the same time as the next string for com1.

Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.

Thanks.
Jun 27 '08 #1
3 1377
Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.
I think you should handle the race condition, a mutex solution would
help, there is buffers to use so you wont lose data eaven if waiting
in one receive event until that is finished. but that is a rather bad
way to solve the problem, if a telex isn't read all the way the
process will be hanging there.
UARTS (like 16550) have a small buffer (16 bytes, I think) but issue
an interrupt and will be handeld by the driver, the buffer size is
normally set to larger than the maximum expected packet in your
program language of choice.

//CY
Jun 27 '08 #2
On Fri, 18 Apr 2008 01:38:20 -0700, }{ <sn****@groups.comwrote:
I have an app that reads a character string on com 1, waits for a signal
(any ascii char) on com 2, then outputs the string on com 2.

I seem to have a problem with the timing. It just so happens that the
signal
from com2 arrives at the same time as the next string for com1.

Do the com ports run in sepaerate threads by default, or should I be
doing
something in code to make this happen.
The "com ports" themselves are handled by the OS. Whether they run in
separate threads or not is immaterial and out of the scope of your
application.

Now, as far as the code in your application that reads the COM ports, .NET
does not introduce new threads to your application's code without your
say-so. If you have written your application as a single-threaded
application, then all of your i/o will be handled in a single-thread.

With most of the i/o classes, there are asynchronous methods that allow
for multi-threaded processing of the i/o. You don't create a thread
explicitly using these methods, but the framework manages special i/o
worker threads that are used whenever some i/o occurs. Your own code
winds up being executed on one or more of these threads, and in that way
the i/o can be dealt with in a multi-threaded way.

I haven't use the SerialPort class (I assume that's what you're using),
and my recollection is that it has a slightly different API that most of
the other i/o classes. So I can't offer specific advice about how best to
approach the multi-threaded issue. However, I can see that the SerialPort
class does have a BaseStream property from which you can get a Stream
instance, and for sure the Stream class provides the asynchronous API I
mentioned above.

That's how I would approach it initially. If for some reason that didn't
work out, then I might look into creating my own threads to deal with the
different ports. But one way or the other, you need to tell .NET via the
code you write that you want a multi-threaded solution, if indeed you do.

Pete
Jun 27 '08 #3
On Fri, 18 Apr 2008 09:38:20 +0100, "}{" <sn****@groups.comwrote:
>I have an app that reads a character string on com 1, waits for a signal
(any ascii char) on com 2, then outputs the string on com 2.

I seem to have a problem with the timing. It just so happens that the signal
from com2 arrives at the same time as the next string for com1.

Do the com ports run in sepaerate threads by default, or should I be doing
something in code to make this happen.
How are you handling the incoming data, via polling, or by handling
the DataReceived event? I'd recommend the latter. Have a
SerialDataReceivedEventHandler method for COM1, and another one for
COM2. The first one just buffers received data into a public string,
the second one sends the buffered string to COM2 on reception of the
trigger character, and empties the buffer. (Synchronize on the buffer)

I'm not quite sure how your app should handle characters incoming on
COM2 with no buffered string present from COM1, or indeed multiple
incoming strings on COM1 with not COM2 request in between - you'll
need to decide what to do here. If memory serves, the incoming serial
data received calls are not on the UI thread, not sure though.

Regards,
Gilles.

Jun 27 '08 #4

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

Similar topics

1
by: Maurice LING | last post by:
Hi, I'm writing something that specifies the use of SOAP. One requirement that fumbles me is the port number(s) to use. Is there any way to find out which ports are not used by the system? I've...
0
by: pothik05 | last post by:
Hi, We are using an application (the application uses WMI componenets) to change the IIS metabase of Server A from Server B. There is a firewall between Server A and Server B. Couple of weeks...
2
by: Hemant Shah | last post by:
Folks, How many tcp ports does DB2 server use? I installed UDB 8.2 on a AIX system and created several instances. I used consecutive ports for each instance, but when I look at /etc/services...
3
by: andyI | last post by:
Where do I find information on how to address and pass data to and from the serial ports and USB ports in VB. VB6 supports the serial ports easily but I see no reference to using the USB ports....
1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
3
by: Tom Brown | last post by:
Hey people, I've written a python app that r/w eight serial ports to control eight devices using eight threads. This all works very nicely in Linux. I even put a GUI on it using PyQt4. Still...
2
by: joaquimfpinto | last post by:
Dear All, I made an app in c# that uses several serial ports. For the serial ports I use a pnp Sunix board, some with 8 serial ports other with 4 or even 2 serial ports. Whenever I use the...
3
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello everyone, I am using .net remoting. Is there any way to find out the list of open ports. Thanks.
3
by: Luke Davis | last post by:
I'm looking for an effective way to open and close TCP ports. Can I do this through Tcpclient? And I know this is a potential security risk, so what kind of permission must the person running...
10
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.