M2D-Laser-Scanner with Ethernet-Interface
Manual
HB-M2D-Ethernet-E
Page 29 of 39
www.MElsensor.com
// M2DSync
// return: 0 = ok, sync found
>0 = ok, sync after retval bytes found
// -1 = timeout
-2 = no sync
// inf->sync
// sync [0] data format version
sync [1] status1
// sync [2] running number
sync [3] status2
int M2DSync (M2DInfo *inf)
{
int
i,
val,
syncCnt=0
tryCnt=0
while(1){
val=ByteFromM2(inf);
if(val == -1)
return -1 // timeout
if(val == 0){
+;
}
else{
if(synCnt >= 8){
#ifdef M2D_DEBUG
if(synCnt > 8){
#ifdef __RT__
printk(“\n[%d]\n”,synCnt);
#else
printf(“\n[%d]\n”,synCnt);
#endif
}
#endif
// ---sync info 4 byte ---
inf->sync[0] = val ;
for(i=1 ; i<4 ; i++){
val=ByteFromM2(inf) ;
if(val == -1)
return -1; // timeout
inf->sync[i] = val;
}
if(inf->sync[0]==3){
//data format 3 : throw away useless encoder data here because of
//special behaviour in trigger mode
for(i=0;i<4;i++){
val = ByteFromM2(inf); if(val == -1) return -1;
}
}
return (tryCnt-8); // OK
}
else{
synCnt = 0;
}
}
+;
if(tryCnt == 8192){
return -2; // snyc not found
}
}
}