B4A Library Moka7 (interfacing natively Siemens S7 PLCs)

Hi everyone

this is my first wrapped library.

It is based on the Moka7 project : http://snap7.sourceforge.net/

Moka7 is the Java port of Snap7 Client , and the snap7 is :

"Snap7 is an open source, 32/64 bit, multi-platform Ethernet communication suite for interfacing natively with Siemens S7 PLCs. The new CPUs 1200/1500, the old S7200, the small LOGO 0BA7/0BA8 and SINAMICS Drives are also partially supported"

In attach there are tha library , a simple example B4A project and a exhaustive Pdf Manual .
The library is very simple to use .

Many tanks to Davide Nardella the Snap7 author.


If you haven't a Plc "at home", it even works with Plcsim and NetToPlcsim tool

PS: Due to the Forum upload limits , rename the file "Moka7-refman.z02.zip" to "Moka7-refman.z02" and "Moka7-refman.z01.zip" to "Moka7-refman.z01" and unzip
 

Attachments

  • moka7.apk
    139.3 KB · Views: 655
  • Moka7.zip
    317.4 KB · Views: 814
  • Moka7-refman.z01.zip
    354 KB · Views: 717
  • Moka7-refman.z02.zip
    354 KB · Views: 687
  • Moka7-refman.zip
    314.7 KB · Views: 699
Last edited:

coslad

Well-Known Member
Licensed User
Longtime User
As ask me from Alan1968 , i modified the library so it can connect to a not default port 102 , to connect you must specify the port :

public int ConnectTo(String Address, int Rack, int Slot,int Port)


PS: "likes" are appreciated
 

Attachments

  • ver11.zip
    15.6 KB · Views: 556

alan1968

Active Member
Licensed User
Longtime User
thank you , I can now access to internet at 5 logo with the forwadin port ! myhomedns.ddns.com:102 ,103,104,105

not possible before !
 

Tom1s

Member
Licensed User
Longtime User
I have a problem. I try to get connection and the program says connected but nothing else.
I try to connect to Siemens LOGO 0BA8.
Should i get Cpu info with the program?

In this I try to get it stopped but no luck

I tried all three connection types.

B4X:
Sub Button1_Click
Dim a As Int

plc.SetConnectionType(s7_constant.S7_BASIC)
plc.SetConnectionParams("192.168.100.15",0x0300,0x0200,102)

If plc.Connect=0  Then
     info.text="Connected"
    If plc.PlcStop=0 Then
    ToastMessageShow("STOPPED",True)
    Else
    ToastMessageShow("NOT STOPPED",True)
    End If
Else
     info.text="Not Connected"
End If
End Sub
 

Tom1s

Member
Licensed User
Longtime User
Connection was OK. Needed to put Vm adresses to LOGO or use static adresses and read those.

Now I can read 4-20mA SENSOR input from logo=)
 

coslad

Well-Known Member
Licensed User
Longtime User
Hi, until now I used my library to connect whit a s7 300 ,now I am trying to connect with a logo8 ,but Something doesn't works. Can somebody share a little sample project? Thanks
 

Pere_Suria

New Member
Licensed User
First of all, excuse my English

I am trying to connect an android screen with a s7 1200 and so far the attempts have been null, I used your example, but when you press the button 1 to establish the connection the android program closes abruptly, someone has some example of connection with an s7 1200?

Thank you
 

coslad

Well-Known Member
Licensed User
Longtime User
Hi, you have to set the right parameter, maybe you have to adapt the example to the 1.1 library version, I mean that in the last library version you have to explicit declare the 102 default port.

Can you post the error log?
 

Pere_Suria

New Member
Licensed User
there is no error code, simply the application is closed

In the plc should something more be done apart from what is explained in pages 11 and 12 of the moka manual?

PS: to see a small video with what I find rename the file "img_657.zip.001.zip" to "img_657.zip.001", "img_657.zip.002.zip" to "img_657.zip.002", "img_657.zip.003.zip" to "img_657.zip.003", "img_657.zip.004.zip" to "img_657.zip.004" and unzip



B4X:
Sub Button1_Click
    Dim a As Int
  
    plc.SetConnectionType(s7_constant.PG)
  
    If plc.ConnectTo("192.168.0.60",0,1,102) = 0 Then
        info.text="Connected"
    Else
        info.text="Not Connected"
    End If
End Sub
 

Attachments

  • IMG_0657.zip.001.zip
    500 KB · Views: 382
  • IMG_0657.zip.002.zip
    500 KB · Views: 341
  • IMG_0657.zip.003.zip
    500 KB · Views: 367
  • IMG_0657.zip.004.zip
    455.4 KB · Views: 362

coslad

Well-Known Member
Licensed User
Longtime User
Are you sure the Rack and Slot parameters are right ? , you have to check them in the Tia Portal hardware configuration .

For example The S7 300 has rack = 0 and slot = 2 .

You used rack = 0 and slot = 1 maybe the slot should be = 2 as s7 300 ?

I never used a S7 1200.

Try to execute the app in the debug mode and copy and paste the log file .
 

Marko62

New Member
I have tested your program. It works smoothly in "Debug mode" while in "Release mode" an error occurred.
"An error has occurred in sub:main:button1:click(java line: 413) android.os.NetworkOnMainThreadException

Marko
 

DonManfred

Expert
Licensed User
Longtime User
Top