-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflir_a310_log_data_via_modbus.py
81 lines (51 loc) · 2.15 KB
/
flir_a310_log_data_via_modbus.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
# A crude script to log the Modbus TCP data from a single or several FLIR A310 IR cameras
# Find or set ip address of each camera on the network
# Adjust 'csv_header' and 'ip_list' to match the number and addresses of cameras
# Adjust 'reg' for desired data object in the camera
# see 'Convert EthernetIP to Modbus TCP.pdf'
# I have used this script with four cameras at a 1 second log interval with great success
# Many thanks to:
# https://pymodbustcp.readthedocs.io/en/latest/
# Casey J. Davis 2020.01.08
# python flir_a310_log_data_via_modbus.py
from pyModbusTCP.client import ModbusClient
from pyModbusTCP import utils
import datetime
import csv
import time
import os
# set working directory
os.chdir('C:\\Users\\yourusername\\Desktop\\')
# generate unique filename
csv_filename = time.strftime("%Y%m%d-%H%M%S") + ' FLIR Cams Box Average.csv'
# first row of csv file
# must have a 'timestamp X' and 'CAM X Box 1 Avg Temp [degC]' string for each camera
csv_header = ['timestamp 1','CAM 1 Box 1 Avg Temp [degC]','timestamp X','CAM X Box 1 Avg Temp [degC]',]
with open(csv_filename, 'w', newline='') as fp:
wr = csv.writer(fp, dialect='excel')
wr.writerow(csv_header)
while True:
# list of ip addresses for the cameras
ip_list = ['192.168.0.101', '192.168.0.X', ]
data_temp = []
for n in ip_list:
c = ModbusClient(host=n, unit_id=109, auto_open=True, auto_close=True)
if c.open():
# 4181 is the FLIR A310 register for the Box 1 Average Temperature
# many other options available - see 'Convert EthernetIP to Modbus TCP.pdf'
reg = c.read_holding_registers(4181, 2)
ts = datetime.datetime.now().timestamp()
c.close()
a= hex(reg[0])
b= hex(reg[1])
c = b+a[2:]
d = int(c,16)
T_avg_K = utils.decode_ieee(d)
T_avg_degC = T_avg_K - 273.15
data_temp.append(ts)
data_temp.append(round(T_avg_degC,2))
print(data_temp)
wr.writerow(data_temp)
# change log interval here
# FLIR A310 registers only appear to update about three times per second
time.sleep(1)