I'm trying to use SerialPort as a parameter for my other classes constructor:
serial1 = new SerialPort(SerialPorts.COM1, Constants.baud_cam, Parity.None, 8, StopBits.One); serial1.DataReceived += new SerialDataReceivedEventHandler(camera_DataReceived); serial1.Open(); Ucamttl camera = new Ucamttl(serial1);
Ucamttl class:
SerialPort serial; public Ucamttl(SerialPort sp) { serial = sp; }
I can't seem to use the serialPort in my Ucamttl class. It works well in the main routine though.
The error occurs when the ucamttl class tries to write to the serial ( serial.Write(_command,0,Constants.CMD_SIZE); )
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) #### #### Message: #### Thermocam.Program::SyncCam [IP: 0007] #### #### Thermocam.Program::Main [IP: 008d] ####
Since I'm a noob there are a lot of questions..
- In which class do i need to open the port?
- In which class do i need to implement the event handlers?
- and if, then how, and why?
Thanks for helping!