/*******************************************************************************
procedure: getinf
purpose: get information from controller
synopsis: int CALLTYPE getinf( fun, rd, rs, ftmr, imp )
input: int fun = function code
int rd = data port address, (data register)
int rs = control port address, that identifies controller (state
register)
double ftmr = exposure time
unsigned long imp = impulse count
result: 0 = operation successful
-1 = communication error
-2 = controller can't make this function to present time or error
code function
-3 = parameter error
-4 = data isn't ready
******************************************************************************/
#ifdef DEBUG
int retspot_get;
#endif // def DEBUG
int CALLTYPE getinf( fun, rd, rs, ftmr, imp )
int fun, rd, rs;
double * ftmr;
unsigned long * imp;
{
register int i, j;
double wftmr;
unsigned long wimp, wtmr, ww;
unsigned char * p;
int l;
/* buffer receive message */
unsigned char bufmsg[LNGMSG];
#ifdef DEBUG
retspot_set = retspot_beg = retspot_get = retspot_init = retspot_tr =
retspot_rc = retspot_out = retspot_in = 0;
#endif // def DEBUG
if (FakeDevice)
{
*ftmr = 0.0;
*imp = 0;
return 0;
}
switch (fun)
{
/* receive result time and impulses */
case 9:
/* receive current time and impulses */
case 0x0b:
for ( i = 0; i < NCYCL; i++ )
{
l = 0;
j = rc_message( fun, rd, rs, bufmsg, LNGMSG, &l );
if ( j == 0 )
break;
if ( j == -2 )
{
#ifdef DEBUG
retspot_get = 1;
#endif // def DEBUG
return -2;
}
if ( j == -4 )
{
#ifdef DEBUG
retspot_get = 2;
#endif // def DEBUG
return -4;
}
}
if ( j != 0 )
{
#ifdef DEBUG
retspot_get = 3;
#endif // def DEBUG
/* error communicate */
return -1;
}
/* read number of counts do Bitshifts to cycle through
the four Bytes of the bufmsg that represent the longint*/
p = bufmsg;
wtmr = 0;
ww = 0;
ww = *p;
wtmr = wtmr + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 8;
wtmr = wtmr + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 16;
wtmr = wtmr + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 24;
wtmr = wtmr + ww;
p++;
/* turn number of counts into exposure time do Bitshifts to cycle through
the four Bytes of the bufmsg that represent the longint*/
wftmr = wtmr;
*ftmr = wftmr / (KMGHZ);
/* read impulse count */
wimp = 0;
ww = 0;
ww = *p;
wimp = wimp + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 8;
wimp = wimp + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 16;
wimp = wimp + ww;
p++;
ww = 0;
ww = *p;
ww = ww << 24;
wimp = wimp + ww;
*imp = wimp;
#ifdef DEBUG
retspot_get = 0;
#endif // def DEBUG
/* exit positively */
return 0;
/* parameter error */
default :
#ifdef DEBUG
retspot_get = 4;
#endif // def DEBUG
return -3;
}
}
|