2022-07-14 20:55:08 -04:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import IsegLibrary as iseg
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import time
|
|
|
|
|
2024-03-11 12:45:09 -04:00
|
|
|
import influxdb_client
|
|
|
|
from influxdb_client import InfluxDBClient, Point, WritePrecision
|
|
|
|
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
|
|
|
|
|
|
|
#------ database
|
2024-10-15 15:48:02 -04:00
|
|
|
try:
|
|
|
|
with open('ISEG_TOKEN.txt', 'r') as f:
|
|
|
|
token = f.readline()
|
|
|
|
except:
|
|
|
|
print("Error: ISEG_TOKEN.txt file not found.")
|
|
|
|
token = None # Or assign a default value if needed
|
2024-03-11 12:45:09 -04:00
|
|
|
|
|
|
|
org = "FSUFoxLab"
|
|
|
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
|
|
|
write_client = influxdb_client.InfluxDBClient(url=ip, token=token, org=org)
|
|
|
|
bucket = "ISEG"
|
|
|
|
write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
|
|
|
|
2022-07-14 20:55:08 -04:00
|
|
|
#assign a port, to prevent the script run mulitple time
|
|
|
|
s = socket.socket()
|
|
|
|
host = socket.gethostname()
|
|
|
|
port = 4305
|
|
|
|
s.bind((host,port))
|
|
|
|
|
|
|
|
|
|
|
|
chList = iseg.GetChList()
|
|
|
|
nChannel = len(chList)
|
|
|
|
|
|
|
|
updateTime = 2 #sec
|
|
|
|
|
|
|
|
# Event Loop to process "events" and get the "values" of the inputs
|
|
|
|
while True:
|
|
|
|
outVList = iseg.GetAllOutputHV()
|
|
|
|
outIList = iseg.GetAllLC()
|
|
|
|
|
2024-03-11 12:45:09 -04:00
|
|
|
# tempFile = open("temp.dat", "w")
|
|
|
|
points = []
|
2022-07-14 20:55:08 -04:00
|
|
|
|
|
|
|
for i in range(0, nChannel):
|
2024-03-11 12:45:09 -04:00
|
|
|
# tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i]))
|
|
|
|
# tempFile.write("LeakageCurrent,Ch=%d value=%f\n" % (chList[i], outIList[i]*1e6))
|
|
|
|
points.append(Point("Voltage").tag("Ch",int(chList[i])).field("value",float(outVList[i])))
|
|
|
|
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i])).field("value",float(outIList[i])))
|
|
|
|
|
|
|
|
|
|
|
|
# tempFile.close()
|
2022-07-14 20:55:08 -04:00
|
|
|
|
2024-03-11 12:45:09 -04:00
|
|
|
write_api.write(bucket=bucket, org=org, record=points)
|
|
|
|
# os.system("curl -XPOST http://128.186.111.107:8086/write?db=testing --data-binary @temp.dat")
|
2022-07-14 20:55:08 -04:00
|
|
|
|
|
|
|
time.sleep(updateTime)
|
|
|
|
|