3.2.  Converting between integer data and physical units

If you selected an analog input subdevice, you probably noticed that the output of tut1 is an unsigned number, for example between 0 and 65535 for a 16 bit analog input. Comedi samples are unsigned, with 0 representing the lowest voltage of the ADC, and a hardware-dependent maximum value representing the highest voltage. Comedi compensates for anything else the manual for your device says (for example, many boards represent bipolar analog input voltages as signed integers). However, you probably prefer to have this number translated to a voltage. Naturally, as a good programmer, your first question is: How do I do this in a device-independent manner?

The functions comedi_to_physical, comedi_to_phys, comedi_from_physical and comedi_from_phys are used to convert between Comedi's integer data and floating point numbers corresponding to physical values (voltages, etc.).