Created
May 12, 2017 17:58
-
-
Save HectorTorres/12bd1db5be58aa63c65ac65fb9d1b2a2 to your computer and use it in GitHub Desktop.
Sensor de temperatura y control con un PIC PIC16F887
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Diagnostics; | |
using System.Threading; | |
using System.Windows.Forms; | |
using System.Windows.Forms.DataVisualization.Charting; | |
namespace SerialPort | |
{ | |
public partial class Form1 : Form | |
{ | |
string RxString; | |
int y; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public void timer1_Tick(object sender, EventArgs e) | |
{ | |
this.tiempo.Text = DateTime.Now.ToString("dddd d MMMM yyyy \n HH:mm.ss "); | |
Di(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
serialPort1.PortName ="COM3"; | |
serialPort1.BaudRate =9600; | |
try | |
{ | |
serialPort1.Open(); | |
if (serialPort1.IsOpen) | |
{ | |
//recibido.Clear(); | |
btStart.Enabled = false; | |
btStop.Enabled = true; | |
textBox1.ReadOnly = false; | |
lStatus.Text = "CONECTADO"; | |
lStatus.ForeColor = Color.Green; | |
cbPorts.Enabled = false; | |
} | |
} | |
catch(Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
} | |
private void Di() | |
{ | |
if (serialPort1.IsOpen) | |
do | |
{ | |
Thread.Sleep(500); | |
y = Convert.ToInt32(RxString); | |
if (y >= 40) | |
{ | |
this.label7.Text = Convert.ToString(y) + ".00 °C"; | |
label7.BackColor = Color.Red; | |
label7.ForeColor = Color.White; | |
this.label9.Text = "ALERTA TEMPERATURA ALTA"; | |
label9.BackColor = Color.Red; | |
label9.ForeColor = Color.Yellow; | |
this.label12.Text = "MOTORES ACTIVADOS"; | |
} | |
else | |
{ | |
if (y < 40 && y >= 10) | |
{ | |
this.label7.Text = Convert.ToString(y) + " °C"; | |
label7.BackColor = Color.Yellow; | |
label7.ForeColor = Color.Red; | |
this.label9.Text = ""; | |
this.label12.Text = "MOTOR 1 ACTIVADO"; | |
} | |
else | |
{ | |
if (y < 10 && y >= -10) | |
{ | |
this.label7.Text = Convert.ToString(y) + " °C"; | |
label7.BackColor = Color.Green; | |
label7.ForeColor = Color.Yellow; | |
this.label9.Text = ""; | |
this.label12.Text = "MOTORES DESACTIVADOS"; | |
} | |
} | |
} | |
} while (!serialPort1.IsOpen); | |
} | |
private void signalRead() | |
{ | |
} | |
private void DisplayText(object sender, EventArgs e) | |
{ | |
textBox1.AppendText(RxString); | |
} | |
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) | |
{ | |
RxString = serialPort1.ReadExisting(); | |
this.Invoke(new EventHandler(DisplayText)); | |
} | |
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) | |
{ | |
// If the port is closed, don't try to send a character. | |
if (!serialPort1.IsOpen) return; | |
// If the port is Open, declare a char[] array with one element. | |
char[] buff = new char[1]; | |
// Load element 0 with the key character. | |
buff[0] = e.KeyChar; | |
// Send the one character buffer. | |
serialPort1.Write(buff, 0, 1); | |
// Set the KeyPress event as handled so the character won't | |
// display locally. If you want it to display, omit the next line. | |
e.Handled = true; | |
} | |
private void Form1_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
if (serialPort1.IsOpen) serialPort1.Close(); | |
} | |
private void btStop_Click(object sender, EventArgs e) | |
{ | |
if (serialPort1.IsOpen) | |
{ | |
serialPort1.Close(); | |
btStart.Enabled = true; | |
btStop.Enabled = false; | |
textBox1.ReadOnly = true; | |
// trackBar1.Enabled = false; | |
//trackBar1.Value = 1; | |
// button1.Enabled = false; | |
cbPorts.Enabled = true; | |
lStatus.Text = "DESCONECTADO"; | |
lStatus.ForeColor = Color.Red; | |
} | |
} | |
private void button1_Click_1(object sender, EventArgs e) | |
{ | |
Application.Exit(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |
Me parecen extraños los ; dentro de una condicion total no me compila en c#.net
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Buenas tardes hector no se si tu creaste este codigo o lo editaste. Pero fijate que tengo el problema en las lineas de los if (63, 75, 85) me da error en las variables < & y > . Bueno , para empezar veo que el codigo dice .c y de la pagina que vengo siguiendo dice que es csharp y total no me corre en c# . Es este codigo c?