本人菜鸟跪求解答真心希望大侠能帮帮,c#串口通信程序连接两台计算机。程序是网上下载的,运行没问题,可是好像用不了,不知道问题出在哪里,真心希望各位大侠可以帮帮我
真心希望各位大侠能帮帮我,谢谢了
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;
namespace SerialComMaster
{
public partial class Form1 : Form
{
SerialPort sp = null;
bool isOpen = false;
bool isSetProperty = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
this.MaximizeBox = false;
for (int i = 0; i < 256; i++)
{
comboBox1.Items.Add("COM" + (i + 1).ToString());
}
comboBox1.SelectedIndex = 0;
//列出常用的波特率
comboBox2.Items.Add("300");
comboBox2.Items.Add("600");
comboBox2.Items.Add("1200");
comboBox2.Items.Add("2400");
comboBox2.Items.Add("4800");
comboBox2.Items.Add("9600");
comboBox2.Items.Add("19200");
comboBox2.Items.Add("38400");
comboBox2.Items.Add("43000");
comboBox2.Items.Add("56000");
comboBox2.Items.Add("57600");
comboBox2.Items.Add("115200");
comboBox2.SelectedIndex = 5;
//列出停止位
comboBox3.Items.Add("0");
comboBox3.Items.Add("1");
comboBox3.Items.Add("1.5");
comboBox3.Items.Add("2");
comboBox3.SelectedIndex = 1;
//列出数据位
comboBox5.Items.Add("8");
comboBox5.Items.Add("7");
comboBox5.Items.Add("6");
comboBox5.Items.Add("5");
comboBox5.SelectedIndex = 0;
//列出奇偶校验位
comboBox4.Items.Add("无");
comboBox4.Items.Add("奇校验");
comboBox4.Items.Add("偶校验");
comboBox4.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{//检测哪些串口可用
comboBox1.Items.Clear();
for (int i = 0; i < 256; i++)
{
try
{
SerialPort sp = new SerialPort("COM" + (i + 1).ToString());
sp.Open();
sp.Close();
comboBox1.Items.Add("COM" + (i + 1).ToString());
}
catch (Exception)
{
continue;
}
}
}
private bool CheckPortSetting()
{//检查串口是否设置