ВКР (1194189), страница 8
Текст из файла (страница 8)
Random r = new Random();
//mypen.Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255), r.Next(255));
mypen.Color = Color.FromArgb(255, 0, 0, 0);
for (int i = 5; i < DrawArea.Width - 1; i++)
{
g.DrawLine(mypen2, i+1, 255, i+1, 00);
if (i < data.Count - 1)
{
int offset = data.Count - DrawArea.Width;
if (offset < 0) offset = 0;
g.DrawLine(mypen3, i, 255 - Convert.ToInt32(data[i + offset] * 50)-5, i + 1, 255 - Convert.ToInt32(data[i + 1 + offset] * 50)-5);
}
}
g.DrawLine(mypen, 5, 0, 5, DrawArea.Height);
g.DrawLine(mypen, 5, 0, 10, 5);
g.DrawLine(mypen, 5, 0, 0, 5);
g.DrawLine(mypen, 0, DrawArea.Height-5, DrawArea.Width, DrawArea.Height-5);
g.DrawLine(mypen, DrawArea.Width-3, DrawArea.Height - 5, DrawArea.Width-8, DrawArea.Height - 10);
g.DrawLine(mypen, DrawArea.Width-3, DrawArea.Height - 5, DrawArea.Width-8, DrawArea.Height);
for (int h = 50; h < DrawArea.Height-5; h = h + 50)
{
g.DrawLine(mypen, 0, h, 10, h);
}
g.DrawLine(mypen, 0, 50, 10, 50);
pictureBox1.Image = DrawArea;
pictureBox1.Refresh();
g.Dispose();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
buffer += indata;
if (buffer.Contains('\n'))
{
buffer=buffer.Replace('.', ',');
data.Add(Convert.ToDouble(buffer));
label1.Text = data.Count.ToString() + " " + Convert.ToDouble(buffer).ToString() + " atm.";
ShowDraph();
buffer = "";
}
}
private void Tick(object sender, EventArgs e)
{
SerPort.Write("f");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Form1.Designer.cs
namespace PresureGraph
{
partial class Form1
{
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(29, 29);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Считать";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// label1
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(54, 83);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Время и давление";
// comboBox1
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(215, 31);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 2;
this.comboBox1.DropDown += new System.EventHandler(this.ScanPorts);
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.PickPort);
// pictureBox1
this.pictureBox1.Location = new System.Drawing.Point(57, 149);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(500, 256);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
// timer1
this.timer1.Interval = 60;
this.timer1.Tick += new System.EventHandler(this.Tick);
// label2
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 149);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 13);
this.label2.TabIndex = 4;
this.label2.Text = "P, а.т.м.";
// label3
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(520, 419);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 13);
this.label3.TabIndex = 5;
this.label3.Text = "t, время";
// label4
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(114, 34);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(95, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Порт считывания";
// label5
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(38, 195);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(13, 13);
this.label5.TabIndex = 7;
this.label5.Text = "4";
// label6
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(38, 243);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(13, 13);
this.label6.TabIndex = 8;
this.label6.Text = "3";
// label7
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(38, 392);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(13, 13);
this.label7.TabIndex = 9;
this.label7.Text = "0";
// label8
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(38, 344);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(13, 13);
this.label8.TabIndex = 10;
this.label8.Text = "1";
// label9
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(38, 295);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(13, 13);
this.label9.TabIndex = 11;
this.label9.Text = "2";
// Form1
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(641, 552);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Считывание данных с датчика";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace PresureGraph
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
73















