This is my code, you read help me please.
Thank you!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.IO;
namespace GTPT_688
{
public partial class Form1 : Form
{
string valueOfTemperature;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 19200;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.DtrEnable = true;
serialPort1.RtsEnable = true;
if (!serialPort1.IsOpen)
{
try
{
serialPort1.Open();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
}
}
private void Send_Click(object sender, EventArgs e)
{
if (ck1.Checked == true)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x6F;
serialPort1.Write(mBuffer, 0, mBuffer.Length);
}
if (ck1.Checked==false)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x66;
serialPort1.Write(mBuffer, 0, mBuffer.Length);
}
if (ck2.Checked==true)
{
byte[] mBuffer = new byte[1];
mBuffer[0] = 0x74;
serialPort1.Write(mBuffer, 0, mBuffer.Length);
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
valueOfTemperature += serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
private void DisplayText(object sender, EventArgs e)
{
lb1.Text = valueOfTemperature;
}
private void bn1_Click(object sender, EventArgs e)
{
}
}
}