haraldev / graphtecpython Goto Github PK
View Code? Open in Web Editor NEWPython script for reading values from Graphtec (GL840) device with PyVisa. Serves as minimum working example.
License: MIT License
Python script for reading values from Graphtec (GL840) device with PyVisa. Serves as minimum working example.
License: MIT License
I changed the source to support the expansion channel and tested it, and it is working.
Share the webpage and changed source for the expansion channel.
#Edit def append_graphtec_readings(self)
from bs4 import BeautifulSoup
from requests import get
from pandas import DataFrame
class Graphtec:
#-----------------------------------
def __init__(self, address, resource_manager):
self.address = address
self.tcpip_gl = f"TCPIP::{self.address}::8023::SOCKET" # TCPIP adress to contact
self.instrument = resource_manager.open_resource(self.tcpip_gl,
write_termination='\n',
read_termination='\r\n')
self.query_id = self.get_graphtec_idn()
self.data = [] # Holds measurement data
#-----------------------------------
def append_graphtec_readings(self):
"""Find all the measurements of the channels and append to self.data list"""
# Format URL
address_channel_data = f"http://{self.address}/digital.cgi?chgrp=13"
# Get http response
response = get(address_channel_data) # Get response from the channel data page
# Create response table
soup_object = BeautifulSoup(response.text, 'html.parser') # Create a soup object from this, which is used to create a table
temps = soup_object.select('b')
# Loop over table to yield formatted data
channels_data = []
# Holds all the found data > in format: [('CH 1', '+ 10', 'degC'), (CH2 ....]
temps = [read_tag.get_text(strip=True) for read_tag in temps]
count = 2
for idx, temp in enumerate(temps):
if idx == count:
channels_data.append(temps[idx-2:idx+1])
count = count + 3
# Append the data to the list
self.data.append(channels_data)
#-----------------------------------
def get_graphtec_idn(self):
"""SCPI command to get IDN"""
idn = self.instrument.query("*IDN?")
return idn
#-----------------------------------
def add_channel_data_to_df(self):
"""Post processing method to format self.data list into a Pandas DataFrame"""
name_index = 0 # Format is ['CH 1', '23.56', 'degC']
reading_index = 1 # so index 0, 1 and 2 are, respectively channel name, value reading and unit.
unit_index = 2
channel_count = len(self.data[0]) # Amount of channels to loop over, might depend on Graphtec device (I have 20)
df = DataFrame()
# Loop over each channel
for channel_ind in range(channel_count):
channel_name = self.data[0][channel_ind][name_index] # get the channel name
channel_unit = self.data[0][channel_ind][unit_index] # and unit
column_name = f"GRPH {channel_name} [{channel_unit}]" # Format column name "GRPH CH1 [degC]"
channel_readings = [] # Stores the channel data > [0.0, 0.1, 0.0 ....]
# Loop over each row and retrieve channel data
for row in self.data:
channel_reading = row[channel_ind][reading_index] # Read the data of channel for this row
# Value formatting
if channel_reading == '-------' or channel_reading == '+++++++' or channel_reading =='BURNOUT':
channel_reading = None #"NaN" # NaN for false values
else:
channel_reading = float(channel_reading.replace(' ',''))# Float for other values, remove spaces in order to have +/-
channel_readings.append(channel_reading)
df[column_name] = channel_readings # Add a new column with data
return df
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.