import com.sun.jna.Library;
public interface TemperatureLibrary extends Library{
int GetTempCount();
int GetTemp1();
int GetTemp2();
int GetTemp3();
int GetTemp4();
int GetTemp5();
int GetTemp6();
int GetTemp7();
}
import com.sun.jna.Native;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TemperatureUtility {
public static final TemperatureLibrary INSTANCE;
static {
INSTANCE = Native.load("lib\\Temperature.dll", TemperatureLibrary.class);
refreshIfCanGetTemperature();
log.info("加载温度动态库完成。");
}
private TemperatureUtility() {
}
private static void refreshIfCanGetTemperature() {
long time = System.currentTimeMillis();
while (true) {
float i = INSTANCE.GetTemp1() / 10f;
if (i != 3276.7f) {
log.info("可以开始获取温度。加载时间ms:{}", System.currentTimeMillis() - time);
return;
} else {
try {
INSTANCE.GetTempCount();
Thread.sleep(10);
} catch (InterruptedException e) {
log.info("error at init getTemp1:{}", e);
Thread.currentThread().interrupt();
}
}
}
}
public static int getTempCount() {
return INSTANCE.GetTempCount();
}
public static float getTemp1() {
return INSTANCE.GetTemp1() / 10f;
}
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68