%Returns currebnt image from the specified camera
function [im, posx, posy, ts]  = GetImage(deviceName)
% posx, posy maps with positions of pixels
% ts  - time stamp of the taken picture

tic;

javaMethod('setProperty', 'java.lang.System', 'cmw.names', 'abcmw.cern.ch:5020');
rda = cern.cmw.rda.client.RDAService.init();
cycle = 'SCT:USER:SETUP';
device = rda.getDeviceHandle(deviceName);

%fprintf(1,'Camera %s: Got Device\n',deviceName)

image = device.get('Image', cycle);
imageArray = image.extractShortArray('imageSet');

posx = image.extractDoubleArray('imagePositionSet1');
posy = image.extractDoubleArray('imagePositionSet2');
ts = char(image.extractString('acqTime'));

t1 = toc;

tic;

nx=length(posx);
ny=length(posy);
im=zeros(nx,ny);

for i=1:ny,
    im(:,i)=imageArray((i-1)*nx+1:i*nx);
end

im = im';

t2=toc;
fprintf(1,'Camera %s: Acquired Image in %f processed in %f\n',deviceName, t1,t2);




