M2i-LAN Laser-Scanner manual
HB-M2-iLAN-UDP-E.doc
page 32 of 44
MEL Mikroelektronik GmbH, Breslauer Str. 2, 85386 Eching / Germany
www.MELSensor.de
// read one byte from sensor
// try until some data found, return -1 if operation times out (error)
int
ByteFromM2(M2Dinfo *inf)
{
int
val, emptyCnt=0;
do{
e+;
if
(emptyCnt == 32767)
{
return
-1;
}
val=ByteFromM2FF(inf);
} while
(val == 0xFF);
return
val;
}
// low level write used by M2Dwrite
void
M2Dwait(M2Dinfo *inf,
int
cnt)
{
outp(inf->ioPort,value);
}
// low level wait used by M2DWrite
void
M2Dwait(M2Dinfo *inf,
int
cnt)
{
while
(cnt--)
inp(inf->2);
}
// M2DWrite
// write to M2D-Register
// anz:
0 -> registerNr == command e.g. 0x1C – reset FIFO; value not used
// 1 -> write value to registerNr
//
2 -> write value to registerNR & reg1, shift value to fit
//
low & high register; e.g. INTENSITY
void
M2DWrite (M2DInfo * inf,
int
registerNr,
int
value,
int
anz)
{
switch
(anz)
{
case
2:
//first register
ByteToM2 (inf, registerNr);
M2DWait (inf,fio_Wait);
ByteToM2(inf, (value & 0x7F) | 0x80);
M2DWait(inf,fio_Wait),
//r1
ByteToM2(inf,reg1);
M2DWait(inf,fio_Wait);
ByteToM2(inf,((value >> 7)& 0x7F | 0x80);
M2DWait(inf,fio_Wait);
break;
case
1:
ByteToM2 (inf, registerNr);
M2DWait (inf,fio_Wait);
ByteToM2(inf, (value & 0x7F) | 0x80);
M2DWait(inf,fio_Wait),
break;
case
0:
ByteToM2 (inf, registerNr);
M2DWait (inf,fio_Wait);
break;
}
}