Swing ActiveX Control
|
This chapter, we make very simple HSMS client software using SwingHsms Control. We use Visual Basic for the development language.
|
Prepare for application
First, create default program group and insert ActiveX control following same procedure described in previous section.
|
Let's make a simple HSMS client
-
Paste ActiveX Control
Paste SwingHsms Control and SwingSecsII Control on the form. In this case, we use only one SwingSecsII Control to simplify source code for explanation.
-
Connect to server
To establish connection, let's write code in FormLoad Event. You can be ready to communicate right after the application comes up.
'Connect
.Active = True
-
Prepare to send
Message header of HSMS is not the same with the one of SECS-I. So first, we prepare Send function to send HSMS messages.
Private Sub Send (bDataMessage As Boolean)
With SwingSecsII1
If bDataMessage Then
.SessionID = 0
.SType = 0
Else
.SessionID = &HFFFF
End If
.PType = 0
.EBit = False
SwingHsms.Send .Msg
End With
End Sub
-
Send 'Select.req' message
In HSMS-SS (Single Session), client (active entity) should send 'Select Request' message to server (passive entity).
'Connected successfully?
If .Active Then
'Send Select.Req message
SwingSecsII1.List = "SelectReq"
Send False
End If
-
Receive HSMS message
It is defined HSMS message type as follows:
0 | Data message |
1 | Select.Req |
2 | Select.Rsp |
3 | Deselect.Req |
4 | Deselect.Rsp |
5 | LinkTest.Req |
6 | LinkTest.Rsp |
7 | Reject.Req |
9 | Separate Req |
In Read Event Handler function, incoming message should be checked each time.
With SwingSecsII1
.Msg = pszMsg
Select Case .SType
Case 0
'Data message
Case 1
'Select.Req
Case 2
'Select.Rsp
Case 3
'Deselect.Req
Case 4
'Deselect.Rsp
Case 5
'LinkTest.Req
Case 6
'LinkTest.Rsp
Case 7
'Reject.Req
Case 9
'Separate.Req
End Select
End With
-
Reply 'LinkTest.rsp' message
When you received 'Link Test Request' message, you must reply immediately. To reply this message, send as follows:
.List = "LinkTestRsp"
.Reply pszMsg
.SType = 6
.Stream = 0
.Fucntion = 0
Send False
-
Run application
Making simple HSMS client has been completed. You can modify and add functionality to it to be a complicated system. But entire source code are still less than 100 lines. It is very clear that it is more easier to develop software using Swing ActiveX control than without using it, if you write same kind of software from the beginning.
Option Explicit
Private Sub Send (bDataMessage As Boolean)
With SwingSecsII1
If bDataMessage Then
.SessionID = 0
.SType = 0
Else
.SessionID = &HFFFF
End If
.PType = 0
.EBit = False
SwingHsms1.Send .Msg
End With
End Sub
Private Sub Command1_Click(Index As Integer)
With SwingHsms1
Select Case Index
Case 0
'Connect
.Active = True
If .Active Then
SwingSecsII1.List = "SelectReq"
Send False
End If
Case 1
'Disconnect
.Active = False
Case 2
'Link test
SwingSecsII1.List = "LinkTestReq"
Send False
Case 3
'S1F1
SwingSecsII1.List = "s1f1w"
Send True
Case 4
'S1F13
SwingSecsII1.List = "s1f13w{}"
Send True
End Select
End With
End Sub
Private Sub Form_Load()
Command1_Click 0
End Sub
Private Sub SwingHsms1_Read (ByVal pszIPAddress As String, ByVal lPortNumber As Long, ByVal pszMsg As String)
With SwingSecsII1
.Msg = pszMsg
Select Case .SType
Case 0
'Data message
If (.Fucntion Mod 2) = 1 And .WBit Then
'Send default reply message
.List = "<b 0>"
.Reply pszMsg
Send True
End If
Case 1
'Select.Req
.List = "SelectRsp"
.Reply pszMsg
.SType = 2
.Stream = 0
.Fucntion = 0
Send False
Case 2
'Select.Rsp
Case 3
'Deselect.Req
.List = "DeselectRsp"
.Reply pszMsg
.SType = 4
.Stream = 0
.Fucntion = 0
Send False
Case 4
'Deselect.Rsp
Case 5
'LinkTest.Req
.List = "LinkTestRsp"
.Reply pszMsg
.SType = 6
.Stream = 0
.Fucntion = 0
Send False
Case 6
'LinkTest.Rsp
Case 7
'Reject.Req
Case 9
'Separate.Req
End Select
End With
End Sub
|
|