Sece II - Hsms
-
date post
11-Apr-2015 -
Category
Documents
-
view
1.386 -
download
4
description
Transcript of Sece II - Hsms
![Page 1: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/1.jpg)
SEMI-SECS ][ HSMS廠區網路實做
指導教授 XXX
班級 XXX
姓名 XXX
學號 XXX
![Page 2: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/2.jpg)
實驗目標• 以二部個人電腦,使用 HSMS 架構,利用
TCP/IP 網路,模擬 Equipment/Host 兩個設備,建立基本訊息交換。
![Page 3: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/3.jpg)
實驗背景網路概要:
TCP/IP network
HOST
EQUIPMENT
Equipment BehaviorMessage ProtocolData Transfer ProtocolPhysical Link
![Page 4: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/4.jpg)
實驗背景(續)訊框結構
![Page 5: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/5.jpg)
實驗背景(續)System Byte
Item format Codes
Byte #
Bit Number 8 7 6 5 4 3 2 1
Description
1234
Format code (octal) | NLBMost significant length byte
Least significant length byts
Format byteLength byte
![Page 6: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/6.jpg)
Example Messages
![Page 7: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/7.jpg)
訊息流程
![Page 8: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/8.jpg)
訊息流程( 續 )
![Page 9: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/9.jpg)
實驗條件
• 硬體設備:二部透過網路連線,架構 TCP/IP 的個人電腦
• 軟體需求:Visual Basic V6.0
Winsock 元件
![Page 10: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/10.jpg)
WishEditor Version 1.1.1Date : 2005/01/20Author : Atwood
![Page 11: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/11.jpg)
SECSEmulator Version 1.5Date : 2001/09/20
Author : 工研院機械所 廖勝泰
![Page 12: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/12.jpg)
HSMS_Emulator
![Page 13: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/13.jpg)
實驗架構
執行1.HSMS_Emsulator(Equipment)2.WishEditor(Equipment)3.SECSEmulator(Equipment)
執行1.HSMS_Emsulator(Host)
Server
Client
![Page 14: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/14.jpg)
實驗流程 流程概述1. 查詢 Server 端電腦網卡 IP 值。2. Server 端執行 MSHS 程式, Role 設定為 Passive ,及連接埠等各項時限參數。3. Client 端執行 MSHS 程式, Role 設定為 Active ,設定所欲連接 Server 電腦的 IP
及 Port 值,並設定各項時限參數。4. 測試與 Server 連線是否成功。5. Client 端執行 WishEditor , Role 設定為 Active ,設定所欲連接 Server 電腦的 I
P 及 Port 值,並設定各項時限參數。6. 測試與 Server 連線是否成功能。7. Client 端執行 SECSEmulator , Role 設定為 Active ,設定所欲連接 Server 電腦
的 IP 及 Port 值,並設定各項時限參數。8. 測試與 Server 連線是否成功能。9. 三組測試程式,分別載入函數功能設定值。10. 由 Server 端分別傳送函數呼叫至三組測試程式,測試回覆是否正確無誤。11. 由三組測試套,分別對 Server 端進行測試,並監看 Server 端之回覆及訊息處理
是否正確無誤。
![Page 15: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/15.jpg)
ServerMSHS
ClientMSHS
ClientWishEditor
ClientSECSEmulator
ConnectionRequestConnectAccept
ConnectionRequest
ConnectionRequestConnectAccept
ConnectAccept
Stream/Function call
reply
Stream/Function call
Stream/Function call
reply
reply
![Page 16: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/16.jpg)
實驗流程 流程步驟1. 在 DOS 式模式下,利用 ipconfig 指令,查詢 Server 端的網卡 IP 。
![Page 17: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/17.jpg)
2. 在 Server 端電腦, 執行實驗程式 HSME.exe , 設定 HSMS 參數, Role : Passive Local Port : 1001
3. 在 Client 端電腦, 再執行另一個 HSMS.exe , 並設定 HSMS 參數, Role : Active Remote IP : 169.254.194.78 Remote Port : 1001
![Page 18: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/18.jpg)
3. 在 Client 端電腦, 執行實驗程式 WishEditor.exe , 設定 HSMS 參數, Role : ActiveClient Remote IP : 169.254.194.78 Remote Port : 1001 Local Port : 1002
4. 在 Client 端電腦, 再執行另一個 SECSEmulator.exe , 並設定 HSMS 參數, Role : Active Remote IP : 169.254.194.78 Remote Port : 1001 Local Port : 1003
![Page 19: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/19.jpg)
實驗結果
![Page 20: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/20.jpg)
![Page 21: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/21.jpg)
使用 NETSTAT.exe 指令,檢查各 PORT 的連接狀況
![Page 22: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/22.jpg)
![Page 23: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/23.jpg)
1. 資料串流雖有長度定義,但沒段落分隔,當傳送品質不穩定時,字元分析將造成程式設計的難度。
2. 功能定義僅接收 WishEditor 及 SECSEmulator 二套軟體所傳送過來的資料,本軟體測試所需功能定義,乃自行在資料庫建立,因 SECS為自定化的規範,且資料量龐大,在考量時間及人力因素,未提供 SML 功能定義的文字檔分析功能。
實驗探討 缺失討論
進階討論HSMS 資料串長度佔 4 個 BYTE, 可傳送最多為 4,294,967,295Byte的元位資料,當網路傳送單一的資料量越大時,產生的網路問題越多,在實際應用上應可研究討論是否縮減單一功能的資料傳送量。
![Page 24: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/24.jpg)
關鍵程式碼設定連線Host :Winsock1(0).Protocol = sckTCPProtocolWinsock1(0).LocalPort = S_LpWinsock1(0).ListenFor I = 1 To 3
Load Winsock1(I) Next I
Equipment :Winsock1(0).RemoteHost = S_Rip$Winsock1(0).RemotePort = S_RpWinsock1(0).Connect
![Page 25: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/25.jpg)
送出位元資料S$ = "00 00 00 0A FF FF 00 00 00 01 99 99 99 99"Call HB(S$, T()) : SystemBytes T()Winsock1(0).SendData T()
Private Sub HB(A$, T() As Byte) Dim R, I As Integer R = Split(A, " ") For I = 0 To UBound(R) T(I) = Val("&H" & R(I)) Next IEnd Sub
Private Function SystemBytes(R() As Byte) Dim T As Single T = Timer Call CopyMemory(R(10), T, 4)End Function
![Page 26: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/26.jpg)
接收資料Winsock1(Index).GetData Rc(), vbByte TB = UBound(Rc()): S = 0Do TL = 0
If TL + 3 + S > TB Then With Data1.Recordset .AddNew .Fields(" 時限 ") = Timer .Fields(" 功能 ") = "InterChr" .Fields(" 描述 ") = "T8" .Fields("SB") = Timer .Update End With Exit Do End If For I = 0 To 3 : TL = TL * 256 + Rc(I + S) : Next I ReDim Rd(TL + 3) For I = 0 To TL + 3 : Rd(I) = Rc(I + S) : Next I
… 分析資料內容 …Loop
![Page 27: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/27.jpg)
解 Item Format CodesBB = Int(A(Id) / 4) ' Bit 876543NLB = A(Id) And 3 ' Bit 21
4-byte integer(signed)For I = 1 To VL Step 8 Vx = 0 For J = 0 To 3 Vx = Vx * 256 + A(Id) Id = Id + 1 Next J If Vx > 2 ^ 31 - 1 Then Vx = 2 ^ 31 - Vx Ve(Vi) = Vx Vi = Vi + 1Next I
![Page 28: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/28.jpg)
8-byte floating pointFor I = 1 To VL Step 8 For J = 0 To 7 FP(J) = A(7 - J + Id) Next J Call CopyMemory(V8, FP(0), 8) Id = Id + 8 Ve(Vi) = V8 Vi = Vi + 1Next I
ASC IIF$ = ""For I = 1 To VL F$ = F$ & Chr$(A(Id)) Id = Id + 1Next IVe(Vi) = F$Vi = Vi + 1
![Page 29: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/29.jpg)
List .. 遞迴呼叫If VL > 0 Then DP Space$( 層 * 3) & "<L " & VL 層 = 層 + 1 For I = 1 To VL Call 解值 (A(), Id, Vi) Next I 層 = 層 - 1 If 層 < 0 Then Id = -3 Exit Sub End If DP Space$( 層 * 3) & ">"End If
![Page 30: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/30.jpg)
傳送逾時處理:Private Sub 時限 (S As Integer, Fun$, W$, T() As Byte) Dim SB As Single With Data1.Recordset .AddNew .Fields(" 時限 ") = Time + S / (24 * 3600#) .Fields(" 功能 ") = Fun$ .Fields(" 描述 ") = "W" & W$ Call CopyMemory(SB, T(10), 4) .Fields("SB") = SB .Update End WithEnd Sub
![Page 31: Sece II - Hsms](https://reader034.fdocument.pub/reader034/viewer/2022051615/552850c549795912048b4756/html5/thumbnails/31.jpg)
Private Sub 逾時檢查 () Dim S$ With Data1.Recordset If .RecordCount Then If .EditMode <> dbEditNone Then Exit Sub .MoveFirst Do Until .EOF S$ = .Fields(" 描述 ") If Left$(S$, 1) = "W" And Time > .Fields(" 時限 ") Then .Edit .Fields(" 描述 ") = Mid$(S$, 2) .Update End If .MoveNext Loop End If End WithEnd Sub