1、點擊右側(cè)的網(wǎng)絡(luò)連接,在彈出的對話框中點擊打開網(wǎng)絡(luò)和共享中心。
成都創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的桐鄉(xiāng)網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
2、在網(wǎng)絡(luò)和共享中心界面中點擊更改適配器設(shè)置。
3、進入網(wǎng)絡(luò)連接界面,右鍵本地連接。
4、在彈出的菜單中選擇屬性。
5、在本地連接屬性界面中點擊配置按鈕。
6、切換到高級選項卡,在屬性列表中找到并點擊網(wǎng)絡(luò)地址,在右側(cè)輸入修改后的網(wǎng)絡(luò)地址,點擊確定按鈕。
7、使用命令提示符,輸入Ipconfig-all,可以查看修改后的物理地址。
如下是檢測串口是否存在,是否被占用的代碼:
Option Explicit
Dim a As Integer
Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeBinary '采用二進制傳輸
MSComm1.InBufferCount = 0 '清空接受緩沖區(qū)
MSComm1.OutBufferCount = 0 '清空傳輸緩沖區(qū)
MSComm1.RThreshold = 1 '產(chǎn)生MSComm事件
MSComm1.InBufferSize = 1024
Shape1.FillStyle = 0
OpenPortNum
End Sub
Private Sub OpenPortNum()
On Error GoTo uerror
For a = 1 To 16
MSComm1.CommPort = a
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Print "可用Com號= "; a
MSComm1.PortOpen = False
End If
Next
Exit Sub
uerror:
Print "出錯或占用Com號= "; a
Resume Next
End Sub
如要探測某個COM口是否有數(shù)據(jù)輸入則需在打開某個串口后,用OnComm事件來接收.
using?System.Net;
if(!string.IsNullOrEmpty(txtPort.Text))
{
IPAddress?ip?=?IPAddress.Parse(txtIp.Text);
IPEndPoint?point=new?IPEndPoint(ip,int.Parse(txtPort.Text));
try
{
TcpClient?tcp=new?TcpClient();
tcp.Connect(point);
MessageBox.Show("端口打開");
}catch(Exception?ex)
{
MessageBox.Show(ex.Message);
}
}
通過以上這個方法,只能判斷你是否能鏈接這個端口。
通過以下這個方法,能判斷端口是否開放
public?static?void?GetTcpConnections()?
{?
IPGlobalProperties?properties?=?IPGlobalProperties.GetIPGlobalProperties();?
TcpConnectionInformation[]?connections?=?properties.GetActiveTcpConnections();?
string?str="";
foreach?(TcpConnectionInformation?t?in?connections)?
{?
str+="Local?endpoint:"+?t.LocalEndPoint.ToString()+",";?
str+="Remote?endpoint:"+?t.RemoteEndPoint.ToString()+",";?
str+=t.State.ToString()+",";?
}?
MessageBox.Show(str);
}
j = 0
For i = 1 To 16 Step 1
If comISP.PortOpen = True Then '先關(guān)閉串口
comISP.PortOpen = False
End If
comISP.CommPort = i
On Error Resume Next '說明當一個運行時錯誤發(fā)生時,控件轉(zhuǎn)到緊接著發(fā)生錯誤的語句之后的語句,并在此繼續(xù)運行。訪問對象時要使用這種形式而不使用 On Error GoTo。
comISP.PortOpen = True
If Err.Number 8002 Then '無效的串口號。這樣可以檢測到虛擬串口,如果用Err.Number = 0的話檢測不到虛擬串口
If j = 0 Then
j = i
End If
cboPort.AddItem "COM" i '生成串口選擇列表
End If
comISP.PortOpen = False
Next i
If j = 1 Then
cboPort.Text = "COM" j '自動打開可用的最小串口號
comISP.CommPort = j
comISP.PortOpen = True
cmdOpenCom.Caption = "關(guān)閉串口"
shpCOM.FillColor = vbGreen
If Err.Number = 8005 Then '串口已打開,vbExclamation '
comISP.PortOpen = False
cboPort.Text = ""
cmdOpenCom.Caption = "打開串口"
shpCOM.FillColor = vbRed
End If
End If
文章標題:vb.net判斷端口 vbnet接口
分享地址:http://vcdvsql.cn/article38/doicesp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站設(shè)計公司、微信小程序、App設(shè)計、網(wǎng)站收錄、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)