M2i-LAN Laser-Scanner manual
HB-M2-iLAN-UDP-E.doc
page 35 of 44
MEL Mikroelektronik GmbH, Breslauer Str. 2, 85386 Eching / Germany
www.MELSensor.de
// DataToInt
// helper function to make integer from sensor status
// dat: array with status info
// cnt: array size
// return: calculated number
long
DatToInt(int *dat,int cnt)
{
int
i;
long
res;
res=0;
for
(i=0;i<cnt;i++){
res = res | ((long)dat[i] << i*7);
}
return
res;
}
// M2DStatus
// select status by num and return value
// Hint: avoid trigger mode
// return:
// 0 = ok, -1 = fail
// inf -> sync [3] = status
int
M2DStatus (M2DInfo *inf, int num)
{
int
i,res,result; //
int res = M2DStatus(sens,3)
result=-1;
M2DWrite(inf,0x11,num,1); // select status register
M2DWrite(inf,0x1C,0,0); // clear FIFO
for
(i=0;i<5;i++)
{
res = M2DSync(inf);
if
(res>=0
&&
(((inf->sync[1]>>1)
&
0x3F) == num))
{
result=0;
break
;
}
}
// M2DStatusInt
// select count status bytes by num and make integer
// Hint: avoid trigger mode
// return:
// 0 = ok, -1 = fail
// value
int
M2DStatusInt(M2DInfo *inf,
int
start,
int
count,
long
*value)
{
int
i, res;
int
dat[8];
res=-1 ;
if
(count>8) count=8;
for
(i=0;i<count;i++){
res= M2DStatus(inf,i+start);
if
(res<0)
break
;
dat[i] = inf->sync[3];
}
*value = DatToInt(dat,count);
return
res;
}