Author Topic: Driver Siemens with Snap7  (Read 10346 times)

tatin

  • Newbie
  • *
  • Posts: 12
    • View Profile
Driver Siemens with Snap7
« on: November 08, 2020, 03:45:27 PM »
Hello, in case someone is interested, I leave a slightly more tested version of a communication driver for Siemens PLCs that uses Snap7.
To integrate it, you have to copy the files in the "AdvancedHMIDrivers" folder, within the project add the SiemensCom.vb file as an existing element, add the Snap7.net.dll file in "References" and finally copy the "snap7.dll" file. in the build folder of the project "AdvancedHMI \ bin \ Debug"

By the way, it works with the Tia Portal simulator via NetToPLCSim.

Cheers...

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Driver Siemens with Snap7
« Reply #1 on: November 08, 2020, 04:40:35 PM »
Nice contribution! I suspect a lot of people will be looking forward to trying this out.

Noe

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Driver Siemens with Snap7
« Reply #2 on: November 09, 2020, 09:44:22 AM »
Great! I will try it as soon as I have another project with Siemens, which will be within the next three weeks.

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Driver Siemens with Snap7
« Reply #3 on: November 10, 2020, 09:09:51 AM »
[Untested]

Right click AdvancedHMIDrivers folder and Add Existing Items:
SiemensCom.vb

Add a Siemens folder (see picture)and Add Existing Items

snap7.dll   
Snap7.net.dll
Change snap7.dll - Copy to output directory to Always.

Right click each project (AdvancedHMIDrivers, AdvancedHMI, AdvancedHMIControls), Add reference : Snap7.net.dll

Build solution

Drag & Drop SiemensCom driver from AdvancedHMIDrivers Component Toolbox to your form.


P.S. If this prove out reliable, Archie should intergrate it into AHMI.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

LuckyAdvabced

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Driver Siemens with Snap7
« Reply #4 on: January 30, 2021, 03:11:00 PM »
Hi all and thanks to Tatin for the integration and thanks to Archie for great AdvancedHmi Project.
I tried to install and use snap7 following all indications written in this thread, but it didn't work for me. I have windows 8 64bit and visual studio 2015.

I suggest to all to make these amending on file SiemensCom.vb:

1) change the return datatype of Write function to string instead of integer as below:
Code: [Select]
Public Function Write(startAddress As String, dataToWrite As String) As String Implements MfgControl.AdvancedHMI.Drivers.IComComponent.Write
        Dim temp(0) As String
        temp(0) = dataToWrite
        Write(startAddress, 1, temp)
        Return ("1")
        'Return Write(startAddress, 1, temp)
    End Function
2) Chenge the return line

Pay attention
Code: [Select]
Return("1") is a compromise because the function
Code: [Select]
MfgControl.AdvancedHMI.Drivers.IComComponent.Write returns back a string.

For easy use, in the attached file the amended SiemensCom.vb

Now I can use snap7. Easy to read and write DB, Merker, Coils etc... for example if you want set to 1 the Merker M18.2 using a BasicButton, you need just to select SetTrue the OutputType and fill M18.2 in the field PLCAddressClick.

Moreover I want underline the powerful of snap7 if compared with modbus. For example, writing a single bit inside a word with modbus, we need to read word, change it and send it back with the risk of data corruption. Snap7 has native fuction for single bit set/reset.

Best Regards e ciao Luciano
« Last Edit: January 30, 2021, 03:22:58 PM by LuckyAdvabced »

LuckyAdvabced

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Driver Siemens with Snap7
« Reply #5 on: February 01, 2021, 03:00:23 AM »
Hi all, one additional thing concerning the returned value on funcion
Code: [Select]
Public Function Write(startAddress As String, dataToWrite As String) As String Implements MfgControl.AdvancedHMI.Drivers.IComComponent.Write
        Dim temp(0) As String
        temp(0) = dataToWrite
        Write(startAddress, 1, temp)
        Return ("1")
        'Return Write(startAddress, 1, temp)
    End Function



Instead of Return("1") as string, we can jus modify the original
Code: [Select]
Return Write(startAddress, 1, temp) converting the result in a string like this
Code: [Select]
    Public Function Write(startAddress As String, dataToWrite As String) As String Implements MfgControl.AdvancedHMI.Drivers.IComComponent.Write
        Dim temp(0) As String
        temp(0) = dataToWrite
        Write(startAddress, 1, temp)
        'Return ("1")
        Return Write(startAddress, 1, temp).ToString()
    End Function

ciao

tatin

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Driver Siemens with Snap7
« Reply #6 on: February 03, 2021, 05:32:55 AM »
Hi Lucky, I'm glad the driver works for you but in V3.99y the Write function returns an Integer to see if the writing has been done. Also, in the code of the BasicButton component, the value returned by the Write function is never used.

MfgControl.AdvancedHMI.Drivers.IComComponent.Write(startAddress As String, dataToWrite As String) As Integer

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Driver Siemens with Snap7
« Reply #7 on: February 04, 2021, 09:08:03 PM »
Hi LUCKY,

I'd like to know which PLC's will get connected with this driver?
S7-1200
S7-1500
Siemens micro

LuckyAdvabced

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Driver Siemens with Snap7
« Reply #8 on: February 05, 2021, 11:22:34 AM »
Hi aquilmustafa.

I am using s7-1200

It works very well for my use.

Ciao Luciano.

lunenburger

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Driver Siemens with Snap7
« Reply #9 on: May 10, 2021, 03:38:36 PM »
I have followed the instructions, but I am getting the error:

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'snap7.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  Source=Snap7.net
  StackTrace:
   at Snap7.S7Client.Cli_Create()
   at Snap7.S7Client..ctor()
   at AdvancedHMIDrivers.SiemensCom.CreateDLLInstance() in C:\Users\christopher.curry\Downloads\AdvancedHMIv399xR1\AdvancedHMIDrivers\SiemensCom.vb:line 110
   at AdvancedHMIDrivers.SiemensCom.PollUpdateTimer_Tick(Object sender, EventArgs e) in C:\Users\christopher.curry\Downloads\AdvancedHMIv399xR1\AdvancedHMIDrivers\SiemensCom.vb:line 638
   at System.Timers.Timer.MyTimerCallback(Object state)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Driver Siemens with Snap7
« Reply #10 on: May 10, 2021, 10:46:52 PM »
Instead of adding snap7.dll file to Support/Siemens folder, remove it and then add it directly to the project where your SiemensCom.vb driver is and set it to Copy Always.

lunenburger

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Driver Siemens with Snap7
« Reply #11 on: May 11, 2021, 07:58:34 AM »
Thank you Godra for the reply.

I am pretty new to .net....
When adding the snap7.dll file to the project, do I do it at the top of the Solution Explorer where it shows My Project with the wrench symbol.
Also, do I add it as a reference or existing item.

And how do I set snap7.dll file to copy always?

Thank you

lunenburger

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Driver Siemens with Snap7
« Reply #12 on: May 11, 2021, 08:48:29 AM »
Hi Godra,
I have it working now.... disregard previous reply

and thanks again for the help!

lunenburger

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Driver Siemens with Snap7
« Reply #13 on: May 11, 2021, 09:33:49 AM »
Actually, I never did figure out how to set snap7.dll copy always.....

If someone could let me know where to set to copy always that would be great...

thank you

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Driver Siemens with Snap7
« Reply #14 on: May 11, 2021, 04:56:03 PM »
See the attached picture.