Skip to content

Instantly share code, notes, and snippets.

@starlightme
Created October 15, 2015 14:54
Show Gist options
  • Save starlightme/b5d8957b9aaf70ed0f28 to your computer and use it in GitHub Desktop.
Save starlightme/b5d8957b9aaf70ed0f28 to your computer and use it in GitHub Desktop.
串口通讯 -- 上位机端
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
{
try
{
serialPort1.Open();
serialPort1.Write("T");
serialPort1.Close();
}
catch
{
MessageBox.Show("There was an error. Please make sure that the correct port was selected, and the device, plugged in.");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment