關于串口通訊的問題:

成都創(chuàng)新互聯(lián)10多年企業(yè)網站制作服務;為您提供網站建設,網站制作,網頁設計及高端網站定制服務,企業(yè)網站制作及推廣,對建筑動畫等多個方面擁有多年的網站推廣經驗的網站建設公司。
很明顯,你還不知道(不會、不習慣)使用事件驅動的方式接收數(shù)據(jù)。
建議你仔細看看串口組件(無論VB6還是VB.net)的OnComm事件,你的問題很容易解決。
關于以太網通訊:
在TCP通訊中端口確實可以重用,你百度一下“TCP端口重用”能查到很多示例。
但絕大多數(shù)情況下不推薦端口重用,而應該采取服務器端建立連接池的方法。
或者,干脆不用TCP,用UDP解決也可以。
很有意思。
原文數(shù)據(jù)全為:“00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ”
加密后變成了:“09 51 55 F4 FB 10 6F A4 D3 E8 87 46 F8 2F 49 CD ; ”
得出這樣的結果是有很多方法都可以實現(xiàn)的:
比如每個原數(shù)上加上個常數(shù)就可以了。
00+09=09;得出第一組加密后的數(shù)值
00+51=51;得出第二組加密后的數(shù)值
...
00+CD=CD;得出第16組加密后的數(shù)值.
加密的方法還有很多,不過這種最簡單。
還有就是你給的原文太單一了,不能夠更好的分析數(shù)據(jù)的規(guī)律。
如果你能把原文改為如下這段代碼再去加密一下,再把加密結果貼上來看一下就好多了。
00000140h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ;
00000150h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ;
00000160h: 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 ; 00000170h: 00 10 20 30 40 50 60 70 80 90 A0 B0 C0 D0 E0 F0 ;
00000180h: 11 11 11 11 11 22 22 22 22 22 22 EE EE EE FF FF ;
以上是單片機高手團為您解答。
如果還沒解決你的問題,可以加我百度HI賬號。
用 vb.net socket通信
Dim th As Threading.Thread
2 Dim tcpl As System.Net.Sockets.TcpListener
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6 th.Start()
7 End Sub
8
9 Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10 Try
11 If IP "" Then
12 Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13 Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14 Dim reqStream As New IO.StreamWriter(tcpStream)
15 reqStream.Write(SendMsg)
16 reqStream.Flush()
17 tcpStream.Close()
18 tcpc.Close()
19 End If
20 Catch ex As Exception
21 MsgBox(ex.Message.ToString)
22 End Try
23 End Sub
24 Private Sub MyListen()Sub MyListen()
25 Try
26 Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27 tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28 tcpl.Start()
29 While True
30 Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31 Dim MyBuffer(1024) As Byte
32 Dim i As Integer
33 i = s.Receive(MyBuffer)
34 If i 0 Then
35 Dim lstrRec As String
36 Dim j As Integer
37 For j = 0 To i - 1
38 TextBox1.Text += Chr(MyBuffer(j)) ","
39 Next
40 End If
41 End While
42 Catch ex As Exception
43 MsgBox(ex.Message.ToString)
44 End Try
45 End Sub
46
47 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48 SendMessage("192.168.0.61", TextBox2.Text)
49 End Sub
使用Winsock控件進行的
Public Function f(ByVal x As Double) As Double
Dim y As Double
y = x ^ 3 - 5 * x ^ 2 + 16 * x - 80
Return y
End Function
Public Function xpoint(ByVal x1 As Double, ByVal x2 As Double) As Double
Dim x As Double
x = (x1 * f(x2) - x2 * f(x1)) / (f(x2) - f(x1))
Return x
End Function
Public Function root(ByVal x1 As Double, ByVal x2 As Double) As Double
Dim x As Double, y1 As Double, y As Double
y1 = f(x1)
Do
x = xpoint(x1, x2)
y = f(x)
If y * y1 0 Then
y1 = y
x1 = x
Else
x2 = x
End If
Loop Until y = 0.0001
Return x
End Function
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim st As String = "", pb As Integer = 11, sum As Integer = 0
Dim f1 As Double, f2 As Double, x As Double, x1 As Double, x2 As Double
Do
x1 = Val(InputBox("請輸入第一個數(shù)字"))
x2 = Val(InputBox("請輸入第二個數(shù)字"))
f1 = f(x1)
f2 = f(x2)
Loop Until f1 * f2 = 0
x = root(x1, x2)
TextBox6.Text = x.ToString
End Sub
名稱欄目:vb.net網口通信,vbnet接口
本文鏈接:http://chinadenli.net/article30/dsgjpso.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供網站導航、微信小程序、網站設計、軟件開發(fā)、、用戶體驗
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)