ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Diagnostics; using System.Media; using System.Runtime.InteropServices; namespace Registro_de_puerta_LPT_01 { public partial class Form1 : Form { class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern char Input(int adress); } public Form1() { InitializeComponent(); } DateTime hora; Boolean estado = false; SoundPlayer puerta; int puerto; private void Form1_Load(object sender, EventArgs e) { hora = DateTime.Now; lblHora.Text = hora.ToString("HH:mm:ss"); } private void timer1_Tick(object sender, EventArgs e) { hora = DateTime.Now; lblHora.Text = hora.ToString("HH:mm:ss"); puerto = ControlPort.Input(0x379); if (estado && (puerto == 62)) { try { FileStream fs = new FileStream( "Registros.txt", FileMode.Append, FileAccess.Write, FileShare.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("Puerta cerrada -> " + hora.ToString()); sw.Close(); } catch (Exception err) { MessageBox.Show("Exception: " + err.Message); } puerta = new SoundPlayer("cerrada.wav"); puerta.Play(); estado = false; } if (!estado && (puerto == 126)) { try { FileStream fs = new FileStream( "Registros.txt", FileMode.Append, FileAccess.Write, FileShare.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("Puerta abierta -> " + hora.ToString()); sw.Close(); } catch (Exception err) { MessageBox.Show("Exception: " + err.Message); } puerta = new SoundPlayer("abierta.wav"); puerta.Play(); estado = true; } } private void btnArchivo_Click(object sender, EventArgs e) { Process.Start("Registros.txt"); } } }
Descarga del archivo
Descargar archivo