Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- SerialPort seriPort;
- public Form1()
- {
- InitializeComponent();
- seriPort = new SerialPort();
- seriPort.BaudRate = 9600;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- timer1.Start();
- try
- {
- seriPort.PortName = textBox1.Text;
- if (!seriPort.IsOpen)
- MessageBox.Show("Bağlantı Kuruldu");
- }
- catch
- {
- MessageBox.Show("Bağlantı Kurulmadı!");
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- seriPort.Write("temperature");
- float sıcaklık = Convert.ToByte(seriPort.ReadExisting());
- textBox2.Text = sıcaklık.ToString();
- comboBox1.Items.Add(textBox2.Text);
- System.Threading.Thread.Sleep(100);
- }
- catch (Exception) {}
- }
- private void button2_Click(object sender, EventArgs e)
- {
- timer1.Stop();
- seriPort.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement