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.Windows.Forms;
- using System.IO.Ports;
- namespace Camsecurity
- {
- public partial class fmConfig : Form
- {
- private SerialPort port;
- public string portcomu = "";
- public bool verif = false;
- public fmConfig()
- {
- InitializeComponent();
- cmbPort.SelectedIndex = 0;
- }
- private void fmConfig_Load(object sender, EventArgs e)
- {
- chbMovCam.Checked = true;
- chbMovCam.Checked = Properties.Settings.Default.chbMVRecord;
- chbPIR.Checked = false;
- chbPIR.Checked = Properties.Settings.Default.chbPIRRecord;
- btnAceptar.Enabled = false;
- }
- /** LISTO **/
- private void btnProbar_Click(object sender, EventArgs e)
- {
- string puerto = Convert.ToString(cmbPort.SelectedItem);
- try
- {
- port = new SerialPort(puerto, 9600);
- if (!port.IsOpen)
- {
- port.Open();
- if (chbMovCam.Checked == true)
- {
- port.WriteLine("3");
- }
- if (chbPIR.Checked == true)
- {
- port.WriteLine("4");
- contSegui.Enabled = true;
- }
- }
- if (port.IsOpen)
- {
- if (chbMovCam.Checked == true)
- {
- port.WriteLine("3");
- }
- if (chbPIR.Checked == true)
- {
- port.WriteLine("4");
- }
- port.Close();
- verif = true;
- btnAceptar.Enabled = true;
- }
- }
- catch (Exception a)
- {
- MessageBox.Show("A ocurrido un error durante la inicialización de la comunicación del programa con arduino, el error es el siguiente: \n\r\n\r" + a + "\n\r\n\rSi Este mensaje le aparece repetidas comuniquese con el EstaQueArreglamosSuProblema_Kpo@gmail.com \n\rgracias por su atención. ", "No se ha podido iniciar la comunicación de puerto");
- }
- portcomu = Convert.ToString(cmbPort.SelectedItem);
- }
- /** LISTO **/
- private void btnAceptar_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("¿Está seguro?\n\rSi se módifica la configuración puede haber errores", "Aceptar configuración", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- bool probando = false;
- if (verif == true)
- {
- contMov.Enabled = true;
- this.Hide();
- portcomu = Convert.ToString(cmbPort.SelectedItem);
- }
- else
- {
- string puerto = Convert.ToString(cmbPort.SelectedItem);
- port = new SerialPort(puerto, 9600);
- try
- {
- if (!port.IsOpen)
- {
- port.Open();
- }
- if (port.IsOpen)
- {
- port.Close();
- probando = true;
- }
- if (probando == true)
- {
- this.Hide();
- portcomu = Convert.ToString(cmbPort.SelectedItem);
- }
- else
- {
- MessageBox.Show("A ocurrido un error en la configuración, por favor, revice que todo este corretamente puesto.", "Error en la configuración");
- }
- }
- catch (Exception n)
- {
- MessageBox.Show("A ocurrido un error durante la inicialización de la comunicación del programa con arduino, el error es el siguiente: \n\r\n\r" + n + "\n\r\n\rSi Este mensaje le aparece repetidas comuniquese con el EstaQueArreglamosSuProblema_Kpo@gmail.com \n\rgracias por su atención. ", "No se ha podido iniciar la comunicación de puerto");
- }
- }
- }
- }
- /** LISTO **/
- private void btnCancelar_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("¿Está seguro de cancelar?", "Cancelar", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- this.Hide();
- portcomu = Convert.ToString(cmbPort.SelectedItem);
- }
- }
- /** LISTO **/
- private void contMov_Tick(object sender, EventArgs e)
- {
- if (chbMovCam.Checked == true)
- {
- string puerto = Convert.ToString(cmbPort.SelectedItem);
- try
- {
- port = new SerialPort(puerto, 9600);
- if (!port.IsOpen)
- {
- port.Open();
- Console.WriteLine("3");
- port.Close();
- }
- else
- {
- Console.WriteLine("3");
- port.Close();
- }
- }
- catch (Exception a)
- {
- MessageBox.Show("A ocurrido un error durante la inicialización de la comunicación del programa con arduino, el error es el siguiente: \n\r\n\r" + a + "\n\r\n\rSi Este mensaje le aparece repetidas comuniquese con el EstaQueArreglamosSuProblema_Kpo@gmail.com \n\rgracias por su atención. ", "No se ha podido iniciar la comunicación de puerto");
- }
- }
- }
- /** LISTO **/
- private string puertocomu()
- {
- return portcomu;
- }
- private void fmConfig_FormClosing(object sender, FormClosingEventArgs e)
- {
- Properties.Settings.Default.chbMVRecord = chbMovCam.Checked;
- Properties.Settings.Default.chbPIRRecord = chbPIR.Checked;
- Properties.Settings.Default.Save();
- }
- private void contSegui_Tick(object sender, EventArgs e)
- {
- if (chbPIR.Checked == true)
- {
- string puerto = Convert.ToString(cmbPort.SelectedItem);
- try
- {
- port = new SerialPort(puerto, 9600);
- if (!port.IsOpen)
- {
- port.Open();
- Console.WriteLine("4");
- port.Close();
- }
- else
- {
- Console.WriteLine("4");
- port.Close();
- }
- }
- catch (Exception a)
- {
- MessageBox.Show("A ocurrido un error durante la inicialización de la comunicación del programa con arduino, el error es el siguiente: \n\r\n\r" + a + "\n\r\n\rSi Este mensaje le aparece repetidas comuniquese con el EstaQueArreglamosSuProblema_Kpo@gmail.com \n\rgracias por su atención. ", "No se ha podido iniciar la comunicación de puerto");
- }
- }
- }
- public override string ToString()
- {
- if (chbMovCam.Checked == true)
- {
- return String.Concat(Convert.ToString(chbMovCam.Checked));
- }
- else
- {
- if (chbPIR.Checked == true)
- {
- return String.Concat(Convert.ToString(chbMovCam.Checked));
- }
- else
- {
- return String.Concat(Convert.ToString(false));
- }
- }
- }
- /*private void chbMovCam_CheckedChanged(object sender, EventArgs e)
- {
- if (chbPIR.Checked == true)
- {
- chbPIR.Checked = false;
- chbMovCam.Checked = true;
- }
- else
- {
- chbMovCam.Checked = true;
- }
- }
- private void chbPIR_CheckedChanged(object sender, EventArgs e)
- {
- if (chbMovCam.Checked == true)
- {
- chbMovCam.Checked = false;
- chbPIR.Checked = true;
- }
- else
- {
- chbPIR.Checked = true;
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement