AdvancedHMI Software

General Category => Open Discussion => Topic started by: tatin on November 08, 2020, 03:45:27 PM

Title: Driver Siemens with Snap7
Post by: tatin 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...
Title: Re: Driver Siemens with Snap7
Post by: Archie on November 08, 2020, 04:40:35 PM
Nice contribution! I suspect a lot of people will be looking forward to trying this out.
Title: Re: Driver Siemens with Snap7
Post by: Noe 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.
Title: Re: Driver Siemens with Snap7
Post by: bachphi 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
(https://i.postimg.cc/J0BSfsqQ/Snap7-Siemens-Driver.png)
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.
Title: Re: Driver Siemens with Snap7
Post by: LuckyAdvabced 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
Title: Re: Driver Siemens with Snap7
Post by: LuckyAdvabced 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
Title: Re: Driver Siemens with Snap7
Post by: tatin 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
Title: Re: Driver Siemens with Snap7
Post by: aquilmustafa 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
Title: Re: Driver Siemens with Snap7
Post by: LuckyAdvabced on February 05, 2021, 11:22:34 AM
Hi aquilmustafa.

I am using s7-1200

It works very well for my use.

Ciao Luciano.
Title: Re: Driver Siemens with Snap7
Post by: lunenburger 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)
Title: Re: Driver Siemens with Snap7
Post by: Godra 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.
Title: Re: Driver Siemens with Snap7
Post by: lunenburger 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
Title: Re: Driver Siemens with Snap7
Post by: lunenburger on May 11, 2021, 08:48:29 AM
Hi Godra,
I have it working now.... disregard previous reply

and thanks again for the help!
Title: Re: Driver Siemens with Snap7
Post by: lunenburger 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
Title: Re: Driver Siemens with Snap7
Post by: Godra on May 11, 2021, 04:56:03 PM
See the attached picture.
Title: Re: Driver Siemens with Snap7
Post by: aquilmustafa on May 15, 2021, 08:45:42 AM
Hi All,

My S7-1200 PLC Project has MW and MD variables instead of DB1.DB0 format. How can i use it?

Please guide me as to how I can accommodate this into existing project.
Title: Re: Driver Siemens with Snap7
Post by: tatin on May 16, 2021, 07:43:24 AM
Hi, try changing DB1.DB to M: M0.0, MB0.0, MB0, MW0, MD0, ...  same with I(input), Q(output)
Title: Re: Driver Siemens with Snap7
Post by: tatin on May 16, 2021, 08:02:46 AM
Hi again, i have a more updated version.

https://drive.google.com/file/d/1xPVYMU-rqc6VH0835sxEOcw59L1iLS0t/view?usp=sharing
Title: Re: Driver Siemens with Snap7
Post by: aquilmustafa on May 18, 2021, 11:24:37 PM
Thanks a lot Tatin. I'll go through it and comeback to you.
Title: Re: Driver Siemens with Snap7
Post by: lunenburger on May 20, 2021, 07:01:24 AM
Thank you Godfra and Tatin for the help with this driver..... it is greatly appreciated.

I have been using the ControlLogix driver, and I have been creating the code:

Code: [Select]
Dim BottomMotorSpeed As Integer = EthernetIPforCLXCom1.Read("BottomMotorSpeed")


Is there a comparable function in the Siemens driver to the EthernetIPforCLXCom1.Read?

Or do I have to do something like the following:

Code: [Select]
Dim recipesteps As Integer

        If e.PlcAddress = "MW10" Then
            recipesteps = e.Values(0)
        End If

Thank you again for the help....
Title: Re: Driver Siemens with Snap7
Post by: tatin on May 20, 2021, 09:13:42 AM
Hi, this functionality is not implemented in the driver, as it is based on Snap7, only the memory addresses can be accessed.
Title: Re: Driver Siemens with Snap7
Post by: MEDALI1TN on July 16, 2021, 04:41:18 AM
Hello Tatin,
can you please write a simple code (for a beginner) how can i read a value from PLC using the driver.
The example of siemens variables :
(DBxxxx,DDxxxx)
(DBxxx,Dxx.x)
(Exxxx.x)
(PEWxxxx)
Title: Re: Driver Siemens with Snap7
Post by: tatin on July 20, 2021, 11:24:39 AM
Hello, it is not necessary to write code to read a value from the PLC, you just have to open the example project, add the SiemensCom driver as explained by a colleague previously, insert a BasicLabel on the screen and finally put in the property PLCAddressValue for example DB1.DBW0. Well, don't forget to put the SiemensCom driver in the ComComponent property. As well as assigning the IP address to the driver.
In the source code of the driver are all the possible examples for DBs, but also if you change DB1.DB to M, I, Q you can access these memory areas.
Bear in mind that this driver forces you to define access to a DB as not optimized or something like that in the TIA Portal project.
I hope I have helped you with your question ...
Greetings...
Title: Re: Driver Siemens with Snap7
Post by: ScottM on June 14, 2022, 04:23:10 AM
I know this thread is almost a year old but had there been any more development on this driver? Has it been tested with S7-300? As our company has been growing over the years all our new equipment has been coming in from Germany and its all Siemens..

Thanks
Title: Re: Driver Siemens with Snap7
Post by: tatin on June 19, 2022, 04:19:37 PM
I'm sorry but I have not used the driver again, it should work with the S7-300 but keep in mind that I have not tested it much, test it well because it may have errors because I am not an expert programmer.
Title: Re: Driver Siemens with Snap7
Post by: Noe on June 21, 2022, 01:28:33 PM
I know this thread is almost a year old but had there been any more development on this driver? Has it been tested with S7-300? As our company has been growing over the years all our new equipment has been coming in from Germany and its all Siemens..

Thanks

I've been using the Modbus driver succesfully but with S7-1200 and S7-1500 and works pretty well, with almost all the functionallity of all the other drivers. I do not know if S7-300 supports it. You only have to write code in VB to convert values that are not integers, like strings. I can share some code I used if want.