Skip to content

Commit

Permalink
improved timestamping
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKOMO committed Oct 21, 2023
1 parent eeccde8 commit 241b758
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
40 changes: 18 additions & 22 deletions src/artisanlib/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ def sendFUJIcommand(self, binstring:bytes, nbytes:int) -> bytes:
#finds time, ET and BT when using Fuji PID. Updates sv (set value) LCD. Finds power duty cycle
def fujitemperature(self) -> Tuple[float,float,float]:
#update ET SV LCD 6
self.aw.qmc.currentpidsv = self.aw.fujipid.readcurrentsv()
#get time of temperature reading in seconds from start; .elapsed() returns milliseconds
tx = self.aw.qmc.timeclock.elapsedMilli()
self.aw.qmc.currentpidsv = self.aw.fujipid.readcurrentsv()
# get the temperature for ET. self.aw.fujipid.gettemperature(unitID)
t1 = self.aw.fujipid.gettemperature(self.controlETpid[0],self.controlETpid[1])/10. #Need to divide by 10 because using 1 decimal point in Fuji (ie. received 843 = 84.3)
#if Fuji for BT is not None (0= PXG, 1 = PXR, 2 = None 3 = DTA)
Expand Down Expand Up @@ -619,6 +619,7 @@ def fujitemperature(self) -> Tuple[float,float,float]:

#especial function that collects extra duty cycle % and SV
def piddutycycle(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
if self.aw.qmc.device == 0: # FUJI
#return saved readings from device 0
return self.aw.qmc.dutycycleTX, self.aw.qmc.dutycycle, self.aw.qmc.currentpidsv
Expand All @@ -640,10 +641,11 @@ def piddutycycle(self) -> Tuple[float,float,float]:
if duty is None:
duty = -1
duty = min(100,max(-100,duty))
return self.aw.qmc.timeclock.elapsedMilli(),duty,sv
return tx,duty,sv

def DTAtemperature(self) -> Tuple[float,float,float]:
_log.debug('DTAtemperature')
tx = self.aw.qmc.timeclock.elapsedMilli()
###########################################################
### create command
command = self.aw.dtapid.message2send(self.controlETpid[1],3,self.aw.dtapid.dtamem['sv'][1],1)
Expand All @@ -659,7 +661,6 @@ def DTAtemperature(self) -> Tuple[float,float,float]:
command = self.aw.dtapid.message2send(self.controlETpid[1],3,self.aw.dtapid.dtamem['pv'][1],1)
#read
t1 = self.sendDTAcommand(command)
tx = self.aw.qmc.timeclock.elapsedMilli()
#if Fuji for BT is not None (0= PXG, 1 = PXR, 2 = None 3 = DTA)
if self.readBTpid[0] < 2:
t2 = self.aw.fujipid.gettemperature(self.readBTpid[0],self.readBTpid[1])/10.
Expand Down Expand Up @@ -744,6 +745,7 @@ def callprogram(self) -> Tuple[float,float,float]:
import subprocess
output = None
try:
tx = self.aw.qmc.timeclock.elapsedMilli()
# output = os.popen(self.aw.ser.externalprogram,"r").readline()
# we try to set the users standard environment, replacing the one pointing to the restrictive python build in Artisan
my_env = self.aw.calc_env()
Expand All @@ -762,7 +764,6 @@ def callprogram(self) -> Tuple[float,float,float]:
p = subprocess.Popen([os.path.expanduser(c) for c in shlex.split(self.aw.ser.externalprogram)],env=my_env,stdout=subprocess.PIPE,startupinfo=startupinfo) # pylint: disable=consider-using-with
output = p.communicate()[0].decode('UTF-8')

tx = self.aw.qmc.timeclock.elapsedMilli()
if ',' in output:
parts = output.split(',')
if len(parts) > 2:
Expand Down Expand Up @@ -1121,33 +1122,29 @@ def VICTOR86B(self) -> Tuple[float,float,float]:
# if force the optimizer is deactivated to ensure fetching fresh readings
def S7(self,force:bool=False) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
self.aw.extraS7tx = tx
t2,t1 = self.S7read(0,force)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def S7_34(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
t2,t1 = self.S7read(1)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def S7_56(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
t2,t1 = self.S7read(2)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def S7_78(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
t2,t1 = self.S7read(3)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def S7_910(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
t2,t1 = self.S7read(4)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def S7_1112(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
t2,t1 = self.S7read(5)
return tx,t2,t1
return self.aw.extraS7tx,t2,t1

def R1_DTBT(self) -> Tuple[float,float,float]:
if self.R1 is None:
Expand Down Expand Up @@ -1209,20 +1206,21 @@ def R1_RPM_STATE(self) -> Tuple[float,float,float]:
# if force the optimizer is deactivated to ensure fetching fresh readings
def MODBUS(self,force:bool=False) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
self.aw.extraMODBUStx = tx
t2,t1 = self.MODBUSread(force)
return tx,t2,t1

def MODBUS_34(self) -> Tuple[float,float,float]:
return self.aw.qmc.extraMODBUStx,self.aw.qmc.extraMODBUStemps[3],self.aw.qmc.extraMODBUStemps[2]
return self.aw.extraMODBUStx,self.aw.extraMODBUStemps[3],self.aw.extraMODBUStemps[2]

def MODBUS_56(self) -> Tuple[float,float,float]:
return self.aw.qmc.extraMODBUStx,self.aw.qmc.extraMODBUStemps[5],self.aw.qmc.extraMODBUStemps[4]
return self.aw.extraMODBUStx,self.aw.extraMODBUStemps[5],self.aw.extraMODBUStemps[4]

def MODBUS_78(self) -> Tuple[float,float,float]:
return self.aw.qmc.extraMODBUStx,self.aw.qmc.extraMODBUStemps[7],self.aw.qmc.extraMODBUStemps[6]
return self.aw.extraMODBUStx,self.aw.extraMODBUStemps[7],self.aw.extraMODBUStemps[6]

def MODBUS_910(self) -> Tuple[float,float,float]:
return self.aw.qmc.extraMODBUStx,self.aw.qmc.extraMODBUStemps[9],self.aw.qmc.extraMODBUStemps[8]
return self.aw.extraMODBUStx,self.aw.extraMODBUStemps[9],self.aw.extraMODBUStemps[8]

def HH802U(self) -> Tuple[float,float,float]:
tx = self.aw.qmc.timeclock.elapsedMilli()
Expand Down Expand Up @@ -2510,9 +2508,7 @@ def MODBUSread(self, force:bool = False) -> Tuple[float, float]:
res[i] = ri
rf = self.processChannelData(res[i],self.aw.modbus.inputDivs[i],self.aw.modbus.inputModes[i])
res[i] = rf

self.aw.qmc.extraMODBUStemps = res[:]
self.aw.qmc.extraMODBUStx = self.aw.qmc.timeclock.elapsedMilli()
self.aw.extraMODBUStemps = res[:]
return res[1], res[0]

def NONEtmp(self) -> Tuple[float, float]:
Expand Down
3 changes: 2 additions & 1 deletion src/artisanlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ class ApplicationWindow(QMainWindow): # pyright: ignore [reportGeneralTypeIssue
'backgroundDlg_activeTab', 'DeviceAssignmentDlg_activeTab', 'AlarmDlg_activeTab', 'resetqsettings', 'settingspath', 'wheelpath', 'profilepath',
'userprofilepath', 'printer', 'main_widget', 'defaultdpi', 'dpi', 'qmc', 'HottopControlActive', 'AsyncSamplingTimer', 'wheeldialog',
'simulator', 'simulatorpath', 'comparator', 'stack', 'eventsbuttonflag', 'minieventsflags', 'seriallogflag',
'seriallog', 'ser', 'modbus', 'extraMODBUStemps', 'extraMODBUStx', 's7', 'ws', 'scale', 'color', 'extraser', 'extracomport', 'extrabaudrate',
'seriallog', 'ser', 'modbus', 'extraMODBUStemps', 'extraMODBUStx', 's7', 'extraS7tx', 'ws', 'scale', 'color', 'extraser', 'extracomport', 'extrabaudrate',
'extrabytesize', 'extraparity', 'extrastopbits', 'extratimeout', 'hottop', 'santokerHost', 'santokerPort', 'santokerSerial', 'santoker', 'fujipid', 'dtapid', 'pidcontrol', 'soundflag', 'recentRoasts', 'maxRecentRoasts',
'kaleidoHost', 'kaleidoPort', 'kaleidoSerial', 'kaleidoPID', 'kaleido',
'lcdpaletteB', 'lcdpaletteF', 'extraeventsbuttonsflags', 'extraeventslabels', 'extraeventbuttoncolor', 'extraeventsactionstrings',
Expand Down Expand Up @@ -1629,6 +1629,7 @@ def __init__(self, parent:Optional[QWidget] = None, *, locale:str, WebEngineSupp

#create an s7 port object (main s7 device)
self.s7:s7port = s7port(self)
self.extraS7tx:float = 0.
#create an WebSocket port object (main device eg Probat Sample)
self.ws:wsport = wsport(self)
#create scale port object
Expand Down
2 changes: 1 addition & 1 deletion src/artisanlib/modbusport.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def cancel_tasks(self) -> None:
# if self._loop.is_running():
# future = asyncio.run_coroutine_threadsafe(self.cancel_tasks(), self._loop)
# try:
# return future.result(0.2) # wait 0.2sec for cancelation of all tasks
# return future.result(0.2) # wait 0.2sec for cancellation of all tasks
# except TimeoutError:
# # the coroutine took too long, cancelling the task...
# future.cancel()
Expand Down

0 comments on commit 241b758

Please sign in to comment.