jondownloads
Level-1
- Beiträge
- 9
- Reaktionspunkte
- 0
-> Hier kostenlos registrieren
[Excuse me but I don't speak German]
Hi,
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
S7ProSim.Connect
Call S7ProSim.WriteDataBlockValue(BlockNumber, ByteIndex, BitIndex, Data)
S7ProSim.Disconnect
End Sub
I get a "PS_E_BADTYPE" error. The problem is related to the data type required by S7PROSIM COM object (const VARIANT*):
STDMETHOD(CS7ProSim::WriteDataBlockValue)(
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.
Hi,
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
S7ProSim.Connect
Call S7ProSim.WriteDataBlockValue(BlockNumber, ByteIndex, BitIndex, Data)
S7ProSim.Disconnect
End Sub
I get a "PS_E_BADTYPE" error. The problem is related to the data type required by S7PROSIM COM object (const VARIANT*):
STDMETHOD(CS7ProSim::WriteDataBlockValue)(
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.