Knowledge of the midplane temperature of protoplanetary disks is one of the key ingredients in theories of dust growth and planet formation. However, direct measurement of this quantity is complicated, and often depends on the fitting of complex models to the data. In this paper we demonstrate a method to directly measure the midplane gas temperature from an optically thick molecular line, if the disk is moderately inclined. The only model assumption that enters is that the line is very optically thick, also in the midplane region where we wish to measure the temperature. Freeze-out of the molecule onto dust grains could thwart this. However, in regions that are expected to be warm enough to avoid freeze-out, this method should work. We apply the method to the CO 2-1 line channel maps of the disk around HD 163296. We find that the midplane temperature between 100 and 400 au drops only mildly from 25 K down to 18 K. While we see no direct evidence of the midplane being optically thin due to strong CO depletion by freeze-out, we cannot rule it out either. The fact that the inferred temperatures are close to the expected CO freeze-out temperature could be an indication of this. Incidently, for the disk around HD 163296 we also find dynamic evidence for a rather abrupt outer edge of the disk, suggestive of outside-in photoevaporation or truncation by an unseen companion.