1111from ctypes import *
1212import struct
1313
14+ ## @cond
15+
1416MB_DATAORDER_DEFAULT = - 1
1517MB_DATAORDER_LITTLEENDIAN = 0
1618MB_DATAORDER_BIGENDIAN = 1
2123MB_REGISTERORDER_R1R0R3R2 = 2
2224MB_REGISTERORDER_R2R3R0R1 = 3
2325
26+ # Note (Feb 08 2025): c_long type was replaced by c_int because
27+ # on some platforms c_long is size of 8 bytes
28+
2429class CDeviceBlock (Structure ):
25- _fields_ = [("flags" , c_ulong ),
26- ("cycle" , c_ulong ),
27- ("count0x" , c_ulong ),
28- ("count1x" , c_ulong ),
29- ("count3x" , c_ulong ),
30- ("count4x" , c_ulong ),
31- ("exceptionStatusRef" , c_ulong ),
32- ("byteOrder" , c_long ),
33- ("registerOrder" , c_long ),
34- ("stoDeviceName" , c_ulong ),
35- ("stringTableSize" , c_ulong )]
30+ _fields_ = [("flags" , c_uint ),
31+ ("cycle" , c_uint ),
32+ ("count0x" , c_uint ),
33+ ("count1x" , c_uint ),
34+ ("count3x" , c_uint ),
35+ ("count4x" , c_uint ),
36+ ("exceptionStatusRef" , c_uint ),
37+ ("byteOrder" , c_int ),
38+ ("registerOrder" , c_int ),
39+ ("stoDeviceName" , c_uint ),
40+ ("stringTableSize" , c_uint )]
3641
3742class CPythonBlock (Structure ):
38- _fields_ = [("pycycle" , c_ulong )]
43+ _fields_ = [("pycycle" , c_uint )]
3944
4045class CMemoryBlockHeader (Structure ):
41- _fields_ = [("changeCounter" , c_ulong ),
42- ("changeByteOffset" , c_ulong ),
43- ("changeByteCount" , c_ulong ),
44- ("dummy" , c_ulong )]
46+ _fields_ = [("changeCounter" , c_uint ),
47+ ("changeByteOffset" , c_uint ),
48+ ("changeByteCount" , c_uint ),
49+ ("dummy" , c_uint )]
4550
51+ ## @endcond
4652
4753class _MbDevice :
4854 """Class for access device parameters.
@@ -114,6 +120,24 @@ def _getstring(self, offset:int)->str:
114120 bs = bytes (cast (self ._pmemstrtable [offset ], POINTER (c_ubyte * c ))[0 ])
115121 return bs .decode ('utf-8' )
116122
123+ def getmemsize (self ):
124+ return self ._shm .size ()
125+
126+ def getmemdump (self , offset :int = 0 , size :int = None )-> bytes :
127+ sz = self ._shm .size ()
128+ if offset >= sz :
129+ return None
130+ c = sz
131+ if not (size is None ):
132+ c = size
133+ if offset + c > sz :
134+ c = sz - offset
135+ pmembytes = cast (self ._pcontrol , POINTER (c_ubyte * 1 ))
136+ self ._shm .lock ()
137+ b = bytes (cast (pmembytes [offset ], POINTER (c_ubyte * c ))[0 ])
138+ self ._shm .unlock ()
139+ return b
140+
117141 def getname (self )-> str :
118142 """
119143 @details Returns name of the current device as string.
@@ -231,7 +255,7 @@ def getmem4x(self):
231255 """
232256 return self ._mem4x
233257
234-
258+ ## @cond
235259class _MemoryPythonBlock :
236260 def __init__ (self , shmid :str ):
237261 shm = QSharedMemory (shmid )
@@ -265,6 +289,7 @@ def incpycycle(self):
265289 self ._shm .lock ()
266290 self ._control .pycycle = self ._cyclecounter
267291 self ._shm .unlock ()
292+ ## @endcond
268293
269294
270295class _MemoryBlock :
@@ -295,6 +320,7 @@ def __del__(self):
295320 except RuntimeError :
296321 pass
297322
323+ ## @cond
298324 def _recalcheader (self , byteoffset :int , bytecount :int )-> None :
299325 rightedge = byteoffset + bytecount
300326 if self ._head .changeByteOffset > byteoffset :
@@ -314,10 +340,11 @@ def _getbytes(self, byteoffset:int, count:int, bytestype=bytes)->bytes:
314340 else :
315341 c = count
316342 self ._shm .lock ()
317- r = bytestype (cast (self ._pmembytes [byteoffset ], POINTER (c_ubyte * c ))[0 ])
343+ b = bytestype (cast (self ._pmembytes [byteoffset ], POINTER (c_ubyte * c ))[0 ])
318344 self ._shm .unlock ()
319- return r
345+ return b
320346 return bytestype ()
347+ ## @endcond
321348
322349 def getid (self )-> int :
323350 """
@@ -1054,7 +1081,7 @@ def getint32(self, offset:int)->int:
10541081 """
10551082 if 0 <= offset < self ._count - 1 :
10561083 self ._shm .lock ()
1057- r = cast (self ._pmem [offset ], POINTER (c_long ))[0 ]
1084+ r = cast (self ._pmem [offset ], POINTER (c_int ))[0 ]
10581085 self ._shm .unlock ()
10591086 return r
10601087 return 0
@@ -1081,7 +1108,7 @@ def getuint32(self, offset:int)->int:
10811108 """
10821109 if 0 <= offset < self ._count - 1 :
10831110 self ._shm .lock ()
1084- r = cast (self ._pmem [offset ], POINTER (c_ulong ))[0 ]
1111+ r = cast (self ._pmem [offset ], POINTER (c_uint ))[0 ]
10851112 self ._shm .unlock ()
10861113 return r
10871114 return 0
@@ -1097,8 +1124,8 @@ def setuint32(self, offset:int, value:int)->None:
10971124 """
10981125 if 0 <= offset < self ._count - 1 :
10991126 self ._shm .lock ()
1100- cast (self ._pmem [offset ], POINTER (c_ulong ))[0 ] = value
1101- cast (self ._pmask [offset ], POINTER (c_ulong ))[0 ] = 0xFFFFFFFF
1127+ cast (self ._pmem [offset ], POINTER (c_uint ))[0 ] = value
1128+ cast (self ._pmask [offset ], POINTER (c_uint ))[0 ] = 0xFFFFFFFF
11021129 self ._recalcheader (offset * 2 , 4 )
11031130 self ._shm .unlock ()
11041131
@@ -1193,7 +1220,7 @@ def setfloat(self, offset:int, value:float)->None:
11931220 if 0 <= offset < self ._count - 1 :
11941221 self ._shm .lock ()
11951222 cast (self ._pmem [offset ], POINTER (c_float ))[0 ] = value
1196- cast (self ._pmask [offset ], POINTER (c_ulong ))[0 ] = 0xFFFFFFFF
1223+ cast (self ._pmask [offset ], POINTER (c_uint ))[0 ] = 0xFFFFFFFF
11971224 self ._recalcheader (offset * 2 , 4 )
11981225 self ._shm .unlock ()
11991226
0 commit comments