"System.NullReferenceException: Object reference not set to an instance of an object."
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { private System.IO.Ports.SerialPort serialPort1; private System.ComponentModel.IContainer components; protected void Page_Load(object sender, EventArgs e) { } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.serialPort1 = new System.IO.Ports.SerialPort(this.components); } protected void Button1_Click(object sender, EventArgs e) { try { if (serialPort1.IsOpen) { serialPort1.Close(); } else { serialPort1.Open(); } Label1.Text += serialPort1.ReadExisting(); //exception here } catch (Exception eo) { Label1.Text = "exception open==>" + eo; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)