Make a fake Pfeiffer device for testing the script context driver
This driver controls the needle valve on the Oxford Mercury
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# vim: ft=python ts=8 sts=4 sw=4 expandtab autoindent smartindent nocindent
|
||||
# Fake Pfeiffer Temperature Controller
|
||||
#
|
||||
# Author: Douglas Clowes 2014
|
||||
#
|
||||
from PfeifferDevice import PfeifferDevice
|
||||
import random
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
class Pfeiffer_tpg261(PfeifferDevice):
|
||||
"""Pfeiffer TPG261 temperature controller object - simulates the device"""
|
||||
|
||||
def __init__(self):
|
||||
PfeifferDevice.__init__(self)
|
||||
print Pfeiffer_tpg261.__name__, "ctor"
|
||||
self.RANDOM = 0.0
|
||||
self.IDN = "Simulated Pfeiffer TPG261"
|
||||
self.reset_powerup()
|
||||
self.pressure = 3.14156E-02
|
||||
|
||||
def doCommand(self, command, params):
|
||||
print Pfeiffer_tpg261.__name__, "Command:", command, params
|
||||
return PfeifferDevice.doCommand(self, command, params)
|
||||
|
||||
def doQuery(self, command, params):
|
||||
print Pfeiffer_tpg261.__name__, "Query:", command, params
|
||||
return PfeifferDevice.doQuery(self, command, params)
|
||||
|
||||
def reset_powerup(self):
|
||||
print Pfeiffer_tpg261.__name__, "reset_powerup"
|
||||
self.LAST_ITERATION = 0
|
||||
|
||||
def doIteration(self):
|
||||
delta_time = time.time() - self.LAST_ITERATION
|
||||
if delta_time < 1:
|
||||
return
|
||||
#print "DoIteration:", delta_time
|
||||
self.LAST_ITERATION = time.time()
|
||||
|
||||
def doCommandSET(self, cmd, args):
|
||||
if len(args) > 0:
|
||||
print "SET", args, float(args[0])
|
||||
self.pressure = float(args[0])
|
||||
print "TODO implement Command: \"SET\" in \"" + cmd + ":" + ":".join(args) + "\""
|
||||
|
||||
def doQueryPR1(self, cmd, args):
|
||||
self.write("0,%11.4E" % self.pressure)
|
||||
#print "TODO implement Query: \"PR1\" in \"" + cmd + ":" + ":".join(args) + "\""
|
||||
|
||||
if __name__ == '__main__':
|
||||
from PfeifferProtocol import PfeifferProtocol
|
||||
|
||||
class TestFactory:
|
||||
def __init__(self):
|
||||
print self.__class__.__name__, "ctor"
|
||||
self.numProtocols = 0
|
||||
def write(self, data):
|
||||
print "test write:", data,
|
||||
def loseConnection(self):
|
||||
print "test lose connection"
|
||||
test_factory = TestFactory()
|
||||
test_device = Pfeiffer_tpg261()
|
||||
test_protocol = PfeifferProtocol(test_device, "\r\n")
|
||||
test_protocol.factory = test_factory
|
||||
test_protocol.transport = test_factory
|
||||
test_device.protocol = test_protocol
|
||||
test_device.protocol.connectionMade()
|
||||
commands = ["PR1", "SET 3.1415926E-03", "PR1"]
|
||||
for cmd in commands:
|
||||
print "Command:", cmd
|
||||
test_device.protocol.dataReceived(cmd)
|
||||
test_device.protocol.dataReceived("\r\n\5")
|
||||
test_device.protocol.connectionLost("Dunno")
|
||||
Reference in New Issue
Block a user