这里的串行通信端口显示错误it not be accessed .....But串行通信端口在arduino中工作正常,所以这不可能是端口问题,也不是驱动程序的问题,驱动程序已经更新并且工作正常,所以问题可能出在代码.....i中,我是C#的新手。
public partial class Form1 : Form
{
private SerialPort myport;
private string in_data;
public Form1()
{
InitializeComponent();
}
private void Start_Click(object sender, EventArgs e)
{
myport = new SerialPort();
myport.BaudRate = 19200;
myport.PortName = pn.Text;
myport.Parity = Parity.None;
myport.DataBits = 8;
myport.StopBits = StopBits.One;
myport.DataReceived += myport_DataReceived;
try
{
myport.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!!");
}
}
void myport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
*in_data = myport.ReadLine();***
this.Invoke(new EventHandler(displaydata_event));
}
private void displaydata_event(object sender, EventArgs e)
{
string[] newData = in_data.Split(',');
bv.Text = newData[0];
bi.Text = newData[1];
pv.Text = newData[2];
pi.Text = newData[3];
t.Text = newData[4];
}
}发布于 2015-06-08 19:18:48
无法访问它
这可能表示该端口不存在或已在使用中。可能另一个应用程序已经在此端口上侦听。(arduino?)
此处描述了Comport.Open()异常:MSDN SerialPort.Open Method
https://stackoverflow.com/questions/30706516
复制相似问题