Zuviel Werbung? - > Hier kostenlos beim SPS-Forum registrieren

Ergebnis 1 bis 2 von 2

Thema: PLCSim from Excel using VBA and S7PROSIMLib

  1. #1
    Registriert seit
    Erhielt 0 Danke für 0 Beiträge


    Zuviel Werbung?
    -> Hier kostenlos registrieren
    [Excuse me but I don't speak German]

    I'm trying to access PLCSim from Excel using VBA and S7PROSIMLib.

    I want perform two operations:

    1) Read operation: takes a DB data address from a cell an retrieves it's current value placing it in another cell.

    2) Write operation: takes a DB data address from a cell and a user input value from another cell and uses them to force the value into de PLCSim.

    Read works OK but I can't figure out how to make Write work properly. I'm using the code below:

    Private WithEvents S7ProSim As S7PROSIMLib.S7ProSim

    Public Sub WriteToPLC(BlockNumber As Long, ByteIndex As Long, BitIndex As Long, Data As Variant)
    Set S7ProSim = New S7PROSIMLib.S7ProSim

    Call S7ProSim.WriteDataBlockValue(BlockNumber, ByteIndex, BitIndex, Data)
    End Sub

    I get a "PS_E_BADTYPE" error. The problem is related to the data type required by S7PROSIM COM object (const VARIANT*):

    long BlockNumber,
    long ByteIndex,
    long BitIndex,
    const VARIANT* pData)

    I get it to work if I always force the same value (e.g. using Const CData0 As Byte = 0). But I'm seeking the end user to be able to force values at will just by typing them in a cell (a range).

    Could anyone tell me which data type or data conversion should I use?
    Thanks, Jon.
    Zitieren Zitieren PLCSim from Excel using VBA and S7PROSIMLib  

  2. #2
    Registriert seit
    Erhielt 1.686 Danke für 1.225 Beiträge


    Zuviel Werbung?
    -> Hier kostenlos registrieren
    Hi Jon,
    you have to set the type-field of a variable of type variant to the correct size.

    Maybe there are ways in VBA to set the variant type-field directly, but the following 'trick' should work too:
    Dim bVal As Variant
    Dim wVal As Variant
    Dim dwVal As Variant
    Dim b As Byte
    Dim w As Integer
    Dim dw As Long
    b = 43
    w = 32767
    dw = 12345678
    bVal = b ' bVal is now of type Byte (1 Byte)
    wVal = w ' wVal is now of type Integer (2 Bytes)
    dwVal = dw ' dwVal is now of type long (4 Bytes)
    Call S7ProSim.WriteDataBlockValue(1, 0, 0, bVal) ' Write a byte to DB1.DBB0
    Call S7ProSim.WriteDataBlockValue(1, 2, 0, wVal) ' Write a word to DB1.DBW2
    Call S7ProSim.WriteDataBlockValue(1, 4, 0, dwVal) ' Write a dword to DB1.DBD4

  3. Folgender Benutzer sagt Danke zu Thomas_v2.1 für den nützlichen Beitrag:

    jondownloads (08.07.2011)

Ähnliche Themen

  1. WIN AC MP4.1 und PLCSIM
    Von Blackmike im Forum HMI
    Antworten: 1
    Letzter Beitrag: 23.05.2009, 10:54
  2. Plcsim 5.4
    Von jabba im Forum Simatic
    Antworten: 6
    Letzter Beitrag: 08.02.2008, 21:24
  3. Plcsim
    Von magmaa im Forum Simatic
    Antworten: 4
    Letzter Beitrag: 28.10.2007, 13:18
  4. Plcsim Ton
    Von kpeter im Forum Simatic
    Antworten: 5
    Letzter Beitrag: 26.02.2007, 13:51
  5. S7-plcsim
    Von snuggles im Forum Simatic
    Antworten: 6
    Letzter Beitrag: 30.11.2006, 09:37



  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein