473,767 Members | 7,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1392
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
SerialDataRecei vedEventHandler 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
1679
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 looked in the library reference and doesn't seems to get anything. Is there a problem with say 2 programs using the same ports? Thanks in advance.
0
1964
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 back we tested the application and it worked fine with ports 135 and 1331 open. Now its not working any more and we are seeing that it is not working because ports 137 and 4332 are closed. (Please note that it did not require ports 137 and 4332...
2
2542
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 file, it seems that db2icrt command adds 4 ports for each server. Example:
3
9330
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. VB.net literature does not provide any coverage on either the serial ports or the USB ports.
1
10919
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 errors 2) My Nokia 6600 prompted me the message "Accept Connection request from DEMON?" note: DEMON is my computers name. 3) Using my Nokia 6600, I hit the button that refers to the "Yes"
3
2995
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 works nicely. Then I put the app on on a virtual Windows machine running inside of vmware on the same Linux box. Vmware only lets me have four serial ports so I run the app against four serial ports using four threads. The app did not respond...
2
3960
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 development computer I don't have ay problem with my application.
3
3550
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
3086
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 the application possess to handle it without errors? -- Luke Davis, MCSE: Security DEM Networks - Senior Systems Architect 7225 N First, Suite 105 Fresno, CA 93720
10
18254
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
9575
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
10171
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
9960
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
8840
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
7384
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
5280
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
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2808
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.