MBT.dll gebruiken in script

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
timdotcom
Starting Member
Starting Member
Posts: 32
Joined: Sun Jun 21, 2009 10:24 am
Location: Netherlands

MBT.dll gebruiken in script

Post by timdotcom »

Hallo,

Ik als homeseer gebruiker met "0" ervaring dacht ik trek toch eens de stoute schoenen aan.

In mijn huis is een Wago PLC aanwezig om de CV te besturen, deze is voorzien van een MODbus TCP interface.
Deze is uit te lezen met een simpel MODbus tool:
http://postimage.org/image/y5av6bnfl/

Nu levert Wago een MBT.dll om via vb of C de modbus functies te benutten.
wago.com/wagoweb/documentation/759/eng_ ... 31200e.pdf

Na veel knip en plakwerk kom ik op onderstaande code:

Code: Select all

'-----------------------------------------------------------------------------
' WAGO Kontakttechnik GmbH       |                                           |
' Hansastr. 27                   |  Technical Support                        |
' D-32423 Minden                 |                                           |
' Tel.: +49(0)571 / 887 - 0      |  Tel.: +49(0)571 / 887 - 555              |
' Fax.: +49(0)571 / 887 - 169    |  Fax.: +49(0)571 / 887 - 8555             |
' Mail: info@wago.com            |  Mail: support@wago.com                   |
' www : http://www.wago.com      |                                           |
'-----------------------------------------------------------------------------
'              Copyright (C) WAGO 2001 - All Rights Reserved                 |
'-----------------------------------------------------------------------------
'  Filename    : MBT.vb
'  Version     : 1.00
'  Date        : 14-08-2003
'-----------------------------------------------------------------------------
'  Description : Interface of MODBUS/TCP DLL                                 
'                implements Modbus-Master-Functions                            
'-----------------------------------------------------------------------------
'  Required    :
'-----------------------------------------------------------------------------
' |Date    |Who |Ver  |Changes
'-----------------------------------------------------------------------------
'  14.08.03 CM   0.00  Init
'-----------------------------------------------------------------------------
Imports MBT

    ' Tablebytes -----------------------------------------------------------------
    Public Const MODBUSTCP_TABLE_OUTPUT_REGISTER As Short = 4
    Public Const MODBUSTCP_TABLE_INPUT_REGISTER As Short = 3
    Public Const MODBUSTCP_TABLE_OUTPUT_COIL As Short = 0
    Public Const MODBUSTCP_TABLE_INPUT_COIL As Short = 1
    Public Const MODBUSTCP_TABLE_EXCEPTION_STATUS As Short = 7

    ' Functions -----------------------------------------------------------------
    Public Declare Function MBTInit Lib "MBT.dll" () _
                                                  As Integer

    Public Declare Function MBTExit Lib "MBT.dll" () _
                                                  As Integer

    Public Declare Function MBTConnect Lib "MBT.dll" (ByVal szHostAddress As String, _
                                                  ByVal Port As Short, _
                                                  ByVal UseTCP As Integer, _
                                                  ByVal RequestTimeout As Integer, _
                                                  ByRef hSocket As Integer) As Integer

    Public Declare Function MBTDisconnect Lib "MBT.dll" (ByVal hSocket As Integer) _
                                                        As Integer

    Public Overloads Declare Function MBTReadRegisters Lib "MBT.dll" (ByVal hSocket As Integer, _
                                                                      ByVal TableType As Byte, _
                                                                      ByVal DataStartAddress As Short, _
                                                                      ByVal NumWords As Short, _
                                                                      ByRef pReadBuffer As UInt16, _
                                                                      ByVal fpReadCompletedCallback As Integer, _
                                                                      ByVal CallbackContext As Integer) _
                                                                      As Integer


    Public Overloads Declare Function MBTWriteRegisters Lib "MBT.dll" (ByVal hSocket As Integer, _
                                                                       ByVal DataStartAddress As Short, _
                                                                       ByVal NumWords As Short, _
                                                                       ByRef pWriteBuffer As UInt16, _
                                                                       ByVal fpWriteCompletedCallback As Integer, _
                                                                       ByVal CallbackContext As Integer) _
                                                                       As Integer


    Public Declare Function MBTReadCoils Lib "MBT.dll" (ByVal hSocket As Integer, _
                                                        ByVal TableType As Byte, _
                                                        ByVal DataStartAddress As Short, _
                                                        ByVal NumBits As Short, _
                                                        ByRef pReadBuffer As Byte, _
                                                        ByVal fpReadCompletedCallback As Integer, _
                                                        ByVal CallbackContext As Integer) _
                                                        As Integer

    Public Declare Function MBTWriteCoils Lib "MBT.dll" (ByVal hSocket As Integer, _
                                                         ByVal DataStartAddress As Short, _
                                                         ByVal NumBits As Short, _
                                                         ByRef pWriteBuffer As Byte, _
                                                         ByVal fpWriteCompletedCallback As Integer, _
                                                         ByVal CallbackContext As Integer) _
                                                         As Integer

    Public Declare Function MBTReadExceptionStatus Lib "MBT.dll" (ByVal hSocket As Integer, _
                                                                  ByRef pExceptionStatus As Byte, _
                                                                  ByVal fpReadCompletedCallback As Integer, _
                                                                  ByVal CallbackContext As Integer) _
                                                                  As Integer

    Public Declare Function MBTSwapWord Lib "MBT.dll" (ByVal wData As UInt16) _
                                                       As UInt16

    Public Declare Function MBTSwapDWord Lib "MBT.dll" (ByVal dwData As UInt32) _
                                                        As UInt32
Sub Main(parm as object)
      Dim Hsocket As Long
      Dim mbtinit As Integer
      Dim mbtexit As Integer
      Dim connection As Integer
      Dim result As Integer
      Dim Testhex As string

mbtinit = MBTInit
   If mbtinit = 0 Then
   HS.writelog ("warning", "Initialisatie gelukt")

   Else
   HS.writelog ("error", "Initialisatie mislukt")

   End If

connection = MBTConnect("192.168.2.2",502,True,1000,Hsocket)

    If connection = 0 Then
    HS.writelog ("warning", "Wago connected")

    Else
    HS.writelog ("Error", "Verbinding Mislukt")

  End If

  result = MBTReadRegisters(Hsocket,3,259,1,1,1,1)

Testhex = Hex(result)

HS.writelog ("warning", Testhex)
HS.writelog ("warning", result)


mbtexit = MBTexit
   If mbtexit = 0 Then
   HS.writelog ("warning", "MBT.dll afsluiten gelukt")

   Else
   HS.writelog ("error", "MBT.dll afsluiten mislukt")

   End If


End Sub
Ik krijg echter geen waarde voor mijn result variabele.

http://postimage.org/image/njqzubh41/

Kan iemand mij verder op weg helpen?

Alvast bedankt,

Tim
Post Reply

Return to “Homeseer Scripts Forum”