运行python脚本后,奇怪的回复

时间:2017-02-05 11:16:18

标签: python plc

我搜索并研究了我的问题,但这有点困难,因为我没有真正的错误(代码)来搜索。

我尝试在我的RPI和PLC之间进行通信,运行脚本后我得到(python Temp_buiten.py)响应如下,但脚本的输出是正确的,我将值作为Float输入PLC就像我想要的但是我得到的每个循环都在我的命令行中响应:

pi@raspberrypi:~/scripts $ python Temp_buiten.py
@▒
A▒
pi@raspberrypi:~/scripts $

我不是python程序员,所以我希望有人可以帮助我。我尝试运行的脚本:

#!python3
#---------------Basis-------------------------
import sys
import datetime
import time
import os
import subprocess
import urllib2
import json
import base64
#--------------PLC Snap7----------------------
import S71200
from time import sleep
import snap7
from snap7.util import *
import struct
#---------------Settings----------------------
domoticzserver="192.168.1.210:8080"
domoticzusername = "Secret"
domoticzpassword = "Secret"
device = "558"
log_to_file = False
plc = S71200.S71200("192.168.1.242")
#---------------Variabelen--------------------
temp1 = 0.0
temp_woonkamer = {}
hum = 0.0
hum_stat = 0 #0 t/m 4
sensorids = ["28-0000062723e6"]

#---------------Wachtwoordenzooi--------------
base64string = base64.encodestring('%s:%s' % (domoticzusername,    domoticzpassword)).replace('\n', '')
domoticzurl = 'http://'+ domoticzserver +'/json.htm?  type=devices&rid='+device
#---------------Logging-----------------------
def log(message):
   print message
   if log_to_file == True:
      logfile = open(sys.argv[0] + '.log', "a")
      logfile.write(message + "\n")
      logfile.close()
#---------------Info ophalen------------------
def domoticzrequest (url):
  request = urllib2.Request(url)
  request.add_header("Authorization", "Basic %s" % base64string)
  #print(request)
  response = urllib2.urlopen(request)
  return response.read()
#--------------Status-------------------------
json_object = json.loads(domoticzrequest(domoticzurl))

if json_object["status"] == "OK":
    temp1 = json_object["result"][0]['Temp']
    hum = json_object["result"][0]['Humidity']
    plc.writeMem("FREAL204",temp1)
    sleep(1)
else:
    print(device + "NOT OK")


for sensor in range(len(sensorids)):
    tfile = open("/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave")
  # Lees alle dat uit het "bestand" in een variabele.
    text = tfile.read()
  # Sluit het "bestand" nadat we het gelezen hebben.
    tfile.close()
  # We gaan nu de tekst splitsen per nieuwe regel (\n)
  # en we selecteren de 2e regel [1] (1e regel = [0])
    secondline = text.split("\n")[1]
  # Splits de regel in "woorden", er wordt gespleten op de spaties.
  # We selecteren hier het 10 "woord" [9] (tellend vanaf 0)
    temperaturedata = secondline.split(" ")[9]
  # De eerste 2 karakters zijn "t=", deze moeten we weghalen.
  # we maken meteen van de string een integer (nummer).
    temperature = float(temperaturedata[2:])
  # De temperatuurwaarde moeten we delen door 1000 voor de juiste waarde.
    temp_woonkamer[sensor] = temperature / 1000

    plc.writeMem("FREAL200",temp_woonkamer[sensor])
    sleep(1)

1 个答案:

答案 0 :(得分:0)

Dave看起来你正在使用的S71200 python库每次调用时都会打印到控制台。第106行source to S71200.py 我一定忘了把它拿出来。 -SimplyAutomationized

如果您想重新下载,我刚刚提交了修复程序。欢呼声