Frink
Frink

Reputation: 221

Using Serial port control in another class

I have a Win-form application. I need to communicate with serial port from class.

For Example:

serialPort1.ReadExisting()

I don't know how to define serialPort1 without to insert component to form.

Can maybe I define it like reference, or?

Thanx

Upvotes: 0

Views: 179

Answers (1)

Ahmed ilyas
Ahmed ilyas

Reputation: 5822

Simply import the System.IO.Ports namespace and then declare the serial port object:

SerialPort serialPort1 = new SerialPort();

Declare this where you need to use it but most likely as a global variable in the class

example:

http://msdn.microsoft.com/en-gb/library/system.io.ports.serialport.aspx

Upvotes: 1

Related Questions