/*******************************************************************************
procedure: begwrk
purpose: issue command to controller
synopsis: int CALLTYPE begwrk( fun, rd, rs )
input: fun = code of command to issue:
1 = count impulses during exposure time
2 = count time when number of impulses is set
3 = intensimeter
5 = stop controller
int rd = data port address, (data register)
int rs = control port address, that identifies controller (state
register)
result: 0 = operation successful
-1 = communication error
-2 = controller can't make this function to present time or error
code function
-3 = parameter error (unknown command)
*******************************************************************************/
#ifdef DEBUG
int retspot_beg;
#endif // def DEBUG
int CALLTYPE begwrk( fun, rd, rs )
int fun, rs, rd;
{
register int i, j;
/* buffer of receive/transmit 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
/* do nothing, if using FakeDevice */
if (FakeDevice)
return 0;
/* depending on the command to issue... (function code filter) */
switch (fun)
{
/* count impulses during exposure time */
case 1:
/* count time when number of impulses is set */
case 2:
/* intensimeter */
case 3:
/* stop controller */
case 5:
/* transmit message NCYCL cycles or until return value is 0 */
for ( i = 0; i < NCYCL; i++ )
{
j = tr_message( fun, rd, rs, bufmsg, 0 );
if (j == 0)
break;
if (j == -2)
{
#ifdef DEBUG
retspot_beg = 1;
#endif // def DEBUG
return -2;
}
}
/* if unknown return code */
if (j != 0)
{
#ifdef DEBUG
retspot_beg = 2;
#endif // def DEBUG
/* return error code */
return -1;
}
#ifdef DEBUG
retspot_beg = 0;
#endif // def DEBUG
/* exit positively */
return 0;
/* unknown command */
default :
#ifdef DEBUG
retspot_beg = 3;
#endif // def DEBUG
/* return error code */
return -3;
}
}
|