Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ComConnector
- {
- public partial class Form1 : Form
- {
- private ComPort _comPort;
- private Modul_I7021 _modulI7021;
- private Modul_I7044 _modulI7044;
- public Form1()
- {
- InitializeComponent();
- UserUI();
- }
- public void SettingsUI()
- {
- GBSettings.Visible = true;
- GBTarget.Visible = false;
- this.Height = 260;
- }
- public void UserUI()
- {
- GBTarget.Visible = true;
- GBSettings.Visible = false;
- GBTarget.Location = new Point(9, 27);
- this.Height = 345;
- }
- private void OpenPort()
- {
- Thread.Sleep(100);
- _comPort = new ComPort(TextBoxComPort.Text, (int)NumericBaudRate.Value);
- var resultOpenPort = _comPort.OpenPort();
- AddLogMessage(resultOpenPort);
- _modulI7021 = new Modul_I7021(_comPort, (int)NUD7021.Value);
- _modulI7044 = new Modul_I7044(_comPort);
- if (!resultOpenPort.ToLower().Contains("ошибка")) ;
- }
- private void ButtonOpenPort_Click(object sender, EventArgs e)
- {
- }
- private void ButtonClosePort_Click(object sender, EventArgs e)
- {
- AddLogMessage(_comPort.ClosePort());
- }
- private void ButtonHandler_Click(object sender, EventArgs e)
- {
- if (_comPort == null)
- {
- OpenPort();
- }
- var count = _modulI7044.GetCountPort((int) NUD7044.Value);
- AddLogMessage($"С устройства {NUD7044.Value} считали {count}");
- if (count <= NumericFirstN.Value)
- {
- AddLogMessage($"{count} <= n1. " +
- $"Установим 5 вольт");
- _modulI7021.SetVolt((int) NUD7021.Value, "7FF");
- }
- else if (count <= NumericSecondN.Value)
- {
- AddLogMessage($"{count} <= n2. " +
- $"Установим 2.5 вольта");
- _modulI7021.SetVolt((int) NUD7021.Value, "3FF");
- }
- else
- {
- AddLogMessage("Количество импульсов больше чем н2");
- }
- }
- private void ButtonClearPort_Click(object sender, EventArgs e)
- {
- AddLogMessage(_modulI7044.ClearCountPort((int)NUD7044.Value));
- }
- private void AddLogMessage(string message)
- {
- TextBoxLog.AppendText($"{message}{Environment.NewLine}");
- TextBoxLog.ScrollToCaret();
- }
- private void ОбАвторахToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show($"Дмитриев Юрий\nБражникова Алина\nГруппа 6401", "Об авторах", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- private bool settings = false;
- private void НастрокиToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (!settings)
- {
- SettingsUI();
- }
- else
- {
- UserUI();
- }
- settings = !settings;
- }
- private void SendCommand_Click(object sender, EventArgs e)
- {
- if (_comPort == null)
- {
- OpenPort();
- _comPort.SendPort(TBCommand.Text);
- while (_comPort.Answer == null) ;
- }
- _comPort.SendPort(TBCommand.Text);
- while (_comPort.Answer == null) ;
- TBAnswer.Text = _comPort.Answer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement