/*******************************************************************************
procedure: setprm
purpose: upload parameters to controller
synopsis: int CALLTYPE setprm( rd, rs, cph, cpl, ve, ftmr, imp, intg, snd,
ntrp )
input: int rd = data port address, (data register)
int rs = control port address, that identifies controller (state
register)
unsigned short cph = upper threshold
unsigned short cpl = lower threshold
int ve = high voltage
double ftmr = exposure time
unsigned long imp = impulse count
int intg = energy integral
int snd = sound
int ntrp = interrupt
result: 0 = operation successful
-1 = communication error
-2 = controller can't make this function to present time or error
code function
-3 = parameter error
******************************************************************************/
#ifdef DEBUG
int retspot_set;
#endif // def DEBUG
int CALLTYPE setprm( rd, rs, cph, cpl, ve, ftmr, imp, intg, snd, ntrp )
int rs, rd;
unsigned short cph, cpl;
int ve;
double ftmr;
unsigned long imp;
int intg;
int snd;
int ntrp;
{
/* local variables */
register int i, j;
unsigned long wtmr;
#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;
/* format energy integral */
bufmsg[0] = (unsigned char) intg;
/* format sound */
bufmsg[1] = (unsigned char) snd;
/* format high voltage do bitshift to get next Byte*/
bufmsg[7] = (unsigned char) ve;
ve = (ve >> 8) & 0xff;
bufmsg[8] = (unsigned char) ve;
/* format lower threshold do bitshift to get next Byte*/
bufmsg[9] = (unsigned char) cpl;
cpl = (cpl >> 8) & 0xff;
bufmsg[10] = (unsigned char) cpl;
/* format upper threshold do bitshift to get next Byte*/
bufmsg[11] = (unsigned char) cph;
cph = (cph >> 8) & 0xff;
bufmsg[12] = (unsigned char) cph;
/* determine and format total counts do bitshifts to get next Bytes*/
wtmr = ftmr * KMGHZ;
bufmsg[13] = (wtmr & 0xff);
bufmsg[14] = ((wtmr >> 8) & 0xff);
bufmsg[15] = (wtmr >> 16) & 0xff;
bufmsg[16] = (wtmr >> 24) & 0xff;
/* format impulse count do bitshifts to get next Bytes*/
bufmsg[17] = (imp & 0xff);
bufmsg[18] = ((imp >> 8) & 0xff);
bufmsg[19] = (imp >> 16) & 0xff;
bufmsg[20] = (imp >> 24) & 0xff;
/* format interrupt */
bufmsg[21] = (ntrp & 0xff);
/* transmit message for NCYCL cycles or until return value is 0 */
for ( i = 0; i < NCYCL; i++ )
{
j = tr_message( CF0, rd, rs, bufmsg, LNGMSG_TR );
if (j == 0)
break;
if (j == -2)
{
#ifdef DEBUG
retspot_set = 1;
#endif // def DEBUG
/* controller can't make this function to present time or error code
function */
return -2;
}
}
/* if max number of cycles reached and return value is not 0 */
if (j != 0)
{
#ifdef DEBUG
retspot_set = 2;
#endif // def DEBUG
return -1;
}
#ifdef DEBUG
retspot_set = 0;
#endif // def DEBUG
/* exit positively */
return 0;
}
|