// Duration between calculation runs #define SLEEPTIME_ms 1000 /* int outputChannel - SPS first Output channel float value - value to deal with int shift_correction - Depending on shifting there may be the need for a "signed" correction on the first short value */ void handle32bits(int outputChannel, float value, int shift_correction) { // take/cast first 16 bits "as is" signed short s_reg = (signed short)value; // handle scalefactor (last bitsequence in calculation) float f_reg_sf = value/pow(2, 16); // shift by 16 bits if (f_reg_sf < 0) f_reg_sf += 32768; signed short s_sf = (signed short) f_reg_sf; if (s_sf != 0) s_sf = (signed short)(((float)s_sf)-32768); setoutput(outputChannel, s_reg-shift_correction); setoutput(outputChannel+1, s_sf); } /* int outputChannel - SPS first Output channel float value - value to deal with */ void handle64bits(int outputChannel, float value) { setoutput(outputChannel, (signed short)value); setoutput(outputChannel+1, (signed short)(value/pow(2,16))-1); // shift by 16 bits handle32bits(outputChannel+2, value/pow(2,32), 1); // shift by 32 bits } // convert 64-bit to 4x16 bit, and 32-bit to 2x16 bit while (TRUE) { handle64bits(0, getinput(0)); handle32bits(4, getinput(1), 0); sleep(SLEEPTIME_ms); }