ich habe das mit Python 3 gelöst. Du musst dir noch mit „sudo pip3 install psutil“ die psutil Bibliothek installieren.
Mit dieser Bibliothek kannst du die CPU Auslastung sowie die Speicherauslastung auslesen.
Hier ist mein Python Programm:
Code: Select all
import struct
import psutil
import time
class RevPiConnect():
# Central process iamge offset values...
REVPISTATUS =113 #RevPi Connect Offsets mit piTest -d ermittelt.
REVPIIOCYCLE =114
CORE_TEMPERATUR =117
CORE_FREQUENCY =118
REVPILED =119
MB_RTU_REG_OUT1 =188 #Modbus RTU Slave Offsets mit piTest -d ermittelt.
MB_RTU_REG_OUT2 =190
MB_RTU_REG_OUT3 =192
MB_RTU_REG_OUT4 =194
f = None # piControl access device
def __init__(self):
self.f=open("/dev/piControl0","wb+",0)
return
#.-----------------------------------------------
def getRevPiStatus(self):
self.f.seek(self.REVPISTATUS)
x = self.f.read(1)
s = struct.unpack('B',x)
i = s[0]
return i
def getRevPiIOCycle(self):
self.f.seek(self.REVPIIOCYCLE)
x = self.f.read(1)
s = struct.unpack('B',x)
i = s[0]
return i
def getCore_Temperatur(self):
self.f.seek(self.CORE_TEMPERATUR)
x = self.f.read(1)
s = struct.unpack('B',x)
i = float(s[0])
return i
def getCore_Frequency(self):
self.f.seek(self.CORE_FREQUENCY)
x = self.f.read(1)
s = struct.unpack('B',x)
i = s[0]*10
return i
def getRevPiLED(self):
self.f.seek(self.REVPILED)
x = self.f.read(1)
s = struct.unpack('B',x)
i = s[0]
return i
def setRevPiLED(self,LED):
self.f.seek(self.REVPILED)
x = struct.pack('B',LED)
self.f.write(x)
return
def setMbRtuTemp(self,TEMP):
self.f.seek(self.MB_RTU_REG_OUT1)
x = struct.pack('B',TEMP)
self.f.write(x)
return
def setMbRtuCPU(self,TEMP):
self.f.seek(self.MB_RTU_REG_OUT2)
x = struct.pack('B',TEMP)
self.f.write(x)
return
def setMbRtuDISK(self,TEMP):
self.f.seek(self.MB_RTU_REG_OUT3)
x = struct.pack('B',TEMP)
self.f.write(x)
return
def run(self):
while True:
time.sleep(10)
temp = (int)(self.getCore_Temperatur())
self.setMbRtuTemp(temp)
cpu = (int)(psutil.cpu_percent(interval=1))
self.setMbRtuCPU(cpu)
disk = (int)(psutil.disk_usage('/').percent)
self.setMbRtuDISK(disk)
RevPi = RevPiConnect()
RevPi.run()