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.Threading.Tasks;
- using System.Windows.Forms;
- namespace Servo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- Porta.Open();
- }
- catch
- {
- MessageBox.Show("Cabo desconectado", "Erro");
- Close();
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- if (Porta.IsOpen)
- {
- Porta.Close();
- }
- }
- catch
- { }
- }
- private void Porta_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
- {
- BeginInvoke(new Action(() =>
- {
- try
- {
- textBox1.Text = Porta.ReadLine();
- }
- catch { }
- }));
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- Porta.Write('0'+textBox2.Text + "\n\r");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement