Click here to Skip to main content
16,007,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created separate class for Serialport and accessing open, close, portnames and Datarecieved event.Now my problem is dont want to hard code the Comport in Serialport class as below.1)Instead want to select one of the comport from combobox which is a getportnames().I have two tabItem,in first tabitem every time i open the port and close for every button click where as in second tabitem on button click i'll be reading data from serial port continuously by using DataReceived event in serialport.Oncei read data continously then i change to tabitem and i try to close the opened port and open it getting Access to comport i sdenied.why is it so and how i can solve it?? any idea ,any solution please let me know

C#
//serialportclass

serialport sp =new Seriaport("COM1");(and other settings  too)

private void PortOpen()
{
sp.Open(); //access is denied
}

private void PortClose()
{
sp.Close();
}

public List<string> GetAllportNames()
{
List<string> lst =new List<string>();
foreach(var item in Serilport.GetPortNames())
{
lst.Add(item);
}
return lst;
}

In UI

In WindowLoaded Event

serialportclass spobj=new serialportclass();
Combobox1.ItemsSource=spobj.GetAllportNames(); //how can i access combobox selecteditem to serialportclass's COMport as show in above.... 
Posted
Comments
keerth516 25-Dec-13 9:52am    
Access is denied means.comport that your trying to access is closed or device is not connected..please check

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