using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace The_control
{
public partial class Form1 : Form
{
SerialPort port;
public Form1()
{
InitializeComponent();
string[] ports = SerialPort.GetPortNames();
foreach (string port1 in ports)
{
coms.Items.Add(port1);
}
}
public String convBoolToString(bool[] a)
{
string s = null;
foreach (bool l in a)
{
if (l == true) { s = 1 + s; }
else s = 0 + s;
}
return s;
}
private void button2_Click(object sender, EventArgs e)
{
button1.Enabled = true;
c.Enabled = true;
button2.Enabled = false;
port = new SerialPort(coms.Text, 9600, Parity.None, 8, StopBits.One);
if (port.IsOpen) port.Close();
try
{
//open serial port
port.Open();
}
catch (System.Exception )
{
if (port.IsOpen) port.Close();
}
}
private void button1_Click_1(object sender, EventArgs e)
{
int i;
bool[] m = new bool[16];
for (i = 0; i < c.Items.Count ; i++)
{
m[i] = c.GetItemChecked(i);
}
//***************************************
// MessageBox.Show(convBoolToString(m));
port.Write(convBoolToString(m));
port.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string m;
m = port.ReadExisting();
if (m == "E")
{
label1.Text = " FIRE!!! ";
label1.BackColor = Color.Red;
}
}