Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2013
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 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 WindowsFormsApplication3
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             byte cmd = 0x10;
  23.             serialPort1.BaudRate = 9600;
  24.             serialPort1.PortName = "COM1";
  25.             serialPort1.Open();
  26.             serialPort1.Write(new byte[] {cmd},0,1);
  27.         }
  28.  
  29.         private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  30.         {
  31.             MessageBox.Show("Prisli data");
  32.         }
  33.  
  34.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  35.         {
  36.             if (serialPort1.IsOpen)
  37.             {
  38.                 serialPort1.Close();
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement