|
Post by alexis on Dec 27, 2018 11:58:17 GMT -5
I have a Lakeshore 240-2P and 240-8P. Is there a way to record data from these via USB, and not Profibus? I would like to record temperatures vs. time for a few hours. I don't think the chart recorder software works with the 240.
|
|
|
Post by Lake Shore Ogi on Jan 2, 2019 14:12:25 GMT -5
Hello Alexis,
It is possible to do this but you would have to write your own software/script to communicate with the 240's. Once you install the USB driver, communication becomes an emulated RS-232 communication and you would use the KRDG? query to get the readings. I confirm that the chart recorder is not compatible with the 240's. Please let us know if you have further questions.
Best Regards, Ogi K.
|
|
|
Post by alexis on Jan 3, 2019 10:52:53 GMT -5
Thanks, Ogi. I wrote a script for the USB communication, like you said, and it is working.
|
|
|
Post by Lake Shore Ryan on Jan 3, 2019 16:11:34 GMT -5
Hi Alexis,
Great to hear you wrote a script to record temperature values! Would you mind sharing the code for future users to start from? I also just finished a very unofficial Python script adapted from scripts we have for some of our newer instruments that could be useful for this purpose too. Doubt you'll want to use it given you already have something working, but maybe someone in the future will find it useful .
""" Script that repeatedly requests temperature values (K) from a 240 Series temperature module that is connected to a computer via a USB cable.
The classes below handle the specifics of detecting, automatically connecting to and communicating with a 240 Series module. Please note that these classes only enable a very small subset of functions on a 240 Series module. Specifically, requesting Kelvin temperature values for all enabled channels. Note that this configuration is not capable of supporting simultaneously connected 240 Series modules. Only one 240 Series modules can be interrogated at once. """
import serial from serial.tools.list_ports import comports from time import time from time import sleep
class SerialConnection: def __init__(self): self.connect()
def connect(self): # Scan ports for device and create serial port
valid_id_combos = [(0x1FB9, 0x0205)] # 240 Module serial_params = {'baudrate': 115200, 'timeout': 2, 'parity': serial.PARITY_NONE}
# Conduct port scan for port_name in comports(): if (port_name.vid, port_name.pid) in valid_id_combos: self.serial = serial.Serial(port_name.device, **serial_params) break else: raise Exception("""Cannot find device. Look at device manager and make sure the COM port is there. Also make sure that MeasureLINK for the 240 Series is not currently connected to the 240 module.""")
def disconnect(self): # Frees the COM port associated with the device
self.serial.close()
def command(self, command_string): # Issue command to device
# write the command out with the terminator self.serial.write(command_string.encode('ascii') + b'\n')
def query(self, query_string): # Send query to device and return response
# send the query string self.command(query_string)
# Return response with terminators stripped return self.serial.readline().decode('ascii').rstrip('\r\n')
class Series240: def __init__(self): self.serial_connection = SerialConnection()
def identify_model(self): # Returns a 2 if the connected unit is a 240-2P and an 8 if the unit is a 240-8P
# Looks inside the product part number for the term that identifies it as a 2 or 8 channel unit return int(self.serial_connection.query("*IDN?")[14])
def enabled_channels(self): # Scans through all channels in the unit and returns a list of channels that are enabled
channels = self.identify_model() # determine whether to scan 2 or 8 channels enabled = []
for channel in range(1, channels + 1): #scan through the channels in the unit
# request the input type for the channel and check to see if it is enabled if(self.serial_connection.query("INTYPE? " + str(channel))[10]=="1"): enabled.append(int(channel)) # add this channel to the list of enabled channels return enabled
def generate_header(self): # Returns a comma separated string that includes the channels that are currently set to enabled # For example: "Time, Ch1, Ch2, Ch4" would be returned if channels 1, 2 and 4 were enabled
query_channels = self.enabled_channels() # determine which channels are enabled for queries header_string = "Time" # A timestamp will be added as the first term of the queried temeprature values
# Add a comma separated channel number for each enabled channel on the device for channel in query_channels: header_string = header_string + ", Ch" + str(channel) return header_string
def query_temperature_all(self): # Return a numberic list of temperature values in Kelvin for all enabled channels
query_channels = self.enabled_channels() # determine which channels are enabled for queries readings = []
#request temperature value for each channel, convert to float and append to the list of readings for channel in query_channels: readings.append(float(self.serial_connection.query("KRDG? " + str(channel)))) return readings
def disconnect(self): # Frees the COM port associated with the device
self.serial_connection.disconnect()
"""=============== USER SCRIPT BEGINS HERE ==================
The script below sends a request for temperature values at a time interval approximated by 'INTERVAL' for a time period determined by 'DURATION'. The actual time interval will be slightly larger than what is set by 'INTERVAL'
Values will be output to screen and logged to a file defined by 'FILENAME'. The text has been formatted specifically for the csv filetype, so it is recommended to leave the file type the same if changing 'FILENAME'.
================================================================"""
# User modifiable variables INTERVAL = 0.1 # approximate time step in seconds. The actual time step will be slightly larger DURATION = 10 # amount of time in seconds to log values FILENAME = "log240.csv"
log_file = open(FILENAME, 'w') connection = Series240()
# Create the header for the log file. Includes all currently enabled measurement channels header = connection.generate_header() print(header) # Print header to screen log_file.write(header + "\n") # Save header to the log file
start = time() # Time in seconds since epoch that measurements begin stop = start + DURATION # Calculate when the measurements should end current = start # Set current time to the start time
# Print and log all temperature values until the stop time is reached while current < stop: current = time() # Create a new timestamp values = connection.query_temperature_all() # Query all temperature values from the unit # Create a string of values that can be displayed on the screen and saved to the log file value_string = '%.3f' % (current - start) + "," + ",".join(str(x) for x in values) print(value_string) # Print string of values log_file.write(value_string + "\n") # Save string of values to the log file
sleep(INTERVAL) # Wait for the defined amount of time log_file.close() # Close the log file connection.disconnect() # Disconnect from the serial interface
|
|