473,800 Members | 2,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open Com port failed (multi threading)

Hi,

I wrote a C# program that is calling C++ legacy code to open a serial port
(using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,NULL))
..
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the time,
1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course) in
parallel thread at the same time ?

Thanks in advance for your help,

Droopy.
Nov 17 '05 #1
5 6898
Droopy <dr************ **@hotmail.com> wrote in
news:Xn******** *************** ***********@195 .129.110.71:
Hi,

I wrote a C# program that is calling C++ legacy code to open a serial
port (using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,NU
LL)) .
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the
time, 1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course) in
parallel thread at the same time ?

Thanks in advance for your help,

Droopy.


Who can help me ?
Nov 17 '05 #2
Droopy <dr************ **@hotmail.com> wrote in
news:Xn******** *************** ***********@195 .129.110.71:
Hi,

I wrote a C# program that is calling C++ legacy code to open a serial
port (using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,NU
LL)) .
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the
time, 1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course) in
parallel thread at the same time ?

Thanks in advance for your help,

Droopy.


Who can help me ?
Nov 17 '05 #3
Yes it is. The "Access denied" error code has IMO nothing to do with the
number of threads, are you sure this error is returned by the CreateFile
call?

Willy.

"Droopy" <dr************ **@hotmail.com> wrote in message
news:Xn******** *************** ***********@195 .129.110.71...
Hi,

I wrote a C# program that is calling C++ legacy code to open a serial port
(using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,NULL))
.
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the
time,
1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course) in
parallel thread at the same time ?

Thanks in advance for your help,

Droopy.

Nov 17 '05 #4
Yes.
To be more precise, CreateFile returns INVALID_HANDLE_ VALUE and
GetLastError () returns 5 (Access Denied)

Sorry for this late answer.
Yes it is. The "Access denied" error code has IMO nothing to do with
the number of threads, are you sure this error is returned by the
CreateFile call?

Willy.

"Droopy" <dr************ **@hotmail.com> wrote in message
news:Xn******** *************** ***********@195 .129.110.71...
Hi,

I wrote a C# program that is calling C++ legacy code to open a serial
port (using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,N
ULL)) .
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the
time,
1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course)
in parallel thread at the same time ?

Thanks in advance for your help,

Droopy.



Nov 17 '05 #5
Who can help me ?
Have I to start it sequentially or add any timeout between thread
starting ?
Droopy <dr************ **@hotmail.com> wrote in
news:Xn******** *************** ***********@195 .129.110.71:
Yes.
To be more precise, CreateFile returns INVALID_HANDLE_ VALUE and
GetLastError () returns 5 (Access Denied)

Sorry for this late answer.
Yes it is. The "Access denied" error code has IMO nothing to do with
the number of threads, are you sure this error is returned by the
CreateFile call?

Willy.

"Droopy" <dr************ **@hotmail.com> wrote in message
news:Xn******** *************** ***********@195 .129.110.71...
Hi,

I wrote a C# program that is calling C++ legacy code to open a serial
port (using CreateFile (comPort,
GENERIC_READ|GE NERIC_WRITE,0,N ULL,OPEN_EXISTI NG,FILE_FLAG_OV ERLAPPED,N ULL)) .
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the
time,
1 Com port opening failed.
The GetLastError returns 5 (access denied).

So, my question is :

Is it safe to call 4 CreateFile (for different Com ports of course)
in parallel thread at the same time ?

Thanks in advance for your help,

Droopy.




Nov 17 '05 #6

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

Similar topics

77
5391
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
0
1018
by: Droopy | last post by:
Hi, I wrote a C# program that is calling C++ legacy code to open a serial port (using CreateFile (comPort, GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL)) .. So far, it works. Now, at startup, I start 4 C# threads. These threads are opening Com ports #2, #3, #4 and #5. Sometimes, these 4 Com ports are opened successfully but, most of the time,
38
9671
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched quite a bit over the web and could not find anything useful. I don't want to use Visual C++ or Cygwin, linux, etc. If any of you guys have some little tid bit of code that would be great to look at.
25
3637
by: bmearns | last post by:
Is it possible to specify which port to use as the outbound port on a connection? I have the IP address and port number for the computer I'm trying to connect to (not listening for), but it's expecting my connection on a certain port. Specifically, I'm trying to write an FTP host, and I'm trying to implement the PORT command. From everything I've read, the client supplies the IP address and port number for where I'm supposed to connect...
2
3495
by: abid gee | last post by:
Please give a kind look on my question. and please comments. I am Using C# as development tool of Dot Net 2.0. I wrote a function read_data() that read data from Serial Port continuously.Till application gets close. But When Form loaded read_data() function take tooo much CPU. Even I can not see Application controls. Some body told me, Use Threading.
0
1880
ammoos
by: ammoos | last post by:
hi friends pls help me.. i got an assignment which i feel very difficult to me.. i dont have more knowledge about multi-threading in .net... the assignment details is below.... pls help me... i have to submit this assignment today evening... please....... Windows Application to demonstrate the use of Multi-Threading with Synchronous & Asynchronous Threading. Requirements 1) A form with a) a button to initialize threads ...
2
4145
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error message is: E:\software\development\boost_1_35_0\boost_1_35_0>bjam -- toolset=msvc-7.1 --variant=release --threading=multi --link=shared --
0
2680
by: Andrew MacIntyre | last post by:
Tony May wrote: The DLL that's actually being imported by your script is not a Python extension module, as the modules initialisation function can't be found. Use the -v option on the Python command line to identify which DLL is actually being imported. You can then decide to move/rename.delete it or your own module as best fits your circumstances. --
29
1923
by: Praki | last post by:
Greetings All, i think this is the right group to post this question. i am working on client server model. in this model the client is sending request in thousands in number. for example per sec around 2000 to 3000 request is coming. so the server is listening in the udp port. after some time the most of the request is dropped. how can manage this problem. is the multi threading will help ? but it is UDP port i dont know how handle...
0
9691
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
10505
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
10276
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...
0
10035
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
6813
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();...
0
5471
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...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.