Advertisement
renglix

Visual servo

Apr 24th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Servo
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20.  
  21.  
  22. private void Form1_Load(object sender, EventArgs e)
  23. {
  24. try
  25. {
  26. Porta.Open();
  27. }
  28. catch
  29. {
  30. MessageBox.Show("Cabo desconectado", "Erro");
  31. Close();
  32. }
  33. }
  34.  
  35. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  36. {
  37. try
  38. {
  39. if (Porta.IsOpen)
  40. {
  41. Porta.Close();
  42. }
  43. }
  44. catch
  45. { }
  46. }
  47.  
  48. private void Porta_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  49. {
  50. BeginInvoke(new Action(() =>
  51. {
  52. try
  53. {
  54.  
  55. textBox1.Text = Porta.ReadLine();
  56.  
  57.  
  58.  
  59. }
  60. catch { }
  61. }));
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. private void button1_Click_1(object sender, EventArgs e)
  69. {
  70.  
  71. Porta.Write('0'+textBox2.Text + "\n\r");
  72.  
  73.  
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement