TOP
SSV Software Systems Register  Register
Log in to check your private messages  Log in to check your private messages
Startseite FAQ Search Mitglieder Profile  Log in 
SSV Support-Forum
Python nutzen …

 
Post new topic   Reply to topic    SSV-Forum Forum Index >>> IGW/935
<<< Previous topic - Next topic >>>  
Display posts from previous:   
Author Message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 16.05.2013, 10:46    Post subject: Python nutzen … Reply with quote

Hallo Forum.

Ein IGW/935 besitzt ab Werk eine vorinstallierte Python-Laufzeitumgebung (Version 2.6.1). Um Python zu nutzen, muss auf einem externen PC ein Python-Quellcode in einer Datei gespeichert werden.

Hierzu ein Beispiel: Speichern Sie die folgenden Zeilen Python-Code auf dem PC in einer Datei mit dem Namen test.py.

Code:
import httplib
import time

flag= 1
while flag:
    conn= httplib.HTTPConnection("3935003697.test.jsapp.us")
    conn.request("GET", "/count")
    r1= conn.getresponse()
    data= r1.read()
    if data == "This test server has expired":
        flag= 0
        print "Server not ready."
    else:
        time.sleep(1)
        print data


Übertragen Sie diese Datei per FTP vom PC zum IGW/935 in das Verzeichnis /flash. Starten Sie dann dieses Python-Skript im Rahmen einer Telnet- bzw. SSH-Sitzung einfach durch die Eingabe:

Code:
cd /flash
python test.py


Das ist schon alles.

Gruß KDW


Last edited by kdw on 09.08.2014, 06:55; edited 1 time in total
Back to top
View user's profile Send private message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 20.06.2013, 11:33    Post subject: CGI per Python … Reply with quote

Hallo Forum.

Mit Hilfe der vorinstallierten Python-Laufzeitumgebung kann man auch CGI-Programme für den IGW/935-lighttpd-Webserver erstellen.

Zuvor muss allerdings der lighttpd-Konfigurationsdatei /etc/lighttpd/lighttpd.conf mitgeteilt werden, dass Python-Skriptdateien mit der Endung *.py als CGI-Programme zu behandeln sind. Erweitern Sie diese Konfigurationsdatei um die beiden folgenden Python-bezogenen Einträge:

Code:
static-file.exclude-extensions = (".cgi", ".sh", ".php", "py")
cgi.assign = (".cgi" => "", ".sh" => "/bin/sh", ".php" => "/usr/bin/php", ".py" => "/usr/bin/python"


Erstellen Sie dann eine Datei mit dem Namen hello-cgi.py und speichern Sie den folgenden Python-Code in dieser Datei:

Code:
#!/usr/bin/python

print "Content-type: text/html"
print
print "<html><head>"
print "<title>Hello World from Python</title>"
print "</head><body>"
print "Hello World!"
print "</body></html>"


Übertragen Sie diese Datei in das Verzeichnis /www/cgi-bin. Starten Sie nun auf Ihrem PC einen Webbrowser und adressieren Sie:

Code:
http://192.168.0.140/cgi-bin/hello-cgi.py


Der Browser müsste Ihnen nun das „Hello World!“ des Python-Skripts anzeigen.

Gruß KDW
Back to top
View user's profile Send private message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 28.06.2013, 15:17    Post subject: Modbus per Python … Reply with quote

Hallo Forum.

Auch per Python kann man auf externe Modbus-Baugruppe zugreifen. Man sollte allerdings eine geeignete Bibliothek, wie zum Beispiel Modbus-TK benutzen. Siehe hierzu auch:

https://code.google.com/p/modbus-tk/wiki/ModbusMasterExample

Die Installationsbeschreibung zu Modbus-TK bezieht sich allerdings auf PCs. Beim IGW/935 gehen Sie bitte wie folgt vor:

1. Laden Sie die von uns zusammengestellte Archivdatei igw935_python-modbus-tk.tar.gz per FTP in das Unterverzeichnis /tmp des IGW/935.

2. Führen Sie dann in einer Telnet-Sitzung die folgenden Befehle aus:

Code:
cd /
remount rw
tar -xzf /tmp/igw935_python-modbus-tk.tar.gz
remount ro


Das ist alles. Nun können Sie Python-Anwendungen mit Modbus-Unterstützung für das IGW/935 erstellen.

Gruß KDW
Back to top
View user's profile Send private message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 14.09.2014, 07:26    Post subject: Erste Schritte … Reply with quote

Hallo Forum.

Für alle, die noch nicht ganz so viel Python-Erfahrung besitzen, findet man unter

http://www.tutorialspoint.com/python/index.htm

ein sehr gutes Nachschlagewerk.

Gruß KDW
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SSV-Forum Forum Index >>> IGW/935 All times are GMT + 1 Hour
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

SSV Software Systems GmbH

Dünenweg 5
30419 Hannover

Fon: +49(0)511  ·  40 000-0
Fax: +49(0)511  ·  40 000-40

sales@ssv-embedded.de


Impressum    ·    Datenschutz    ·    AGB

© 2023 SSV SOFTWARE SYSTEMS GmbH. Alle Rechte vorbehalten.

ISO 9001:2015