@@ -49,17 +49,17 @@ class _MbDevice:
4949
5050 More details.
5151 """
52- def __init__ (self , memidprefix :str ):
53- memid_device = memidprefix + ".device"
54- memid_python = memidprefix + ".python"
55- memid_mem0x = memidprefix + ".mem0x"
56- memid_mem1x = memidprefix + ".mem1x"
57- memid_mem3x = memidprefix + ".mem3x"
58- memid_mem4x = memidprefix + ".mem4x"
59- shm = QSharedMemory (memid_device )
52+ def __init__ (self , shmidprefix :str ):
53+ shmid_device = shmidprefix + ".device"
54+ shmid_python = shmidprefix + ".python"
55+ shmid_mem0x = shmidprefix + ".mem0x"
56+ shmid_mem1x = shmidprefix + ".mem1x"
57+ shmid_mem3x = shmidprefix + ".mem3x"
58+ shmid_mem4x = shmidprefix + ".mem4x"
59+ shm = QSharedMemory (shmid_device )
6060 res = shm .attach ()
6161 if not res :
62- raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ memid_device } '" )
62+ raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ shmid_device } '" )
6363 qptr = shm .data ()
6464 size = shm .size ()
6565 memptr = c_void_p (qptr .__int__ ())
@@ -81,11 +81,11 @@ def __init__(self, memidprefix:str):
8181 self ._name = self ._getstring (stoDeviceName )
8282 self ._shm .unlock ()
8383 # submodules
84- self ._python = _MemoryPythonBlock (memid_python )
85- self ._mem0x = _MemoryBlockBits (memid_mem0x , self ._count0x )
86- self ._mem1x = _MemoryBlockBits (memid_mem1x , self ._count1x )
87- self ._mem3x = _MemoryBlockRegs (memid_mem3x , self ._count3x )
88- self ._mem4x = _MemoryBlockRegs (memid_mem4x , self ._count4x )
84+ self ._python = _MemoryPythonBlock (shmid_python )
85+ self ._mem0x = _MemoryBlockBits (shmid_mem0x , self ._count0x , 0 )
86+ self ._mem1x = _MemoryBlockBits (shmid_mem1x , self ._count1x , 1 )
87+ self ._mem3x = _MemoryBlockRegs (shmid_mem3x , self ._count3x , 3 )
88+ self ._mem4x = _MemoryBlockRegs (shmid_mem4x , self ._count4x , 4 )
8989 # Exception status
9090 memtype = self ._excstatusref // 100000
9191 self ._excoffset = (self ._excstatusref % 100000 ) - 1
@@ -233,11 +233,11 @@ def getmem4x(self):
233233
234234
235235class _MemoryPythonBlock :
236- def __init__ (self , memid :str ):
237- shm = QSharedMemory (memid )
236+ def __init__ (self , shmid :str ):
237+ shm = QSharedMemory (shmid )
238238 res = shm .attach ()
239239 if not res :
240- raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ memid } '" )
240+ raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ shmid } '" )
241241 qptr = shm .data ()
242242 self ._memsize = shm .size ()
243243 memptr = c_void_p (qptr .__int__ ())
@@ -272,17 +272,18 @@ class _MemoryBlock:
272272
273273 Class is abstract (can't be used directly).
274274 """
275- def __init__ (self , memid :str , bytecount :int ):
276- shm = QSharedMemory (memid )
275+ def __init__ (self , shmid :str , bytecount : int , id :int ):
276+ shm = QSharedMemory (shmid )
277277 res = shm .attach ()
278278 if not res :
279- raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ memid } '" )
279+ raise RuntimeError (f"Cannot attach to Shared Memory with id = '{ shmid } '" )
280280 qptr = shm .data ()
281281 memptr = c_void_p (qptr .__int__ ())
282282 sz = shm .size ()
283283 cbytes = bytecount if bytecount <= sz else sz
284284 self ._shm = shm
285285 self ._countbytes = cbytes
286+ self ._id = id
286287 ptrhead = cast (memptr , POINTER (CMemoryBlockHeader ))
287288 self ._head = ptrhead [0 ]
288289 self ._pmembytes = cast (byref (ptrhead [1 ]),POINTER (c_ubyte * 1 ))
@@ -318,6 +319,12 @@ def _getbytes(self, byteoffset:int, count:int, bytestype=bytes)->bytes:
318319 return r
319320 return bytestype ()
320321
322+ def getid (self )-> int :
323+ """
324+ @details Returns id (0, 1, 3 or 4) of the current memory object as integer.
325+ """
326+ return self ._id
327+
321328 def getbytes (self , byteoffset :int , count :int )-> bytes :
322329 """
323330 @details Function returns `bytes` object from device memory starting with `byteoffset` and `count` bytes.
@@ -525,8 +532,8 @@ class _MemoryBlockBits(_MemoryBlock):
525532
526533 More details.
527534 """
528- def __init__ (self , memid :str , count :int ):
529- super ().__init__ (memid , (count + 7 )// 8 )
535+ def __init__ (self , shmid :str , count : int , id :int ):
536+ super ().__init__ (shmid , (count + 7 )// 8 , id )
530537 c = self ._countbytes * 8
531538 self ._count = count if count <= c else c
532539
@@ -877,8 +884,8 @@ class _MemoryBlockRegs(_MemoryBlock):
877884
878885 More details.
879886 """
880- def __init__ (self , memid :str , count :int ):
881- super ().__init__ (memid , count * 2 )
887+ def __init__ (self , shmid :str , count : int , id :int ):
888+ super ().__init__ (shmid , count * 2 , id )
882889 c = self ._countbytes // 2
883890 self ._count = count if count <= c else c
884891 self ._pmem = cast (self ._pmembytes ,POINTER (c_ushort * 1 ))
0 commit comments