Reputation: 221
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
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