前幾天和你碰到一樣的問題了,不要用port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);接收。自己寫一個委托!port.DataReceived回傳太慢
public class SerialPortConnection
{
Thread thread;//創建執行緒物件
private static SerialPort _port = new SerialPort();
public delegate void ComPortReceiveHandler(byte[] data);
public event ComPortReceiveHandler ComPortReceiveEvent;
public void Int()
{
_port.PortName = "COM4";
_port.BaudRate = 38400;
_port.Parity = System.IO.Ports.Parity.None;
_port.DataBits = 8;
_port.StopBits = System.IO.Ports.StopBits.One;
_port.Open();
thread = new Thread(() =>//新開執行緒,執行接收資料操作
{
while (true)//如果標識為true
{
try
{
SerialPortConnection ser = new SerialPortConnection();
ser.Int();
ser.ComPortReceiveEvent += Ser_ComPortReceiveEvent;
private void Ser_ComPortReceiveEvent(byte[] data)
{
}
uj5u.com熱心網友回復:
你配置的是發送端,而不是接收端
感謝回復!
下面這段話是從官網在線檔案上面復制下來的:
SerialPort.ReceivedBytesThreshold 屬性
定義
命名空間:
System.IO.Ports
程式集:
System.dll
獲取或設定 DataReceived 事件發生前內部輸入緩沖區中的位元組數。
難道說的不是接收端嗎?
前幾天和你碰到一樣的問題了,不要用port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);接收。自己寫一個委托!port.DataReceived回傳太慢
public class SerialPortConnection
{
Thread thread;//創建執行緒物件
private static SerialPort _port = new SerialPort();
public delegate void ComPortReceiveHandler(byte[] data);
public event ComPortReceiveHandler ComPortReceiveEvent;
public void Int()
{
_port.PortName = "COM4";
_port.BaudRate = 38400;
_port.Parity = System.IO.Ports.Parity.None;
_port.DataBits = 8;
_port.StopBits = System.IO.Ports.StopBits.One;
_port.Open();
thread = new Thread(() =>//新開執行緒,執行接收資料操作
{
while (true)//如果標識為true
{
try
{