473,406 Members | 2,713 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,406 software developers and data experts.

MSCommLib ActiveX Control in a C# Windows Service?

I'm working on a C# Windows Service that needs to monitor serial port
communication. Because the .Net framework does not include support for
serial communications, I've decided to use the Microsoft Communication
Control (MSCommLib) that comes with Visual Studio 6. It seems easy to use
and works well enough for me within the context of a Windows Application.
Because I need the serial ports to be monitored 24/7, however, a Windows
Service seems like the better choice.

Because the MSCommLib control is an OCX, it needs to be placed on a Form.
I've added a Form that presumably won't be displayed during runtime to my
Windows Service project. At this point, with just a Windows Service and an
Empty Form, I am able to install and start the service with no problems.
After adding the MSCommLib Control to the form, however, when I start the
service I get an error message that says something like:

"Your Service started and then stopped. Some services do this"

Placing Event Log debug statements in the code reveals that the Service
never appears to return from the Form.InitializeComponents() function, in
which the MACommLib control is instantiated and initialized.

Does anyonone have any advice regarding my situation? Perhaps I am trying
to do the impossible...Any workarounds or alternate solutions for monitoring
a server's serial ports would be greatly appreciated.

Thanks,

Will
Nov 15 '05 #1
7 10847
Will,

Generally speaking, trying to access UI elements is a bad idea when
running in the context of a service. Granted, you can have your service
interact with the desktop (by clicking "allow service to interact with
desktop"), but you can't guarantee that there will always be a desktop.

Because of this, you might want to conisder making calls to the Windows
API through the P/Invoke layer to access the serial port. There are a few
classes out there that do this already, and I believe there is an
implementation on gotdotnet.com.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Will" <de*@rusmo.com> wrote in message
news:cp********************@giganews.com...
I'm working on a C# Windows Service that needs to monitor serial port
communication. Because the .Net framework does not include support for
serial communications, I've decided to use the Microsoft Communication
Control (MSCommLib) that comes with Visual Studio 6. It seems easy to use and works well enough for me within the context of a Windows Application.
Because I need the serial ports to be monitored 24/7, however, a Windows
Service seems like the better choice.

Because the MSCommLib control is an OCX, it needs to be placed on a Form.
I've added a Form that presumably won't be displayed during runtime to my
Windows Service project. At this point, with just a Windows Service and an Empty Form, I am able to install and start the service with no problems.
After adding the MSCommLib Control to the form, however, when I start the
service I get an error message that says something like:

"Your Service started and then stopped. Some services do this"

Placing Event Log debug statements in the code reveals that the Service
never appears to return from the Form.InitializeComponents() function, in
which the MACommLib control is instantiated and initialized.

Does anyonone have any advice regarding my situation? Perhaps I am trying
to do the impossible...Any workarounds or alternate solutions for monitoring a server's serial ports would be greatly appreciated.

Thanks,

Will

Nov 15 '05 #2
Sam
You may want to try using NetSerialComm, it works well:
http://msdn.microsoft.com/msdnmag/is...netserialcomm/

Supposedly, MS is supposed to add serial ports to a future version of the
..NET framework. Anyone know if 2.0 will have this functionality?

"Will" <de*@rusmo.com> wrote in message
news:cp********************@giganews.com...
I'm working on a C# Windows Service that needs to monitor serial port
communication. Because the .Net framework does not include support for
serial communications, I've decided to use the Microsoft Communication
Control (MSCommLib) that comes with Visual Studio 6. It seems easy to use and works well enough for me within the context of a Windows Application.
Because I need the serial ports to be monitored 24/7, however, a Windows
Service seems like the better choice.

Because the MSCommLib control is an OCX, it needs to be placed on a Form.
I've added a Form that presumably won't be displayed during runtime to my
Windows Service project. At this point, with just a Windows Service and an Empty Form, I am able to install and start the service with no problems.
After adding the MSCommLib Control to the form, however, when I start the
service I get an error message that says something like:

"Your Service started and then stopped. Some services do this"

Placing Event Log debug statements in the code reveals that the Service
never appears to return from the Form.InitializeComponents() function, in
which the MACommLib control is instantiated and initialized.

Does anyonone have any advice regarding my situation? Perhaps I am trying
to do the impossible...Any workarounds or alternate solutions for monitoring a server's serial ports would be greatly appreciated.

Thanks,

Will

Nov 15 '05 #3
Hi Will,
Because the MSCommLib control is an OCX, it needs to be placed on a
Form.


This is not true, you do not have to place the MSComm control in a form.
Simply add a reference in your C# project to MSCommLib. Click on the COM
tab and browse to select your MSCOMM32.OCX .

Then create an instance of it in your C# class:

MSCommLib.MSComm mscomm = new MSCommLib.MSCommClass();

The MSComm control has been working fine for me however I am still looking
for a better .NET way to do it:

Some alternatives to using the MSComm control in .NET

C#
http://www.gotdotnet.com/Community/U...4-dfe325097c69

Managed C++
http://www.codeproject.com/managedcpp/howtocomport.asp

VB .NET
http://www.mentalis.org/classlib/class.php?id=15
http://www.gotdotnet.com/Community/U...0-93391fc4c196

C# ( This uses thread pooling that is not supported under Win98)
http://www.gotdotnet.com/Community/U...4-dfe325097c69

C#
http://www.gotdotnet.com/Community/U...f-0045b0c79ec7

-Ed
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/28/2003
Nov 15 '05 #4
> This is not true, you do not have to place the MSComm control in a
form. Simply add a reference in your C# project to MSCommLib. Click on the COM tab and browse to select your MSCOMM32.OCX . Then create an instance of it in your C# class: MSCommLib.MSComm mscomm = new MSCommLib.MSCommClass();


Ed, thanks a ton for the tip. I'm going to give this a shot first before I
punt on the MSCommLib control.

Will.
Nov 15 '05 #5
Thanks for the link...it'll serve as a backup plan if Ed Sutton's suggestion
doesn't work.

Thanks,
Will.
Nov 15 '05 #6
> Ed, thanks a ton for the tip. I'm going to give this a shot first
before I punt on the MSCommLib control.


I agree that is the least riskiest approach.

The MSComm control is very reliable. I am using it in my C# application to
reliably communicate at high speeds 460,800 bps using a USB/Serial
interface.

Whenever I get enough time though, I want to use a more .NET approach.

This guy says "MSCOMM is the most bug-free component that Microsoft has ever
released.". Actually, I think Microsoft purchased it from Sax.

http://www.vbrad.com/source/src_mscomm_tutorial.htm

-Ed
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/27/2003
Nov 15 '05 #7
Thanks Ed, your suggestion worked!
Nov 15 '05 #8

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

Similar topics

0
by: Terminal882003 | last post by:
Hi, Here I have a question about MSCommLib. I need to dynamically add activeX controls that requires run-time license for MSCommLib. The following is the actual code: AxMSCommLib.AxMSComm...
5
by: David | last post by:
Hi everyone, I have a ActiveX EXE component written in VB6. This ActiveX EXE exposes various public methods that can be called by several other independent Windows EXE applications (also written...
2
by: Rene | last post by:
I added the MSCommLib (Microsoft ActiveX component) reference to my project so that I could use the MSCommClass for serial communication. The problem is that I get the following error "Class is not...
5
by: andy.g.ward | last post by:
I keep getting this when trying to create an MFC activex control in a c# windows service - anyone got any ideas what the missing module could be??? Exception thrown :...
0
by: zevikw | last post by:
I am using an ActiveX control in a .NET application which I put on a form. I have another .NET control on that form that handles the Validating event. The method that handles the Validating event,...
7
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do...
6
by: Budhi Saputra Prasetya | last post by:
Hi All, I'm trying to display .NET Custom Control (created using Inherited Control) on an ASPX page, but no luck. I already registered the Control to Global Assembly Cache through .NET Framework...
6
by: hufaunder | last post by:
I have an ActiveX component that I want to use in a library that I am writing. As a first test I used the ActiveX component in a windows form application. Adding the component created: Ax.dll...
2
by: =?Utf-8?B?Sm9obiBG?= | last post by:
Hello All, I have a question about using an ActiveX control with a Windows Servce in C#. I believe it is not possible to properly setup an ActiveX control in a windows service as the particular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.