device = det
det.imageCounter.polling = 500

class AreaDetectorROI(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
    def __init__(self, name, detector, x, y, w, h):
        ReadonlyRegisterBase.__init__(self, name)
        self.detector = detector
        self.x, self.y, self.w, self.h = x, y, w, h
        
    def doRead(self):
        data = self.detector.dataMatrix.take()
        ret = Convert.matrixRoi(data, self.x, self.y, self.w, self.h)
        return ret

    def getWidth(self):
        return self.w

    def getHeight(self):
        return self.h


add_device(AreaDetectorROI("roi1", device, 10,10,10,5), True)
add_device(AreaDetectorROI("roi2", device,100,30,7,3), True)

#tscan((roi1, roi2), 10, 0.1)

mscan(device.imageCounter, (roi1, roi2), 10, async=False)