日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

winform访问被拒绝_c#串口提示端口访问被拒绝

發(fā)布時(shí)間:2024/3/12 C# 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 winform访问被拒绝_c#串口提示端口访问被拒绝 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

如下代碼請教大神====使用是串口調(diào)試助手進(jìn)行調(diào)試,但是在調(diào)試的時(shí)候出現(xiàn)老是提示“端口訪問拒絕”,如果把串口調(diào)試助手關(guān)掉就不出現(xiàn)這個(gè)問題,請問如何解決====usingSystem;usingSyst...

如下代碼請教大神

====

使用是串口調(diào)試助手進(jìn)行調(diào)試,但是在調(diào)試的時(shí)候出現(xiàn)老是提示“端口訪問拒絕”, 如果把串口調(diào)試助手關(guān)掉就不出現(xiàn)這個(gè)問題,請問如何解決

====

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;

using System.IO.Ports;

namespace WindowsFormsApplication3

{

public partial class Form1 : Form

{

SerialPort serialPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); //初始化串口設(shè)置

public delegate void Displaydelegate(byte[] InputBuf);

Byte[] OutputBuf = new Byte[128];

public Displaydelegate disp_delegate;

public Form1()

{

disp_delegate = new Displaydelegate(DispUI);

serialPort1.DataReceived += new SerialDataReceivedEventHandler(Comm_DataReceived);

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

try

{

if (button1.Text == "打開")

{

if (!serialPort1.IsOpen)

{ serialPort1.Open(); }

button1.Text = "關(guān)閉";

}

else

{

serialPort1.Close();

button1.Text = "打開";

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "錯(cuò)誤提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

}

}

void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)

{

Byte[] InputBuf = new Byte[128];

try

{

serialPort1.Read(InputBuf, 0, serialPort1.BytesToRead); //讀取緩沖區(qū)的數(shù)據(jù)直到“}”即0x7D為結(jié)束符

//InputBuf = UnicodeEncoding.Default.GetBytes(strRD); //將得到的數(shù)據(jù)轉(zhuǎn)換成byte的格式

System.Threading.Thread.Sleep(50);

this.Invoke(disp_delegate, InputBuf);

}

catch (TimeoutException ex) //超時(shí)處理

{

MessageBox.Show(ex.ToString());

}

}

public void DispUI(byte[] InputBuf)

{

//textBox1.Text = Convert.ToString(InputBuf);

ASCIIEncoding encoding = new ASCIIEncoding();

richTextBox1.Text = encoding.GetString(InputBuf);

}

}

}

展開

總結(jié)

以上是生活随笔為你收集整理的winform访问被拒绝_c#串口提示端口访问被拒绝的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。