生產中經常會使用到串列埠來處理資料,在此做一下記錄:
串列埠選擇框
波特率選擇框
開啟、關閉按鈕
大致如下:
注意紅色的表示的是串列埠開啟的狀態,為了便於區分當前串列埠狀態。紅色表示關閉,綠色表示開啟
/// /// 自動載入獲取串列埠
///
private void getcomlist()
if (cbbcom.properties.items.count > 0)
}/// /// 定義的串列埠
///
serialport comdevice = new serialport();
/// /// 串列埠開啟/關閉事件
///
///
///
private void btncom_click(object sender, eventargs e)
if (btncom.tag.tostring() == "0")
catch (exception ex)
btncom.text = "關閉串列埠";
btncom.tag = "1";
cbbcom.enabled = false;
piccomstatus.image = properties.resources.green;
comdevice.datareceived += new serialdatareceivedeventhandler(comdevice_datareceived);
}else
catch (exception ex)
btncom.text = "開啟串列埠";
btncom.tag = "0";
cbbcom.enabled = true;
piccomstatus.image = properties.resources.red;}}
catch (exception ex)
}
private stringbuilder builder = new stringbuilder();
/// /// 串列埠的datareceived事件
///
///
///
private void comdevice_datareceived(object sender, serialdatareceivedeventargs e)
else if (builder[builder.length - 2] == '\r' && builder[builder.length - 1] == '\n')
}catch
}));
}/// /// 串列埠資料處理
///
///
private void analyse(string data)
");}
WinForm 串列埠通訊
ialport 串列埠資源 常用屬性 baudrate 此串列埠上要使用的波特率 databits 每傳送 接收乙個位元組的資料位數目 dtrenable 在通訊過程中是否啟用資料終端就緒 str 行 portname 要開啟的通訊埠的名稱 rtsenable 在通訊過程中是否啟用請求傳送 rts ...
winform 操作實踐
想要達到的狀態是 點選開始按鈕,進度條跑完之前,資料表資料瘋狂的顯示變化,進度條也一直更進,且form表單拖動不卡頓,像德芙一樣絲滑。點選開始按鈕,label 出現字型提示 1 private void btnstart click object sender,eventargs e 2 5 pub...
串列埠操作類
using system using system.collections.generic using system.linq using system.text using system.io.ports namespace communicationcomm region 傳送接收資料 publ...