Package: restoreEpics
restoreEpicsA simple package that gives wrapped caput and writeMatrix functions for writing EPICS channels which save previous values and a restoreEpics function can be used later to restore all values in case of error, interrupt, or as a final restore.UsageRestoring channelsfromrestoreEpicsimportrestoreEpics,caput,cagettry:# do some work that uses caget or caput as usualexceptBaseException:# Handle error casesfinally:restoreEpics()# Will restore all changes to previous valuesWriting to matrices with form basename_ii_jj_suffixfromrestoreEpicsimportrestoreEpics,writeMatrixtry:writeMatrix(basename,mat,suffix=suffix,tramp=10)exceptBaseException:# Handle error casesfinally:restoreEpics()# Will restore all changes to previous valuesWriting multiple channels with option of ramping togetherfromrestoreEpicsimportrestoreEpics,writeChannelstry:chanInfo={'channels':{'C1:FIRST_CH':{'value':5},'C1:SECON_CH':{'value':10}},'tramp':4}writeChannels(chanInfo)exceptBaseException:# Handle error casesfinally:restoreEpics()# Will restore all changes to previous valuesMake your own restoring methodsfromrestoreEpicsimportrestoreEpics,backUpVals,restoreMethodsfromawgimportSinedefexciteSine(ch,freq,ampl,duration=10,ramptime=1,bak=backUpVals):exc=Sine(ch,freq,ampl,duration=duration)exc.start(ramptime=ramptime)ifchinbak:bak[ch]={'type':'excSine',# Store the exc object wth a type defined.'name':ch,# Values'exc':exc,# Values'sno':len(bak)}# Assign a serial number like thisdefrestoreExc(bakVal):bakVal['exc'].stop()# Restoring method for excitation.# Add the restoring method to restoreMethods dictionary with type defined above as keyrestoreMethods['excSine']=restoreExctry:exciteSine('blah',0.5,10)exceptBaseException:# Handle error casesfinally:restoreEpics()# Will restore all changes to previous valuesCommand line toolsThe readMatrix and writeMatrix functions are available as command line tools on installation through pip. Usage:$readMatrix-h
usage:readMatrix[-h][--firstRowFIRSTROW][--firstColFIRSTCOL][-sSUFFIX]basenameinMatFilerowscols

ThisreadsmatrixcoefficientsfromEPICSchannelstoatextfileto.Note
thatallindicesstartfrom1byconventionforEPICSchannels.

positionalarguments:basenameMatrixEPICSbasenameinMatFileInputMatrixfilenamerowsNumberofrowstoread.DefaultNone(all)colsNumberofcolumnstoread.DefaultNone(all)optionalarguments:-h,--helpshowthishelpmessageandexit--firstRowFIRSTROWFirstindexofoutput.Default1--firstColFIRSTCOLFirstindexofinput.Default1-sSUFFIX,--suffixSUFFIXAnysuffixafterthematrixindicesinchannelnames.DefaultisNone.$writeMatrix-h
usage:writeMatrix[-h][-rROWS][-cCOLS][--firstRowFIRSTROW][--firstColFIRSTCOL][--fileRowIndFILEROWIND][--fileColIndFILECOLIND][-tTRAMP][-sSUFFIX]inMatFilebasename

ThiswritesmatrixcoefficientsfromatextfiletoEPICSchannels.Notethat
allindicesstartfrom1byconventionforEPICSchannels.

positionalarguments:inMatFileInputMatrixfilenamebasenameMatrixEPICSbasename

optionalarguments:-h,--helpshowthishelpmessageandexit-rROWS,--rowsROWSNumberofrowstowrite.DefaultNone(all)-cCOLS,--colsCOLSNumberofcolumnstowrite.DefaultNone(all)--firstRowFIRSTROWFirstindexofoutput.Default1--firstColFIRSTCOLFirstindexofinput.Default1--fileRowIndFILEROWINDFirstrowindexinfile.Default1--fileColIndFILECOLINDFirstcolindexinfile.Default1-tTRAMP,--trampTRAMPRampingtimewhenchaningvalues.Default3-sSUFFIX,--suffixSUFFIXAnysuffixafterthematrixindicesinchannelnames.DefaultisNone.$caputt-h
usage:caputt[-h][-tTRAMP][-w][-oTIMEOUT][chanInfo[chanInfo...]]Thisscriptisaversionofnominalcaputcommandwithaddedfunctionalityof
settingatrampandreadingasetofchannelsfromyamlfilesiftheyneedto
besetalltogetherorrampedalltogethertonewvalues.

positionalarguments:chanInfoChannelnameandvaluepairssepaatedbyspaceornameoftheyamlfilecontainingthem.

optionalarguments:-h,--helpshowthishelpmessageandexit-tTRAMP,--trampTRAMPGlobalrampingtimeinseconds.-w,--waitWhethertowaituntiltheprocessinghascompleted.Globalandwouldoverrideanyothervaluefromparamterfile.-oTIMEOUT,--timeoutTIMEOUThowlongtowait(inseconds)forputtocompletebeforegivingup.Globalandwouldoverrideanyothervaluefromparamterfile.

Exampleuse:
caputtC1:FIRST_CH8.0
caputtC1:FIRST_CH8.0-t5caputtC1:FIRST_CH8.0C1:SECOND_CH5.6-t6-w-o60caputtchannelsFile.ymlExample of channelsFile.ymlchannels:C1:FIRST_CH:value:10C1:SECOND_CH:value:20C1:THIRD_CH:value:30tramp:5# Individual tramp, will get overridden by global tramp if present.C1:FOURTH_CH:value:40timeout:60# Time after which the process will call it failed attempt.wait:True# Will wait for the process to endtramp:5# GLobal tramp, overrides individual tramp