Jazz Soft 您要聯絡嗎?   JazzSoft@live.com     繁體字漢語   英語  日語  繁體字漢語  簡體字漢語
提供半導體工廠自動化與生産效率改善法 
Skip Navigation Links首頁 > 產品一覽 > Swing > Samples > HSMS Client (Visual Basic 6.0)
Swing ActiveX Control   



Programming Guide - Making a mini HSMS client in Visual Basic 6

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

  1. 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.



  2. 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


  3. 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


  4. 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


  5. Receive HSMS message
    It is defined HSMS message type as follows:


    ValueDescription
    0Data message
    1Select.Req
    2Select.Rsp
    3Deselect.Req
    4Deselect.Rsp
    5LinkTest.Req
    6LinkTest.Rsp
    7Reject.Req
    9Separate 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


  6. 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


  7. 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


您要聯絡嗎?   JazzSoft@live.com
  Copyright © 1997 - 2018 Jazz Soft, Inc.