Показать сообщение отдельно
  #18  
Старый 06.04.2011, 17:33
AlexSku AlexSku вне форума
Специалист
 
Регистрация: 07.05.2007
Адрес: Москва
Сообщения: 884
Репутация: 21699
По умолчанию из руководства

Код:
Programming an Interface to S7-PLCSIM with S7ProSim
To use S7ProSim to programmatically operate the S7-PLCSIM simulated controller, you must perform
these tasks:
• Include the Siemens S7ProSim COM Object in the project.
• Add a declaration to your project for S7ProSim.
Example: Visual Basic 6.0
Option Explicit
Private WithEvents S7ProSim As S7PROSIMLib.S7ProSim
...
Private Sub Form_Load()
Set S7ProSim = New S7PROSIMLIB.S7ProSim
...
End Sub
Example: Visual Basic .NET
Private WithEvents S7ProSim As New S7PROSIMLib.S7ProSim
Example: Visual C++ 6.0
// the ProSim library/tlb is in the dll
#import <S7wspsmx.dll> named_guids, no_namespace//, raw_interfaces_only
class ProSimWrapper
{
public:
ProSimWrapper() : m_pProSim(OLESTR("S7wspsmx.S7ProSim"), NULL,
CLSCTX_INPROC_SERVER)
{}; // the spartptr is automatically created on the stack when the app
starts
virtual ~ProSimWrapper()
{}; // no implementation, the smartptr is automatically released when the
app shutsdown
IS7ProSim * GetPtr()
{
return m_pProSim;
};
// Attributes
protected:
// IProSimPtr is a CComPtr (smart ptr) to the IProSim interface
// It is from the dll file from the #import
// CoCreateInstance will be called automatically on the ptr object in the
constructor of this class
// release ptr is automatically called by the destructor of this class
IS7ProSimPtr m_pProSim;
};
Example: C#
using S7PROSIMLib;
...
private S7ProSim ps;
• For Visual Basic, program event handlers for the S7ProSim events. Event handlers are not
necessary in Visual C++. Within each event handler, you can insert any custom code for your
application.
S7ProSim Overview
S7ProSim V5.4 9
A5E00992430-01
Example: Visual Basic 6.0
Private Sub S7ProSim_PauseStateChanged(ByVal NewState As String)
DoEvents
...
End Sub
Private Sub S7ProSim_ScanFinished(ByVal ScanInfo As Variant)
DoEvents
...
End Sub
Private Sub S7ProSim_PLCSimStateChanged(ByVal NewState As String)
DoEvents
...
End Sub
Private Sub S7ProSim_ConnectionError(ByVal ControlEngine As String, ByVal error
As Long)
DoEvents
MsgBox "Connection Error"
End Sub
Private Sub S7ProSim_ScanModeChanged(ByVal NewState As String)
DoEvents
...
End Sub
Note
In Visual Basic .NET, the "DoEvents" call is not necessary.
• Add command buttons, textboxes or other objects to your application as needed to access the
various S7ProSim methods. Program the code for each command button handler to call S7ProSim
methods and set corresponding values for textboxes as appropriate for your application.
Ответить с цитированием