plc.myforum.ro Forum Index plc.myforum.ro
PLCs users www.plc.myforum.ro!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Needed s7prosim com object

 
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> SIMATIC Automation Systems -Reg.U
View previous topic :: View next topic  
Author Message
torkua
Junior
Junior


Joined: 13 Mar 2012
Posts: 5

PostPosted: 13/03/2012 23:24    Post subject: Needed s7prosim com object Reply with quote

Hi, someone knows a link for obtaining s7prosim com object for programming plcsim 5.4 from Visual basic?

Thanks in advance.
Back to top
View user's profile Send private message
rumsfeld
Member 3
Member 3


Joined: 29 Oct 2011
Posts: 572

PostPosted: 14/03/2012 07:38    Post subject: Reply with quote

A code example:


Needed s7prosim com object

Code:
Option Explicit On

Public Class Form1

    Private WithEvents S7ProSim1 As S7PROSIMLib.S7ProSim

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        S7ProSim1 = New S7PROSIMLib.S7ProSim
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        S7ProSim1.Connect()
    End Sub

    Private Sub Form_Unload(ByVal cancel As Integer)
        S7ProSim1.Disconnect()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim s As String
        s = S7ProSim1.GetState()
        Label1.Text = s
    End Sub
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim s As String
        S7ProSim1.SetState("RUN_P")
        s = S7ProSim1.GetState()
        Label1.Text = s
    End Sub

 
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim s As String
         S7ProSim1.SetState("STOP")
        s = S7ProSim1.GetState()
        Label1.Text = s
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pData As Byte
        pData = 8
        S7ProSim1.WriteFlagValue(0, 0, pData)
    End Sub

 
  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim pData As Byte
        S7ProSim1.ReadFlagValue(0, 0, 2, pData)
        Label1.Text = pData
    End Sub
Back to top
View user's profile Send private message
messer
Senior
Senior


Joined: 08 Mar 2012
Posts: 2059
Location: Europe

PostPosted: 14/03/2012 23:06    Post subject: JACOB - Java COM Bridge Reply with quote

JACOB - Java COM Bridge

JACOB is a JAVA-COM Bridge that allows you to call COM Automation components from Java. It uses JNI to make native calls to the COM libraries. JACOB runs on x86 and x64 environments supporting 32 bit and 64 bit JVMs
Homepage:
http://sourceforge.net/projects/jacob-project/
and download:
http://sourceforge.net/projects/jacob-project/files/latest/download

JACOB - Java COM Bridge on Sourceforge..
http://sourceforge.net/projects/jacob-project/develop
Back to top
View user's profile Send private message
torkua
Junior
Junior


Joined: 13 Mar 2012
Posts: 5

PostPosted: 14/03/2012 23:35    Post subject: Thank you everyone Reply with quote

Thank you for all the information.

I'm going to work over it, but i want to know if someone has a link for downloading a copy of the s7prosim com objet. I already seen the links in this forum related to step7 2010, etc, and i have it yet, but i can't found s7prosim anywhere.

Again, Thank you all for the information.
Back to top
View user's profile Send private message
torkua
Junior
Junior


Joined: 13 Mar 2012
Posts: 5

PostPosted: 14/03/2012 23:57    Post subject: Excuse me Reply with quote

Thank you..

Finally i understood, the com object is inside my system, i dont need a separate com object, i was assuming that it was a piece of software sold separately as add-on to plcsim. i haven't had tested the procedures you have previously explained to me.

Thanks and sorry.
:innocent:
Back to top
View user's profile Send private message
rumsfeld
Member 3
Member 3


Joined: 29 Oct 2011
Posts: 572

PostPosted: 15/03/2012 06:46    Post subject: Reply with quote

I forgot to tell you to install first VS2008.
The same situation is in WinCC.
In Graphic Designer you have a .NET button on the right panel.
Click with right button of the mouse and Add... and it will add all the Windows Net objects.....you can then use on designing ...
Back to top
View user's profile Send private message
torkua
Junior
Junior


Joined: 13 Mar 2012
Posts: 5

PostPosted: 07/02/2013 23:23    Post subject: Reply with quote

First of all, I would like to thank all the people who helped me a time ago, I sucessfully completed the simulation for a process at that time, but now in another project I need to write a value in order to simulate an analog input over PEW 418 , for example, Could somebody tell me how to do this?

Something like this , but for dealing with analogs inputs would be enough

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pData As Byte
        pData = 8
        S7ProSim1.WriteFlagValue(0, 0, pData)
    End Sub


I'm not a great programmer, I'm afraid. Anyway, Thank you in advance :-)
Back to top
View user's profile Send private message
rumsfeld
Member 3
Member 3


Joined: 29 Oct 2011
Posts: 572

PostPosted: 09/02/2013 21:55    Post subject: Reply with quote

...maybe you should explore a code template like that...
Code:
Private Sub WriteInputWordImage(ByVal lStartIndex As Long, ByVal vData() As Int16)
...
Dim errInputWordImage AsLong
errInputWordImage = AxS7ProSim1.WriteInputImage(lStartIndex, vData)
If errInputWordImage = S_OK Then
'MsgBox(MSG_OK, vbInformation, "S7ProSim Example")
Else
ShowError(errInputWordImage)
EndIf
EndSub
Back to top
View user's profile Send private message
rumsfeld
Member 3
Member 3


Joined: 29 Oct 2011
Posts: 572

PostPosted: 09/02/2013 22:44    Post subject: Reply with quote

.you can also try to use Delphi for PLCSim..tested few years ago....
make a TLB file from the library s7wspsmx.dll.

Code:
MySim: OleVariant;
...
MySim:= CreateOleObject('S7wspsmx.S7ProSim');
MySim.Connect;
MySim.SetScanMode(ContinuousScan);
MySim.SetState('RUN');


If you want to receive events..
Code:

unit S7PROSIMLib_TLB;
 
// ************************************************************************ //
// WARNING                                                                   
// -------                                                                   
// The types declared in this file were generated from data read from a     
// Type Library. If this type library is explicitly or indirectly (via       
// another type library referring to this type library) re-imported, or the 
// 'Refresh' command of the Type Library Editor activated while editing the 
// Type Library, the contents of this file will be regenerated and all       
// manual modifications will be lost.                                       
// ************************************************************************ //
 
// PASTLWTR : 1.2
// File generated on 23.03.2011 0:05:10 from Type Library described below.
 
// ************************************************************************  //
// Type Lib: C:\Program Files\Siemens\Plcsim\s7wsi\s7wspsmx.dll (1)
// LIBID: {83CC0D80-FEDA-11D1-BE76-0060B06816CF}
// LCID: 0
// Helpfile:
// HelpString: Siemens S7ProSim COM Object
// DepndLst:
//   (1) v2.0 stdole, (C:\Windows\system32\stdole2.tlb)
// Errors:
//   Error creating palette bitmap of (TS7ProSim) : Server C:\Program Files\Siemens\Plcsim\s7wsi\s7wspsmx.dll contains no icons
// ************************************************************************ //
// *************************************************************************//
// NOTE:                                                                     
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties
// which return objects that may need to be explicitly created via a function
// call prior to any access via the property. These items have been disabled
// in order to prevent accidental use from within the object inspector. You 
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively 
// removing them from the $IFDEF blocks. However, such items must still be   
// programmatically created via a method of the appropriate CoClass before   
// they can be used.                                                         
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface
 
uses Windows, ActiveX, Classes, Graphics, OleServer, StdVCL, Variants;
   
 
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:       
//   Type Libraries     : LIBID_xxxx                                     
//   CoClasses          : CLASS_xxxx                                     
//   DISPInterfaces     : DIID_xxxx                                     
//   Non-DISP interfaces: IID_xxxx                                       
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  S7PROSIMLibMajorVersion = 1;
  S7PROSIMLibMinorVersion = 0;
 
  LIBID_S7PROSIMLib: TGUID = '{83CC0D80-FEDA-11D1-BE76-0060B06816CF}';
 
  IID_IS7ProSimEvents: TGUID = '{83CC0D82-FEDA-11D1-BE76-0060B06816CF}';
  IID_IS7ProSim: TGUID = '{83CC0D81-FEDA-11D1-BE76-0060B06816CF}';
  CLASS_S7ProSim: TGUID = '{83CC0D83-FEDA-11D1-BE76-0060B06816CF}';
 
// *********************************************************************//
// Declaration of Enumerations defined in Type Library                   
// *********************************************************************//
// Constants for enum __MIDL___MIDL_itf_S7wspsmx_0000_0002
type
  __MIDL___MIDL_itf_S7wspsmx_0000_0002 = TOleEnum;
const
  S7Byte = $00000002;
  S7Word = $00000003;
  S7DoubleWord = $00000004;
 
// Constants for enum __MIDL___MIDL_itf_S7wspsmx_0000_0003
type
  __MIDL___MIDL_itf_S7wspsmx_0000_0003 = TOleEnum;
const
  S7_Bit = $00000001;
  S7_Byte = $00000002;
  S7_Word = $00000003;
  S7_DoubleWord = $00000004;
 
// Constants for enum __MIDL___MIDL_itf_S7wspsmx_0000_0001
type
  __MIDL___MIDL_itf_S7wspsmx_0000_0001 = TOleEnum;
const
  SingleScan = $00000000;
  ContinuousScan = $00000001;
 
// Constants for enum __MIDL___MIDL_itf_S7wspsmx_0000_0004
type
  __MIDL___MIDL_itf_S7wspsmx_0000_0004 = TOleEnum;
const
  Running = $00000000;
  Paused = $00000001;
  Disabled = $00000002;
 
// Constants for enum __MIDL___MIDL_itf_S7wspsmx_0000_0005
type
  __MIDL___MIDL_itf_S7wspsmx_0000_0005 = TOleEnum;
const
  WarmStart = $00000000;
  HotStart = $00000001;
  ColdStart = $00000002;
 
type
 
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                   
// *********************************************************************//
  IS7ProSimEvents = interface;
  IS7ProSim = interface;
  IS7ProSimDisp = dispinterface;
 
// *********************************************************************//
// Declaration of CoClasses defined in Type Library                     
// (NOTE: Here we map each CoClass to its Default Interface)             
// *********************************************************************//
  S7ProSim = IS7ProSim;
 
 
// *********************************************************************//
// Declaration of structures, unions and aliases.                       
// *********************************************************************//
  POleVariant1 = ^OleVariant; {*}
 
  ImageDataTypeConstants = __MIDL___MIDL_itf_S7wspsmx_0000_0002;
  PointDataTypeConstants = __MIDL___MIDL_itf_S7wspsmx_0000_0003;
  ScanModeConstants = __MIDL___MIDL_itf_S7wspsmx_0000_0001;
  PauseStateConstants = __MIDL___MIDL_itf_S7wspsmx_0000_0004;
  RestartSwitchPositionConstants = __MIDL___MIDL_itf_S7wspsmx_0000_0005;
 
// *********************************************************************//
// Interface: IS7ProSimEvents
// Flags:     (256) OleAutomation
// GUID:      {83CC0D82-FEDA-11D1-BE76-0060B06816CF}
// *********************************************************************//
  IS7ProSimEvents = interface(IUnknown)
    ['{83CC0D82-FEDA-11D1-BE76-0060B06816CF}']
    function ScanFinished(ScanInfo: OleVariant): HResult; stdcall;
    function ConnectionError(const ControlEngine: WideString; Error: Integer): HResult; stdcall;
    function PLCSimStateChanged(const NewState: WideString): HResult; stdcall;
    function PauseStateChanged(const NewState: WideString): HResult; stdcall;
    function ScanModeChanged(const NewState: WideString): HResult; stdcall;
  end;


Code:
// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object    : TS7ProSim
// Help String      : S7ProSim Class
// Default Interface: IS7ProSim
// Def. Intf. DISP? : No
// Event   Interface: IS7ProSimEvents
// TypeFlags        : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  TS7ProSimProperties= class;
{$ENDIF}
  TS7ProSim = class(TOleServer)
  private
    FOnScanFinished: TS7ProSimScanFinished;
    FOnConnectionError: TS7ProSimConnectionError;
    FOnPLCSimStateChanged: TS7ProSimPLCSimStateChanged;
    FOnPauseStateChanged: TS7ProSimPauseStateChanged;
    FOnScanModeChanged: TS7ProSimScanModeChanged;
    FIntf:        IS7ProSim;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    FProps:       TS7ProSimProperties;
    function      GetServerProperties: TS7ProSimProperties;
{$ENDIF}
    function      GetDefaultInterface: IS7ProSim;
  protected
    procedure InitServerData; override;
    procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure Connect; override;
    procedure ConnectTo(svrIntf: IS7ProSim);
    procedure Disconnect; override;
    procedure ReadOutputImage(StartIndex: Integer; ElementsToRead: Integer;
                              DataType: ImageDataTypeConstants; var pData: OleVariant);
    procedure WriteInputImage(StartIndex: Integer; var pData: OleVariant);
    procedure ReadOutputPoint(ByteIndex: Integer; BitIndex: Integer;
                              DataType: PointDataTypeConstants; var pData: OleVariant);
    procedure WriteInputPoint(ByteIndex: Integer; BitIndex: Integer; var pData: OleVariant);
    procedure ExecuteSingleScan;
    procedure Connect1;
    procedure Disconnect1;
    procedure BeginScanNotify;
    procedure EndScanNotify;
    procedure ExecuteNmsScan(MsNumber: Integer);
    procedure ExecuteNScans(NScanNumber: Integer);
    function GetScanMode: ScanModeConstants;
    procedure SetScanMode(newVal: ScanModeConstants);
    procedure Pause;
    procedure Continue;
    function GetPauseState: PauseStateConstants;
    procedure SavePLC(const FileName: WideString);
    procedure HotStartWithSavedValues(val: Integer);
    function GetState: WideString;
    procedure SetState(const newVal: WideString);
    procedure StartPLCSim(const plcFile: WideString);
    procedure SetStartUpSwitch(postion: RestartSwitchPositionConstants);
    function GetStartUpSwitch: RestartSwitchPositionConstants;
    procedure ReadDataBlockValue(BlockNum: Integer; ByteIndex: Integer; BitIndex: Integer;
                                 DataType: PointDataTypeConstants; var pData: OleVariant);
    procedure WriteDataBlockValue(BlockNum: Integer; ByteIndex: Integer; BitIndex: Integer;
                                  var pData: OleVariant);
    procedure ReadFlagValue(ByteIndex: Integer; BitIndex: Integer;
                            DataType: PointDataTypeConstants; var pData: OleVariant);
    procedure WriteFlagValue(ByteIndex: Integer; BitIndex: Integer; var pData: OleVariant);
    procedure ConnectExt(InstanceNumber: Integer);
    procedure StartPLCSimExt(const plcFile: WideString);
    property DefaultInterface: IS7ProSim read GetDefaultInterface;
  published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
    property Server: TS7ProSimProperties read GetServerProperties;
{$ENDIF}
    property OnScanFinished: TS7ProSimScanFinished read FOnScanFinished write FOnScanFinished;
    property OnConnectionError: TS7ProSimConnectionError read FOnConnectionError write FOnConnectionError;
    property OnPLCSimStateChanged: TS7ProSimPLCSimStateChanged read FOnPLCSimStateChanged write FOnPLCSimStateChanged;
    property OnPauseStateChanged: TS7ProSimPauseStateChanged read FOnPauseStateChanged write FOnPauseStateChanged;
    property OnScanModeChanged: TS7ProSimScanModeChanged read FOnScanModeChanged write FOnScanModeChanged;
  end;
 
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object    : TS7ProSim
// (This object is used by the IDE's Property Inspector to allow editing
//  of the properties of this server)
// *********************************************************************//
 TS7ProSimProperties = class(TPersistent)
  private
    FServer:    TS7ProSim;
    function    GetDefaultInterface: IS7ProSim;
    constructor Create(AServer: TS7ProSim);
  protected
  public
    property DefaultInterface: IS7ProSim read GetDefaultInterface;
  published
  end;
{$ENDIF}
 
 
procedure Register;
 
resourcestring
  dtlServerPage = 'ActiveX';
 
  dtlOcxPage = 'ActiveX';


..................................................
Code:

implementation
 
uses ComObj;
 
class function CoS7ProSim.Create: IS7ProSim;
begin
  Result := CreateComObject(CLASS_S7ProSim) as IS7ProSim;
end;
 
class function CoS7ProSim.CreateRemote(const MachineName: string): IS7ProSim;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_S7ProSim) as IS7ProSim;
end;
 
procedure TS7ProSim.InitServerData;
const
  CServerData: TServerData = (
    ClassID:   '{83CC0D83-FEDA-11D1-BE76-0060B06816CF}';
    IntfIID:   '{83CC0D81-FEDA-11D1-BE76-0060B06816CF}';
    EventIID:  '{83CC0D82-FEDA-11D1-BE76-0060B06816CF}';
    LicenseKey: nil;
    Version: 500);
begin
  ServerData := @CServerData;
end;
 
procedure TS7ProSim.Connect;
var
  punk: IUnknown;
begin
  if FIntf = nil then
  begin
    punk := GetServer;
    ConnectEvents(punk);
    Fintf:= punk as IS7ProSim;
  end;
end;
 
procedure TS7ProSim.ConnectTo(svrIntf: IS7ProSim);
begin
  Disconnect;
  FIntf := svrIntf;
  ConnectEvents(FIntf);
end;
 
procedure TS7ProSim.DisConnect;
begin
  if Fintf <> nil then
  begin
    DisconnectEvents(FIntf);
    FIntf := nil;
  end;
end;
 
function TS7ProSim.GetDefaultInterface: IS7ProSim;
begin
  if FIntf = nil then
    Connect;
  Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  Result := FIntf;
end;
 
constructor TS7ProSim.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps := TS7ProSimProperties.Create(Self);
{$ENDIF}
end;
 
destructor TS7ProSim.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  FProps.Free;
{$ENDIF}
  inherited Destroy;
end;
 
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TS7ProSim.GetServerProperties: TS7ProSimProperties;
begin
  Result := FProps;
end;
{$ENDIF}
 
procedure TS7ProSim.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
begin
  case DispID of
    -1: Exit;  // DISPID_UNKNOWN
    1: if Assigned(FOnScanFinished) then
         FOnScanFinished(Self, Params[0] {OleVariant});
    2: if Assigned(FOnConnectionError) then
         FOnConnectionError(Self,
                            Params[0] {const WideString},
                            Params[1] {Integer});
    3: if Assigned(FOnPLCSimStateChanged) then
         FOnPLCSimStateChanged(Self, Params[0] {const WideString});
    4: if Assigned(FOnPauseStateChanged) then
         FOnPauseStateChanged(Self, Params[0] {const WideString});
    5: if Assigned(FOnScanModeChanged) then
         FOnScanModeChanged(Self, Params[0] {const WideString});
  end; {case DispID}
end;
 
procedure TS7ProSim.ReadOutputImage(StartIndex: Integer; ElementsToRead: Integer;
                                    DataType: ImageDataTypeConstants; var pData: OleVariant);
begin
  DefaultInterface.ReadOutputImage(StartIndex, ElementsToRead, DataType, pData);
end;
 
procedure TS7ProSim.WriteInputImage(StartIndex: Integer; var pData: OleVariant);
begin
  DefaultInterface.WriteInputImage(StartIndex, pData);
end;
 
procedure TS7ProSim.ReadOutputPoint(ByteIndex: Integer; BitIndex: Integer;
                                    DataType: PointDataTypeConstants; var pData: OleVariant);
begin
  DefaultInterface.ReadOutputPoint(ByteIndex, BitIndex, DataType, pData);
end;
 
procedure TS7ProSim.WriteInputPoint(ByteIndex: Integer; BitIndex: Integer; var pData: OleVariant);
begin
  DefaultInterface.WriteInputPoint(ByteIndex, BitIndex, pData);
end;
 
procedure TS7ProSim.ExecuteSingleScan;
begin
  DefaultInterface.ExecuteSingleScan;
end;
 
procedure TS7ProSim.Connect1;
begin
  DefaultInterface.Connect;
end;
 
procedure TS7ProSim.Disconnect1;
begin
  DefaultInterface.Disconnect;
end;
 
procedure TS7ProSim.BeginScanNotify;
begin
  DefaultInterface.BeginScanNotify;
end;
 
procedure TS7ProSim.EndScanNotify;
begin
  DefaultInterface.EndScanNotify;
end;
 
procedure TS7ProSim.ExecuteNmsScan(MsNumber: Integer);
begin
  DefaultInterface.ExecuteNmsScan(MsNumber);
end;
 
procedure TS7ProSim.ExecuteNScans(NScanNumber: Integer);
begin
  DefaultInterface.ExecuteNScans(NScanNumber);
end;
 
function TS7ProSim.GetScanMode: ScanModeConstants;
begin
  Result := DefaultInterface.GetScanMode;
end;
 
procedure TS7ProSim.SetScanMode(newVal: ScanModeConstants);
begin
  DefaultInterface.SetScanMode(newVal);
end;
 
procedure TS7ProSim.Pause;
begin
  DefaultInterface.Pause;
end;
 
procedure TS7ProSim.Continue;
begin
  DefaultInterface.Continue;
end;
 
function TS7ProSim.GetPauseState: PauseStateConstants;
begin
  Result := DefaultInterface.GetPauseState;
end;
 
procedure TS7ProSim.SavePLC(const FileName: WideString);
begin
  DefaultInterface.SavePLC(FileName);
end;
 
procedure TS7ProSim.HotStartWithSavedValues(val: Integer);
begin
  DefaultInterface.HotStartWithSavedValues(val);
end;
 
function TS7ProSim.GetState: WideString;
begin
  Result := DefaultInterface.GetState;
end;
 
procedure TS7ProSim.SetState(const newVal: WideString);
begin
  DefaultInterface.SetState(newVal);
end;
 
procedure TS7ProSim.StartPLCSim(const plcFile: WideString);
begin
  DefaultInterface.StartPLCSim(plcFile);
end;
 
procedure TS7ProSim.SetStartUpSwitch(postion: RestartSwitchPositionConstants);
begin
  DefaultInterface.SetStartUpSwitch(postion);
end;
 
function TS7ProSim.GetStartUpSwitch: RestartSwitchPositionConstants;
begin
  Result := DefaultInterface.GetStartUpSwitch;
end;
 
procedure TS7ProSim.ReadDataBlockValue(BlockNum: Integer; ByteIndex: Integer; BitIndex: Integer;
                                       DataType: PointDataTypeConstants; var pData: OleVariant);
begin
  DefaultInterface.ReadDataBlockValue(BlockNum, ByteIndex, BitIndex, DataType, pData);
end;
 
procedure TS7ProSim.WriteDataBlockValue(BlockNum: Integer; ByteIndex: Integer; BitIndex: Integer;
                                        var pData: OleVariant);
begin
  DefaultInterface.WriteDataBlockValue(BlockNum, ByteIndex, BitIndex, pData);
end;
 
procedure TS7ProSim.ReadFlagValue(ByteIndex: Integer; BitIndex: Integer;
                                  DataType: PointDataTypeConstants; var pData: OleVariant);
begin
  DefaultInterface.ReadFlagValue(ByteIndex, BitIndex, DataType, pData);
end;
 
procedure TS7ProSim.WriteFlagValue(ByteIndex: Integer; BitIndex: Integer; var pData: OleVariant);
begin
  DefaultInterface.WriteFlagValue(ByteIndex, BitIndex, pData);
end;
 
procedure TS7ProSim.ConnectExt(InstanceNumber: Integer);
begin
  DefaultInterface.ConnectExt(InstanceNumber);
end;
 
procedure TS7ProSim.StartPLCSimExt(const plcFile: WideString);
begin
  DefaultInterface.StartPLCSimExt(plcFile);
end;
 
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TS7ProSimProperties.Create(AServer: TS7ProSim);
begin
  inherited Create;
  FServer := AServer;
end;
 
function TS7ProSimProperties.GetDefaultInterface: IS7ProSim;
begin
  Result := FServer.DefaultInterface;
end;
 
{$ENDIF}
 
procedure Register;
begin
  RegisterComponents(dtlServerPage, [TS7ProSim]);
end;
 
end.


.................................................

You can copy (in notepad or Delphi) consecutive these pieces.
Code:
unit Unit1;
 
interface
 
uses
  S7PROSIMLib_TLB,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  procedure S7ProSimConnectionError(ASender: TObject; const ControlEngine: WideString;
    Error: Integer);
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
var
  S7ProSim: TS7ProSim;
begin
  S7ProSim:=TS7ProSim.Create(Self);
  S7ProSim.OnConnectionError:=S7ProSimConnectionError;
  S7ProSim.Connect;
  S7ProSim.SetScanMode(ContinuousScan);
  S7ProSim.SetState('RUN');
end;
 
procedure TForm1.S7ProSimConnectionError(ASender: TObject;
  const ControlEngine: WideString; Error: Integer);
begin
  //  OnConnectionError
end;
 
end.


Code:
uses
  S7PROSIMLib_TLB,
 
var
  S7ProSim: IS7ProSim;
begin
  S7ProSim:=CreateComObject(CLASS_S7ProSim) as IS7ProSim;
  S7ProSim.Connect;
  S7ProSim.SetScanMode(ContinuousScan);
  S7ProSim.SetState('RUN');
end;


..and to write "handler" IS7ProSimEvents it would do well to "tie" to IS7ProSim..

Code:
uses
  InterfacedObjectDispatch,
  S7PROSIMLib_TLB,
  ComObj,
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InvokeEvent(DispID: Integer; const IID: TGUID; LocaleID: Integer;
      Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer);
  public
    { Public declarations }
  end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  S7ProSim: IS7ProSim;
  FEventsConnection: Integer;
  FEventDispatch: TInterfacedObjectDispatch;
begin
  FEventDispatch:=TInterfacedObjectDispatch.Create;
  FEventDispatch.OnInvokeEvent:=InvokeEvent;
  S7ProSim:=CreateComObject(CLASS_S7ProSim) as IS7ProSim;
  InterfaceConnect(S7ProSim, IID_IS7ProSimEvents, FEventDispatch, FEventsConnection);
  S7ProSim.Connect;
  S7ProSim.SetScanMode(ContinuousScan);
  S7ProSim.SetState('RUN');
 
// 
//  InterfaceDisconnect(S7ProSim, IID_IS7ProSimEvents, FEventsConnection);
end;
 
procedure TForm1.InvokeEvent(DispID: Integer; const IID: TGUID;
  LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
  ArgErr: Pointer);
begin
  //
  case DispID of
    1: begin
      // OnScanFinished
    end;
    2: begin
      // OnConnectionError
    end;
    3: begin
      // OnPLCSimStateChanged
    end;
    4: begin
      // OnPauseStateChanged
    end;
    5: begin
      // OnScanModeChanged
    end;
  end;
end;


another option...
Code:

unit Unit1;
 
interface
 
uses
  InterfacedObjectDispatch,
  S7PROSIMLib_TLB,
  ComObj,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure InvokeEvent(DispID: Integer; const IID: TGUID; LocaleID: Integer;
      Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer);
  public
    { Public declarations }
    S7ProSim: IS7ProSim;
    FEventDispatch: TInterfacedObjectDispatch;
    FEventsConnection: Longint;
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var
  punk: IUnknown;
begin
  FEventDispatch:=TInterfacedObjectDispatch.Create(InvokeEvent, IS7ProSimEvents);
  punk:=CreateComObject(CLASS_S7ProSim);
  InterfaceConnect(punk, IS7ProSimEvents, FEventDispatch, FEventsConnection);
  S7ProSim:=punk as IS7ProSim;
  S7ProSim.Connect;
  S7ProSim.SetScanMode(ContinuousScan);
  S7ProSim.SetState('RUN');
 
// 
//  InterfaceDisconnect(S7ProSim, IID_IS7ProSimEvents, FEventsConnection);
//  FEventDispatch.Free;
end;
 
procedure TForm1.InvokeEvent(DispID: Integer; const IID: TGUID;
  LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
  ArgErr: Pointer);
begin
  // 
  case DispID of
    1: begin
      // OnScanFinished
    end;
    2: begin
      Memo1.Text:='close';
      // OnConnectionError
    end;
    3: begin
      // OnPLCSimStateChanged
    end;
    4: begin
      // OnPauseStateChanged
    end;
    5: begin
      // OnScanModeChanged
    end;
  end;
end;
 
end.


...good luck.....
Back to top
View user's profile Send private message
torkua
Junior
Junior


Joined: 13 Mar 2012
Posts: 5

PostPosted: 11/02/2013 22:55    Post subject: Reply with quote

Finally I managed to read and write data to and from the analog inputs or outputs, in visual studio 2010, visual basic, using the COM object.

this is the code I used,
Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       

        '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        'Reading two bytes from  periferia
        Dim cByteArray2(0 To 1) As Byte
        Dim lStartIndex2 As Integer
        Dim lElementsToRead As Integer
        Dim DataType As S7PROSIMLib.ImageDataTypeConstants
        Dim vData2 As Object
        vData2 = cByteArray2
        DataType = S7PROSIMLib.ImageDataTypeConstants.S7Byte 'Read type Byte
        lStartIndex2 = 522 'Start at address PEW 522
        lElementsToRead = 2 'Read 2 elements (Bytes)
        S7ProSim1.ReadOutputImage(lStartIndex2, lElementsToRead, DataType, vData2)
        'MsgBox("Value of first byte is: " & (vData2(0)) & vbCrLf & "Value of second byte is: " & CByte(vData2(1)), vbInformation, "S7ProSim Example")
        'vdata2(0) es el byte mas significativo, vdata2(1)el menos.

        '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        'Writing two bytes to periferia
        Dim cByteArray(0 To 1) As Byte
        Dim lStartIndex As Long
        Dim vData As Object
        cByteArray(0) = vData2(0) 'Byte) mas significativo
        cByteArray(1) = vData2(1) '(Byte) menos significativo
        lStartIndex = 480 'direccion de la periferia for example PAW480
        vData = cByteArray
        S7ProSim1.WriteInputImage(lStartIndex, vData)

    End Sub


I read the example that appears on the documents concerning the activeX object, instead of the included with the COM object. In this last one, there is not any example.

Apparently you need a kind of vector for retrieving and writing data, is not as simple as reading a flag or a digital input.

Maybe it could be done in an easier form, but this one worked for me.

As i told before i'm very far from being a "coder" but i would like to share this one, maybe it can be usefull for somebody else.

Thank you all again for spending your time answering my questions.
Back to top
View user's profile Send private message
finrod
Junior
Junior


Joined: 30 May 2013
Posts: 1
Location: colombia

PostPosted: 15/11/2013 03:04    Post subject: plcsim with visual basic Reply with quote

hy i will like to read one of the outputs points , im using readoutputpoint but i dont know if that is what i have to use ,, somebody hepl me please
Back to top
View user's profile Send private message Send e-mail
oldsnake
Junior
Junior


Joined: 24 Jun 2012
Posts: 14

PostPosted: 11/07/2014 04:19    Post subject: Reply with quote

If I want status connect or no. How can i do?
Back to top
View user's profile Send private message
rumsfeld
Member 3
Member 3


Joined: 29 Oct 2011
Posts: 572

PostPosted: 11/02/2015 18:33    Post subject: Reply with quote

With NetToPLCSim you are able to connect your SCADA/HMI-systems via S7-communication to PLCSim over TCP/IP, and read/write data areas from your simulated PLC.

http://nettoplcsim.sourceforge.net/index.html
Download from:
http://sourceforge.net/projects/nettoplcsim/files/

http://sourceforge.net/projects/nettoplcsim/files/nettoplcsim-S7o/

Other sourceforge projects:
S7 Data Archiver
Tool for store Siemens S7 PLC's data, eg: DB, DI, M and more, in a local file, or write them from local file. Conține data editor.
License
European Union Public License
http://sourceforge.net/projects/s7dataarchiver/

libnodave
Libnodave is a library that provides the necessary functions to connect to and exchange data with Siemens S7 300/400 PLCs (200 family and S5 family now also supported). Can now also be used under Win32.
License
GNU Library or Lesser General Public License version 2.0 (LGPLv2)
http://sourceforge.net/projects/libnodave/
http://libnodave.sourceforge.net/

S7comm Wireshark dissector plugin
Needed s7prosim com object
Wireshark dissector for S7 communication. This Wireshark dissector plugin (dll) dissects the ISOonTCP-packets for communication to Siemens S7 PLCs.
Plugin dll for the new 1200/1500 protocol as s7comm-plus plugin available.
Version 0.0.5 is only compatible with Wireshark Version >= 1.12.0.
http://sourceforge.net/projects/s7commwireshark/
http://s7commwireshark.sourceforge.net/
Back to top
View user's profile Send private message
kirk
Junior
Junior


Joined: 08 Oct 2016
Posts: 4

PostPosted: 24/10/2016 18:52    Post subject: Reply with quote

is this working with TIA V14?
Back to top
View user's profile Send private message
karkalete
Junior 2
Junior 2


Joined: 20 Nov 2016
Posts: 25

PostPosted: 21/11/2016 22:33    Post subject: Communication with Siemens S7 Plc with C# and S7.Net plc dri Reply with quote

Communication with Siemens S7 Plc with C# and S7.Net plc driver
http://www.mesta-automation.com/siemens-s7-plc-c-s7-net-plc-driver/
https://github.com/killnine/s7netplus
Back to top
View user's profile Send private message
karkalete
Junior 2
Junior 2


Joined: 20 Nov 2016
Posts: 25

PostPosted: 21/11/2016 22:36    Post subject: Snap7: an open source Siemens S7 communication library Reply with quote

Snap7: an open source Siemens S7 communication library
http://www.mesta-automation.com/snap7-open-source-siemens-s7-communication-library/
Back to top
View user's profile Send private message
poddesky
Junior
Junior


Joined: 27 Aug 2018
Posts: 7

PostPosted: 29/08/2018 17:17    Post subject: Reply with quote

kirk wrote:
is this working with TIA V14?

No..Step 7 V5.4/5.5
TCP/IP-Network extension for the PLC simulation software Siemens PLCSim (Step 7 V5.4/5.5). With NetToPLCSim you are able to simulate e.g. SCADA systems over Network in combination with your simulated PLC.
Back to top
View user's profile Send private message
ALooser
Junior 2
Junior 2


Joined: 26 Oct 2018
Posts: 37

PostPosted: 03/07/2019 14:29    Post subject: nettoplcsim Reply with quote

nettoplcsim
https://sourceforge.net/projects/nettoplcsim/files/
PLCSIM S7-1200 - NetToPLCSim - S7 PLC HMI Lite
https://www.youtube.com/watch?v=0yCt43C9Pgw
https://www.mesta-automation.com/nettoplcsim-how-to-connect-step-7-plc-sim-to-scadas/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> SIMATIC Automation Systems -Reg.U All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro