فى البداية سوف نتحكم فى المشروع عن طريق برنامج مصمم على السى شارب
وهذه هى صورته
ومشاهدة محاكاة للاجهزة عن طريف برنامج Proteus وهذه هى صورته
شرح الكود الذى بداخل برنامج السى شارب
كود:
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;
using System.IO;
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;
sh.Enabled = true;
port = new SerialPort(coms.Text, 9600, Parity.None, 8, StopBits.One);
try
{
if (port.IsOpen)
port.Close();
//open serial port
port.Open();
}
catch (Exception x)
{
MessageBox.Show("The Port is Open");
}
}
//****************************************************
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = ".txt";
saveDialog.Filter = "text files(*.txt)|*.txt|All files (*.*)|*.*";
if (saveDialog.ShowDialog() != DialogResult.Cancel)
{
StreamWriter s = File.AppendText(saveDialog.FileName);
int i;
bool[,] m = new bool[10,8];
for (i = 0; i < c1.Items.Count; i++)
{
m[0, i] = c1.GetItemChecked(i);
if (c1.GetItemChecked(i) == true)
s.WriteLine(c1.GetItemText(c1.Items[i])+" is On");
else
s.WriteLine(c1.GetItemText(c1.Items[i]) + " is Off");
m[1, i] = c2.GetItemChecked(i);
if (c2.GetItemChecked(i) == true)
s.WriteLine("****"+c2.GetItemText(c2.Items[i])+" is On");
else
s.WriteLine("****" + c3.GetItemText(c3.Items[i]) + " is Off");
m[2, i] = c3.GetItemChecked(i);
if (c3.GetItemChecked(i) == true)
s.WriteLine("****" + c3.GetItemText(c3.Items[i]) + " is On");
else
s.WriteLine("****" + c3.GetItemText(c3.Items[i]) + " is Off");
m[3, i] = c4.GetItemChecked(i);
if (c4.GetItemChecked(i) == true)
s.WriteLine("****" + c4.GetItemText(c4.Items[i]) + " is On");
else
s.WriteLine("****" + c4.GetItemText(c4.Items[i]) + " is Off");
m[4, i] = c5.GetItemChecked(i);
if (c5.GetItemChecked(i) == true)
s.WriteLine("****" + c5.GetItemText(c5.Items[i]) + " is On");
else
s.WriteLine("****" + c5.GetItemText(c5.Items[i]) + " is Off");
m[5, i] = c6.GetItemChecked(i);
if (c6.GetItemChecked(i) == true)
s.WriteLine("****" + c6.GetItemText(c6.Items[i]) + " is On");
else
s.WriteLine("****" + c6.GetItemText(c6.Items[i]) + " is Off");
m[6, i] = c7.GetItemChecked(i);
if (c7.GetItemChecked(i) == true)
s.WriteLine("****" + c7.GetItemText(c7.Items[i]) + " is On");
else
s.WriteLine("****" + c7.GetItemText(c7.Items[i]) + " is Off");
m[7, i] = c8.GetItemChecked(i);
if (c8.GetItemChecked(i) == true)
s.WriteLine("****" + c8.GetItemText(c8.Items[i]) + " is On");
else
s.WriteLine("****" + c8.GetItemText(c8.Items[i]) + " is Off");
m[8, i] = c9.GetItemChecked(i);
if (c9.GetItemChecked(i) == true)
s.WriteLine("****" + c9.GetItemText(c9.Items[i]) + " is On");
else
s.WriteLine("****" + c9.GetItemText(c9.Items[i]) + " is Off");
m[9, i] = c10.GetItemChecked(i);
if (c10.GetItemChecked(i) == true)
s.WriteLine("****" + c10.GetItemText(c10.Items[i]) + " is On");
else
s.WriteLine("****" + c10.GetItemText(c10.Items[i]) + " is Off");
}
s.Close();
//***************************************
MessageBox.Show(convBoolToString(m));
port.Write(convBoolToString(m));
}
}
}
}
سوف يتم تعديل هذا الكود نظرا لطوله وهو عيب فى لغة البرمجة
ولكن هذا الكود صحيح ولقد وضعت فكرة عمل مصفوفة
وسف اشرح هذا الكود انشاء الله بالتفصيل
والله الموفق