Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Writing method in wcf seervice for write data on comport:- COM1

C#
if (!(comPort.IsOpen == true)) comPort.Open();
                       //convert the message to byte array
                       byte[] newMsg = StingToAscii(msg);
                       //send the message to the port
                       comPort.Write(newMsg, 0, newMsg.Length);


when i call method then first time write data on port but second time get error:-Access to the port 'COM1' is denied.

when I comment this line
C#
//if (!(comPort.IsOpen == true)) comPort.Open();

then get error :- Comport is Closed

please Suggest me. Its very ugent.

Thanks In Advance

Chandrashekhar
Posted

1 solution

I think I need some more of your code to try to help. How is this code used? Inside an object? In your Service? Do you have more than one instances of this object? (more than one connection?)

Maybe (just an idea, and thats why i moved this from Comment to solution) you have to make this method static?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900