mirror of
https://github.com/naruxde/revpimodio2.git
synced 2026-09-30 23:04:29 +02:00
test: Cycle loop functions
This commit is contained in:
1 parent
1de230c1e2
commit
dc5906288c
2 files changed
+130
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
{"App":{"name": "PiCtory", "version": "1.2.3","saveTS": "20170826120906","language": "en","layout": {"north":{"size":70,"initClosed":false,"initHidden":false},"south":{"size":480,"initClosed":false,"initHidden":false,"children":{"layout1":{"east":{"size":500,"initClosed":false,"initHidden":false}}}},"east":{"size":70,"initClosed":true,"initHidden":false,"children":{"layout1":{"north":{"size":100,"initClosed":false,"initHidden":false},"south":{"size":98,"initClosed":false,"initHidden":false}}}},"west":{"size":200,"initClosed":false,"initHidden":false,"children":{"layout1":{}}}}},"Summary":{"inpTotal": 338,"outTotal": 113},"Devices":[{"catalogNr": "RevPiCore","GUID": "4ebb85e8-92ea-415d-b191-cc58c2857c0a","id": "device_RevPiCore_20170404_1_2_001","type": "BASE","productType": "95","position": "0","name": "picore01","bmk": "RevPi Core V1.2","inpVariant": 0,"outVariant": 0,"comment": "This is a RevPiCore Device","offset": 0,"inp": {"0": ["RevPiStatus","0","8","0",true,"0000", "",""],"1": ["RevPiIOCycle","0","8","1",true,"0001", "",""],"2": ["RS485ErrorCnt","0","16","2",false,"0002", "",""],"3": ["Core_Temperatur","0","8","4",false,"0003", "",""],"4": ["Core_Frequency","0","8","5",false,"0004", "",""]},"out": {"0": ["RevPiLED","0","8","6",true,"0005", "",""],"1": ["RS485ErrorLimit1","10","16","7",false,"0006", "",""],"2": ["RS485ErrorLimit2","1000","16","9",false,"0007", "",""]},"mem": {},"extend": {}},{"catalogNr": "RevPiDI","GUID": "2e2c089e-6bef-14c0-852b-41b7cf48d846","id": "device_RevPiDI_20160818_1_0_001","type": "LEFT_RIGHT","productType": "97","position": "32","name": "di01","bmk": "RevPi DI","inpVariant": 0,"outVariant": 0,"comment": "","offset": 11,"inp": {"0": ["notaus_ok","0","1","0",true,"0000", "","0"],"1": ["motorschutz_ok","0","1","0",true,"0001", "","1"],"2": ["fu_ok","0","1","0",true,"0002", "","2"],"3": ["fu_motoran","0","1","0",true,"0003", "","3"],"4": ["I_5","0","1","0",true,"0004", "","4"],"5": ["I_6","0","1","0",true,"0005", "","5"],"6": ["I_7","0","1","0",true,"0006", "","6"],"7": ["I_8","0","1","0",true,"0007", "","7"],"8": ["t_automatik","0","1","0",true,"0008", "","8"],"9": ["t_start","0","1","0",true,"0009", "","9"],"10": ["t_stop","0","1","0",true,"0010", "","10"],"11": ["t_quit","0","1","0",true,"0011", "","11"],"12": ["t_notaus","0","1","0",true,"0012", "","12"],"13": ["I_14","0","1","0",true,"0013", "","13"],"14": ["I_15","0","1","0",true,"0014", "","14"],"15": ["I_16","0","1","0",true,"0015", "","15"],"16": ["Status","0","16","4",false,"0016", "",""],"17": ["Counter_1","0","32","6",false,"0017", "",""],"18": ["Counter_2","0","32","10",false,"0018", "",""],"19": ["Counter_3","0","32","14",false,"0019", "",""],"20": ["Counter_4","0","32","18",false,"0020", "",""],"21": ["Counter_5","0","32","22",false,"0021", "",""],"22": ["Counter_6","0","32","26",false,"0022", "",""],"23": ["Counter_7","0","32","30",false,"0023", "",""],"24": ["Counter_8","0","32","34",false,"0024", "",""],"25": ["Counter_9","0","32","38",false,"0025", "",""],"26": ["Counter_10","0","32","42",false,"0026", "",""],"27": ["Counter_11","0","32","46",false,"0027", "",""],"28": ["Counter_12","0","32","50",false,"0028", "",""],"29": ["Counter_13","0","32","54",false,"0029", "",""],"30": ["Counter_14","0","32","58",false,"0030", "",""],"31": ["Counter_15","0","32","62",false,"0031", "",""],"32": ["Counter_16","0","32","66",false,"0032", "",""],"33": ["Output_Status","0","16","2",false,"0050", "",""]},"out": {"0": ["Output","0","16","70",false,"0051", "",""],"1": ["PWM_1","0","8","72",false,"0052", "",""],"2": ["PWM_2","0","8","73",false,"0053", "",""],"3": ["PWM_3","0","8","74",false,"0054", "",""],"4": ["PWM_4","0","8","75",false,"0055", "",""],"5": ["PWM_5","0","8","76",false,"0056", "",""],"6": ["PWM_6","0","8","77",false,"0057", "",""],"7": ["PWM_7","0","8","78",false,"0058", "",""],"8": ["PWM_8","0","8","79",false,"0059", "",""],"9": ["PWM_9","0","8","80",false,"0060", "",""],"10": ["PWM_10","0","8","81",false,"0061", "",""],"11": ["PWM_11","0","8","82",false,"0062", "",""],"12": ["PWM_12","0","8","83",false,"0063", "",""],"13": ["PWM_13","0","8","84",false,"0064", "",""],"14": ["PWM_14","0","8","85",false,"0065", "",""],"15": ["PWM_15","0","8","86",false,"0066", "",""],"16": ["PWM_16","0","8","87",false,"0067", "",""]},"mem": {"0": ["InputMode_1","0","8","88",false,"0033", "",""],"1": ["InputMode_2","0","8","89",false,"0034", "",""],"2": ["InputMode_3","0","8","90",false,"0035", "",""],"3": ["InputMode_4","0","8","91",false,"0036", "",""],"4": ["InputMode_5","0","8","92",false,"0037", "",""],"5": ["InputMode_6","0","8","93",false,"0038", "",""],"6": ["InputMode_7","0","8","94",false,"0039", "",""],"7": ["InputMode_8","0","8","95",false,"0040", "",""],"8": ["InputMode_9","0","8","96",false,"0041", "",""],"9": ["InputMode_10","0","8","97",false,"0042", "",""],"10": ["InputMode_11","0","8","98",false,"0043", "",""],"11": ["InputMode_12","0","8","99",false,"0044", "",""],"12": ["InputMode_13","0","8","100",false,"00Line truncated
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Test cycle loop functions."""
|
||||||
|
__author__ = "Sven Sager"
|
||||||
|
__copyright__ = "Copyright (C) 2024 Sven Sager"
|
||||||
|
__license__ = "GPLv2"
|
||||||
|
|
||||||
|
from os.path import dirname, join
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
import revpimodio2
|
||||||
|
from tests import TestRevPiModIO
|
||||||
|
from tests.helper import ExitThread
|
||||||
|
|
||||||
|
event_data = (None, None)
|
||||||
|
|
||||||
|
|
||||||
|
def xxx(name, value):
|
||||||
|
"""Test event function."""
|
||||||
|
global event_data
|
||||||
|
event_data = (name, value)
|
||||||
|
|
||||||
|
|
||||||
|
def xxx_thread(th):
|
||||||
|
"""Test event function with thread."""
|
||||||
|
global event_data
|
||||||
|
event_data = (th.ioname, th.iovalue)
|
||||||
|
th.stop()
|
||||||
|
|
||||||
|
|
||||||
|
def xxx_timeout(name, value):
|
||||||
|
"""Test event with long timeout."""
|
||||||
|
sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCycleloop(TestRevPiModIO):
|
||||||
|
|
||||||
|
data_dir = dirname(__file__)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
global event_data
|
||||||
|
event_data = (None, None)
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_cycleloop(self):
|
||||||
|
"""Testet Cycleloop-Funktion."""
|
||||||
|
rpi = self.modio()
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
rpi.cycleloop(zyklus, 51)
|
||||||
|
|
||||||
|
rpi.autorefresh_all()
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
rpi.cycleloop(False, 51)
|
||||||
|
rpi.cycleloop(zyklus, 51)
|
||||||
|
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
rpi.cycleloop(lambda: None)
|
||||||
|
|
||||||
|
rpi.exit()
|
||||||
|
|
||||||
|
rpi.autorefresh_all()
|
||||||
|
sleep(0.1)
|
||||||
|
rpi._imgwriter.stop()
|
||||||
|
sleep(0.1)
|
||||||
|
with self.assertRaisesRegex(RuntimeError, r"autorefresh thread not running"):
|
||||||
|
rpi.cycleloop(zyklus)
|
||||||
|
|
||||||
|
rpi.exit()
|
||||||
|
|
||||||
|
def test_cycleloop_longtime(self):
|
||||||
|
"""Testet no data."""
|
||||||
|
rpi = self.modio(autorefresh=True)
|
||||||
|
rpi.debug = -1
|
||||||
|
rpi._imgwriter.lck_refresh.acquire()
|
||||||
|
th_ende = ExitThread(rpi, 4)
|
||||||
|
th_ende.start()
|
||||||
|
|
||||||
|
with self.assertWarnsRegex(
|
||||||
|
RuntimeWarning, r"no new io data in cycle loop for 2500 milliseconds"
|
||||||
|
):
|
||||||
|
rpi.cycleloop(zyklus)
|
||||||
|
|
||||||
|
rpi.exit()
|
||||||
|
|
||||||
|
def test_cycletools(self):
|
||||||
|
rpi = self.modio()
|
||||||
|
ct = revpimodio2.Cycletools(50, rpi)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
ct.changed("bad_value")
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
ct.changed(rpi.io.magazin1, edge=revpimodio2._internal.RISING)
|
||||||
|
del rpi
|
||||||
|
|
||||||
|
def test_run_plc(self):
|
||||||
|
self.assertEqual(
|
||||||
|
revpimodio2.run_plc(
|
||||||
|
zyklus,
|
||||||
|
cycletime=30,
|
||||||
|
procimg=self.fh_procimg.name,
|
||||||
|
configrsc=join(self.data_dir, "config.rsc"),
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def zyklus(ct):
|
||||||
|
"""Cycle program for testing the cycle loop."""
|
||||||
|
if ct.flag10c:
|
||||||
|
ct.set_ton("test", 100)
|
||||||
|
ct.set_tof("test", 100)
|
||||||
|
ct.set_tp("test", 100)
|
||||||
|
ct.set_tonc("testc", 3)
|
||||||
|
ct.set_tofc("testc", 3)
|
||||||
|
ct.set_tpc("testc", 3)
|
||||||
|
|
||||||
|
ct.get_ton("test")
|
||||||
|
ct.get_tof("test")
|
||||||
|
ct.get_tp("test")
|
||||||
|
ct.get_tonc("testc")
|
||||||
|
ct.get_tofc("testc")
|
||||||
|
ct.get_tpc("testc")
|
||||||
|
|
||||||
|
t = ct.runtime
|
||||||
|
|
||||||
|
# Check change
|
||||||
|
ct.changed(ct.io.v_druck, edge=revpimodio2._internal.RISING)
|
||||||
|
ct.changed(ct.io.magazin1)
|
||||||
|
|
||||||
|
if ct.flag20c:
|
||||||
|
return 1
|
||||||
Reference in new issue
Block a user