lectura serial

Upload: cristian-rodriguez

Post on 10-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

serial

TRANSCRIPT

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication3{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.serialPort1.Open(); CheckForIllegalCrossThreadCalls = false; } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { this.serialPort1.Close(); } private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { if (this.serialPort1.ReadChar().Equals('F')) { this.label1.Text = "ADELANTE"; this.label2.Text = "N/A"; this.label3.Text = "N/A"; this.label4.Text = "N/A"; this.label5.Text = "N/A"; } if (this.serialPort1.ReadChar().Equals('B')) { this.label1.Text = "N/A"; this.label2.Text = "ATRAS"; this.label3.Text = "N/A"; this.label4.Text = "N/A"; this.label5.Text = "N/A"; } if (this.serialPort1.ReadChar().Equals('R')) { this.label1.Text = "N/A"; this.label2.Text = "N/A"; this.label3.Text = "DERECHA"; this.label4.Text = "N/A"; this.label5.Text = "N/A"; } if (this.serialPort1.ReadChar().Equals('L')) { this.label1.Text = "N/A"; this.label2.Text = "N/A"; this.label3.Text = "N/A"; this.label4.Text = "IZQUIERDA"; this.label5.Text = "N/A"; } if (this.serialPort1.ReadChar().Equals('S')) { this.label1.Text = "N/A"; this.label2.Text = "N/A"; this.label3.Text = "N/A"; this.label4.Text = "N/A"; this.label5.Text = "STOP"; } } private void timer1_Tick(object sender, EventArgs e) { this.label1.Text = ""; this.label2.Text = ""; this.label3.Text = ""; this.label4.Text = ""; this.label5.Text = ""; } }}