SerialPort serial = new SerialPort(); public string recieved_data; //public static string strtemp = string.Empty; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } private void Recieve(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { // Collecting the characters received to our 'buffer' (string). try { if (serial.IsOpen == false) serial.Open(); if (serial.IsOpen == true) { recieved_data = serial.ReadExisting(); clsData.strData = recieved_data; } } catch (Exception ex) { lblMessage.Text = ex.Message.ToString(); } } protected void btnStart_Click(object sender, EventArgs e) { try { serial.PortName = "COM1"; //Com Port Name serial.BaudRate = 9600; //COM Port Sp serial.Handshake = System.IO.Ports.Handshake.None; serial.Parity = Parity.None; serial.DataBits = 8; serial.StopBits = StopBits.One; serial.ReadTimeout = 200; serial.WriteTimeout = 50; if (serial.IsOpen == true) serial.Close(); serial.Open(); //Sets button State and Creates function call on data recieved serial.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Recieve); } catch (Exception exp) { lblMessage.Text = exp.Message.ToString(); } } protected void btnStop_Click(object sender, EventArgs e) { serial.Close(); } } [Serializable] public class clsData { public static string strData = ""; public static string getclsData() { return strData; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)