日期:2014-05-17 浏览次数:20740 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Collections;
using System.Threading;
using System.Timers;
using System.Xml;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using System.Configuration;
namespace 串口通信
{
public partial class Form1 : Form
{
public bool isFirstTimeToStart = true;
private int timeStamp = 50;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 初始化串口属性
/// </summary>
public void InitializeSerialPort()
{
if (isFirstTimeToStart == true)
{
port.DataBits = 8;
port.PortName = ConfigurationManager.AppSettings["port"].ToString();
port.BaudRate = 19200;
port.DiscardNull = false;
port.DtrEnable = false;
port.Handshake = Handshake.None;
port.Parity = Parity.None;
port.ParityReplace = Convert.ToByte("63");
port.RtsEnable = false;
port.StopBits = StopBits.One;
isFirstTimeToStart = false;
}
}
private void comboBox1_DropDown(object sender, EventArgs e)
{
///加载计算机上所有的COM串口
comboBox1.Items.Clear();
&