Я использую Python для создания сценария для программы, которая будет запускаться с помощью программы для жарки Artisan-Scope.Программа уже работает с моим устройством (Phidgets 1045_1B), но мне нужно больше фильтровать по показаниям температуры.Я хотел бы, чтобы программа производила выборку со скоростью 32 мс и организовывала эти 30 выборок в секунду в порядке возрастания.Затем я хотел бы, чтобы самые низкие 10 образцов были средними и возвращались в программу Artisan для анализа.
Это то, что я имею до сих пор, но мне нужна помощь, чтобы выяснить, как организовать образцы и усреднить их, прежде чем дать одно измерение температуры Artisan.
import sys
import time
import traceback
from Phidget22.Devices.TemperatureSensor import *
from Phidget22.PhidgetException import *
from Phidget22.Phidget import *
from Phidget22.Net import *
try:
from PhidgetHelperFunctions import *
except ImportError:
sys.stderr.write("\nCould not find PhidgetHelperFunctions. Either add PhdiegtHelperFunctions.py to your project folder "
"or remove the import from your project.")
sys.stderr.write("\nPress ENTER to end program.")
readin = sys.stdin.readline()
sys.exit()
def onAttachHandler(self):
ph = self
try:
#If you are unsure how to use more than one Phidget channel with this event, we recommend going to
#www.phidgets.com/docs/Using_Multiple_Phidgets for information
print("\nAttach Event:")
channelClassName = ph.getChannelClassName()
serialNumber = ph.getDeviceSerialNumber()
channel = ph.getChannel()
ph.setDataInterval(32)
ph.setTemperatureChangeTrigger(0)
except PhidgetException as e:
print("\nError in Attach Event:")
DisplayError(e)
traceback.print_exc()
return
def onDetachHandler(self):
ph = self
try:
except PhidgetException as e:
print("\nError in Detach Event:")
DisplayError(e)
traceback.print_exc()
return
def onErrorHandler(self, errorCode, errorString):
sys.stderr.write("[Phidget Error Event] -> " + errorString + " (" + str(errorCode) + ")\n")
"""
* Outputs the TemperatureSensor's most recently reported temperature.
* Fired when a TemperatureSensor channel with onTemperatureChangeHandler registered meets DataInterval and ChangeTrigger criteria
*
* @param self The TemperatureSensor channel that fired the TemperatureChange event
* @param temperature The reported temperature from the TemperatureSensor channel
"""
def onTemperatureChangeHandler(self, temperature):
#If you are unsure how to use more than one Phidget channel with this event, we recommend going to
#www.phidgets.com/docs/Using_Multiple_Phidgets for information
print("[Temperature Event] -> Temperature: " + str(temperature))
"""
* Prints descriptions of how events related to this class work
"""
def PrintEventDescriptions():
print("\n--------------------\n"
"\n | Temperature change events will call their associated function every time new temperature data is received from the device.\n"
" | The rate of these events can be set by adjusting the DataInterval for the channel.\n"
" | Press ENTER once you have read this message.")
readin = sys.stdin.readline(1)
print("\n--------------------")
"""
* Creates, configures, and opens a TemperatureSensor channel.
* Displays Temperature events for 10 seconds
* Closes out TemperatureSensor channel
*
* @return 0 if the program exits successfully, 1 if it exits with errors.
"""
def main():
try:
ch = TemperatureSensor()
ch.setOnAttachHandler(onAttachHandler)
ch.setDeviceSerialNumber(424909)
ch.setChannel(0)
ch.openWaitForAttachment(5000)
ch.setTemperatureChangeTrigger(0)
ch.setOnDetachHandler(onDetachHandler)
ch.setOnErrorHandler(onErrorHandler)
#This call may be harmlessly removed
PrintEventDescriptions()
ch.setOnTemperatureChangeHandler(onTemperatureChangeHandler)
try:
ch.openWaitForAttachment(5000)
except PhidgetException as e:
PrintOpenErrorMessage(e, ch)
raise EndProgramSignal("Program Terminated: Open Failed")
time.sleep(1)
return 0
except PhidgetException as e:
sys.stderr.write("\nExiting with error(s)...")
DisplayError(e)
traceback.print_exc()
print("Cleaning up...")
ch.close()
return 1
except EndProgramSignal as e:
print(e)
print("Cleaning up...")
ch.close()
return 1
except RuntimeError as e:
sys.stderr.write("Runtime Error: \n\t" + e)
traceback.print_exc()
return 1
finally:
print("Press ENTER to end program.")
readin = sys.stdin.readline()
main()