Advertisement
Guest User

onoff v

a guest
Nov 26th, 2014
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. using System;
  2. 2.  using System.Collections.Generic;
  3. 3.  using System.ComponentModel;
  4. 4.  using System.Data;
  5. 5.  using System.Drawing;
  6. 6.  using System.Linq;
  7. 7.  using System.Text;
  8. 8.  using System.Threading.Tasks;
  9. 9.  using System.Windows.Forms;
  10. 10. using System.IO.Ports;
  11. 11.  
  12. 12.  
  13. 13. namespace zapnuti_led
  14. 14. {
  15. 15.     public partial class Form1 : Form
  16. 16.     {
  17. 17.         private SerialPort myport;
  18. 18.  
  19. 19.         public Form1()
  20. 20.         {
  21. 21.             InitializeComponent();
  22. 22.             init();
  23. 23.         }
  24. 24.  
  25. 25.         private void On_btn_Click(object sender, EventArgs e)
  26. 26.         {
  27. 27.             myport.WriteLine("ON");
  28. 28.  
  29. 29.             On_btn.Enabled = false;
  30. 30.             Off_btn.Enabled = true;
  31. 31.             pictureBox1.Image = zapnuti_led.Properties.Resources.zarovka;
  32. 32.         }
  33. 33.  
  34. 34.         private void init()
  35. 35.         {
  36. 36.             try
  37. 37.             {
  38. 38.                 myport = new SerialPort();
  39. 39.                 myport.BaudRate = 9600;
  40. 40.                 myport.PortName = "COM3";
  41. 41.                 myport.Open();
  42. 42.             }
  43. 43.             catch (Exception)
  44. 44.             {
  45. 45.                 MessageBox.Show("Error!!");
  46. 46.             }
  47. 47.  
  48. 48.             On_btn.Enabled = true;
  49. 49.             Off_btn.Enabled = false;
  50. 50.            
  51. 51.         }
  52. 52.  
  53. 53.         private void Off_btn_Click(object sender, EventArgs e)
  54. 54.         {
  55. 55.             myport.WriteLine("OFF");
  56. 56.  
  57. 57.             On_btn.Enabled = true;
  58. 58.             Off_btn.Enabled = false;
  59. 59.             pictureBox1.Image = zapnuti_led.Properties.Resources.zarovka1;
  60. 60.         }
  61. 61.     }
  62. 62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement