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_movimiento_LPT_01 { public partial class Form2 : Form { class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern char Input(int adress); } public Form2() { InitializeComponent(); } DateTime hora; Boolean estado = false; SoundPlayer puerta; int puerto; private void Form2_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( "Movimientos.csv", FileMode.Append, FileAccess.Write, FileShare.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("PIR 1," + hora.ToString("dd/MM/yy") + "," + hora.ToString("HH:mm:ss")); sw.Close(); } catch (Exception err) { MessageBox.Show("Exception: " + err.Message); } puerta = new SoundPlayer("deteccion.wav"); puerta.Play(); estado = false; } if (!estado && (puerto == 126)) estado = true; } private void btnArchivo_Click(object sender, EventArgs e) { Process.Start("Movimientos.csv"); } } }
Descarga del archivo
Descargar archivo