using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
string InputString = serialPort1.ReadExisting();
string[] data = InputString.Split(',');
textBox1.Text = data[0];
textBox2.Text = data[1];
int b;
int d;
bool result = Int32.TryParse(data[0], out b);
bool sonuc = Int32.TryParse(data[1], out d);
if (result)
{
if (b < 224)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
else
{
button1.BackColor = Color.Lime;
label1.Text = "AVAILABLE";
}
}
if (sonuc)
{
if (d< 224)
{
button1.BackColor = Color.Red;
label1.Text = " OCCUPIED";
}
else
{
button1.BackColor = Color.Lime;
label1.Text = "AVAILABLE";
}
}
int b = Int16.Parse(a);
textBox1.Text= a.ToString();*/
private void button3_Click(object sender, EventArgs e)
{
listBox1.Visible = true;
listBox1.Items.Add("Değerler alınıyor!");
if (!serialPort1.IsOpen)
{
serialPort1.PortName = "COM11";
serialPort1.Open();
}
}
private void button4_Click(object sender, EventArgs e)
{
serialPort1.Close();
listBox1.Items.Add("Durduruldu!");
}
}
}
我收到了一个错误:
&#34; serialport1在上下文中不存在&#34;
我能做什么?每当我想编译时,我都会得到上面提到的错误
我是否需要添加任何库?
我正在使用visual Studio 2010