Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Open Com port failed (multi threading)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Droopy - 07 Jul 2005 09:50 GMT
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,
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.
Droopy - 11 Jul 2005 15:53 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>
> Droopy.

Who can help me ?
Willy Denoyette [MVP] - 15 Jul 2005 17:57 GMT
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.

> Hi,
>
[quoted text clipped - 18 lines]
>
> Droopy.
Droopy - 19 Jul 2005 14:42 GMT
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
[quoted text clipped - 24 lines]
>>
>> Droopy.
Droopy - 25 Jul 2005 14:37 GMT
Who can help me ?
Have I to start it sequentially or add any timeout between thread
starting ?

> Yes.
> To be more precise, CreateFile returns INVALID_HANDLE_VALUE and
[quoted text clipped - 12 lines]
>>> 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,N
>>> ULL)) .
>>> So far, it works.
[quoted text clipped - 13 lines]
>>>
>>> Droopy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.