craft-software/Legacy/Instrument_Drivers/global_variables.py
2025-07-04 15:52:40 +02:00

93 lines
3.9 KiB
Python

import multiprocessing
import multiprocessing.managers
#This starts a server (mulitprocessing basemanager) where all standalones store their current measurement values and set_parameters. This data can be accessed from
#all python instances running on this computer. It can be extended so it can be reached from other PCs aswell.
#The dictionarioes which store the values must be initialized and registered here. To register a new dictionary an (empty) dictionary must be created and a function
#must be defined which returns this dictionary. After that the dictionary must be registered in the manager. This is done with:
#MyListManager.register('syncdict',get_dict) where 'syncdict' is the name that other programs use to reach this dictionary and get_dict the function which return the
#dictionary.
#The values don't have to be stored in dictionaries. List or simple variables also work. But I haven't tested all posibillities.
#To access these dictionaries from other programs, a basemanager must be created in the program which is then connected to the manager created here. There the
#dictionary must also be registered. Finally a local variable is created which points at the dictionary on this server. The following example is from Keysigh_U2042XA_control
#manager = multiprocessing.managers.BaseManager(address=('localhost',5001), authkey=b'')
#manager.connect()
#manager.register('sync_K_U2042XA')
#self.sync_K_U2042XA = manager.sync_K_U2042XA() <- the local variable "self.sync_K_U2042XA" can have any name
class MyListManager(multiprocessing.managers.BaseManager):
pass
#!!!
#please use unambigous names
#!!!
syncdict = {} #dummy where everything can be stored
sync_AG_304 = {}
sync_K_U2042XA = {}
sync_K_34461A = {}
sync_K_34461A_2 = {}
sync_T_LS6081B = {}
sync_LS_336 = {}
sync_LS_218 = {}
sync_BK_9131B = {}
sync_BK_9132B = {}
sync_BK_9132B_2 = {}
sync_BK_9174B = {}
sync_BK_9174B_2 = {}
sync_Keithley_2230G = {}
def get_dict():
return syncdict
def get_dict_sync_AG_304():
return sync_AG_304
def get_dict_sync_K_U2042XA():
return sync_K_U2042XA
def get_dict_sync_K_34461A():
return sync_K_34461A
def get_dict_sync_K_34461A_2():
return sync_K_34461A_2
def get_dict_sync_T_LS6081B():
return sync_T_LS6081B
def get_dict_sync_LS_336():
return sync_LS_336
def get_dict_sync_LS_218():
return sync_LS_218
def get_dict_sync_BK_9131B():
return sync_BK_9131B
def get_dict_sync_BK_9132B():
return sync_BK_9132B
def get_dict_sync_BK_9132B_2():
return sync_BK_9132B_2
def get_dict_sync_BK_9174B():
return sync_BK_9174B
def get_dict_sync_BK_9174B_2():
return sync_BK_9174B_2
def get_dict_sync_Keithley_2230G():
return sync_Keithley_2230G
def main():
MyListManager.register('syncdict',get_dict)
MyListManager.register('sync_AG_304',get_dict_sync_AG_304)
MyListManager.register('sync_K_U2042XA',get_dict_sync_K_U2042XA)
MyListManager.register('sync_T_LS6081B',get_dict_sync_T_LS6081B)
MyListManager.register('sync_LS_336',get_dict_sync_LS_336)
MyListManager.register('sync_K_34461A',get_dict_sync_K_34461A)
MyListManager.register('sync_K_34461A_2',get_dict_sync_K_34461A_2)
MyListManager.register('sync_LS_218',get_dict_sync_LS_218)
MyListManager.register('sync_BK_9131B', get_dict_sync_BK_9131B)
MyListManager.register('sync_BK_9132B', get_dict_sync_BK_9132B)
MyListManager.register('sync_BK_9132B_2', get_dict_sync_BK_9132B_2)
MyListManager.register('sync_BK_9174B', get_dict_sync_BK_9174B)
MyListManager.register('sync_BK_9174B_2', get_dict_sync_BK_9174B_2)
MyListManager.register('sync_Keithley_2230G', get_dict_sync_Keithley_2230G)
manager = MyListManager(address=('localhost',5001), authkey=b'')
manager.start()
input("Press Enter (Not Str+C) to exit. But kill client first".center(50,"-")) #keeps program running until enter is pressed
manager.shutdown()
if __name__ == '__main__':
main()