|
发表于 2024-8-19 01:16:16
|
显示全部楼层
#include <Array.au3>
#include <CommMG.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Opt("GUICloseOnESC", 0) ;1 = 點擊 Esc 鍵關閉, 0 = 點擊 Esc 鍵不關閉
Opt("TrayIconHide", 0) ;0 = 顯示托盤圖標, 1 = 隱藏托盤圖標
Opt('MustDeclareVars', 1);1 = 變量不需預先聲明, 1 = 變量必需預先聲明
Local $hGUI = GUICreate("com_port-check", 200, 200)
GUISetState(@SW_SHOW)
CommLoad()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE ;離開
_CommCloseport()
EXIT
EndSwitch
WEnd
Func CommLoad() ;commPort_Load
Local $portnum = "" , $portnum_temp = "" , $portlist1 = "", $ComPort_Total
Local $portlist = _CommListPorts(0)
_ArrayDisplay($portlist)
If $portlist[0] >= 1 Then
For $pl = 1 To $portlist[0]
$portlist1 = _ComGetPortNames($portlist[$pl])
$portnum_temp = StringReplace($portlist[$pl], "COM", '')
$ComPort_Total &= $portnum_temp & "|"
Next
_CommSetTimeouts(5,5,5,5,5)
Local $sz2 = StringSplit($ComPort_Total,'|',3)
_ArraySort($sz2 ) ;埠位排序
$ComPort_Total = ""
For $pl = 1 To (UBound($sz2,1)- 1)
$ComPort_Total &= $sz2[$pl]& "|"
Next
MsgBox(0,"",$ComPort_Total)
Else
MsgBox(0,"串列Port錯誤","無串列Port,程式關閉。")
Exit
EndIf
EndFunc
:---- 給你參考看看 |
|