Skip to content

Commit

Permalink
Merge 1f4e13d into 767536c
Browse files Browse the repository at this point in the history
  • Loading branch information
scasagrande committed Jan 23, 2016
2 parents 767536c + 1f4e13d commit 4b77e80
Show file tree
Hide file tree
Showing 20 changed files with 2,391 additions and 806 deletions.
41 changes: 41 additions & 0 deletions instruments/doc/examples/ex_thorlabstc200.py
@@ -0,0 +1,41 @@
#Thorlabs Temperature Controller example

import instruments as ik
import quantities
tc = ik.thorlabs.TC200.open_serial('/dev/tc200', 115200)


tc.temperature = 70*quantities.degF
print("The current temperature is: ", tc.temperature)

tc.mode = tc.Mode.normal
print("The current mode is: ", tc.mode)

tc.enable = True
print("The current enabled state is: ", tc.enable)

tc.p = 200
print("The current p gain is: ", tc.p)

tc.i = 2
print("The current i gain is: ", tc.i)

tc.d = 2
print("The current d gain is: ", tc.d)

tc.degrees = quantities.degF
print("The current degrees settings is: ", tc.degrees)

tc.sensor = tc.Sensor.ptc100
print("The current sensor setting is: ", tc.sensor)

tc.beta = 3900
print("The current beta settings is: ", tc.beta)

tc.max_temperature = 150*quantities.degC
print("The current max temperature setting is: ", tc.max_temperature)

tc.max_power = 1000*quantities.mW
print("The current max power setting is: ", tc.max_power)


@@ -1,14 +1,14 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# loopback_communicator.py: Loopback communicator, just prints what it receives
#
# loopback_communicator.py: Loopback communicator, just prints what it receives
# or queries return empty string
##
# © 2013-2015 Steven Casagrande (scasagrande@galvant.ca).
#
# © 2013-2016 Steven Casagrande (scasagrande@galvant.ca).
#
# This file is a part of the InstrumentKit project.
# Licensed under the AGPL version 3.
##
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -21,76 +21,83 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
##
#
#

## IMPORTS #####################################################################
# IMPORTS #####################################################################

import io
from instruments.abstract_instruments.comm import AbstractCommunicator
import sys

## CLASSES #####################################################################
# CLASSES #####################################################################


class LoopbackCommunicator(io.IOBase, AbstractCommunicator):

"""
Used for testing various controllers
"""

def __init__(self, stdin=None, stdout=None):
AbstractCommunicator.__init__(self)
self._terminator = '\n'
self._stdout = stdout
self._stdin = stdin
## PROPERTIES ##

# PROPERTIES ##

@property
def address(self):
return sys.stdin.name

@address.setter
def address(self, newval):
raise NotImplementedError()

@property
def terminator(self):
return self._terminator

@terminator.setter
def terminator(self, newval):
if not isinstance(newval, str):
raise TypeError('Terminator must be specified '
'as a single character string.')
'as a single character string.')
if len(newval) > 1:
raise ValueError('Terminator for LoopbackCommunicator must only be 1 '
'character long.')
'character long.')
self._terminator = newval

@property
def timeout(self):
return 0

@timeout.setter
def timeout(self, newval):
pass
## FILE-LIKE METHODS ##

# FILE-LIKE METHODS ##

def close(self):
try:
self._stdin.close()
except:
pass
def read(self, size):

def read(self, size=-1):
"""
Gets desired response command from user
:param int size: Number of characters to read. Default value of -1
will read until termination character is found.
:rtype: `str`
"""
if self._stdin is not None:
if (size >= 0):
if size >= 0:
input_var = self._stdin.read(size)
return input_var
elif (size == -1):
elif size == -1:
result = bytearray()
c = 0
while c != self._terminator:
Expand All @@ -105,43 +112,41 @@ def read(self, size):
else:
input_var = raw_input("Desired Response: ")
return input_var

def write(self, msg):
if self._stdout is not None:
self._stdout.write(msg)
else:
print " <- {} ".format(repr(msg))



def seek(self, offset):
return NotImplemented

def tell(self):
return NotImplemented

def flush_input(self):
pass
## METHODS ##

# METHODS ##

def sendcmd(self, msg):
'''
"""
Receives a command and passes off to write function
:param str msg: The command to be received
'''
"""
if msg is not '':
msg = msg + self._terminator
msg = "{}{}".format(msg, self._terminator)
self.write(msg)

def query(self, msg, size=-1):
'''
"""
Receives a query and returns the generated Response
:param str msg: The message to received
:rtype: `str`
'''
"""
self.sendcmd(msg)
resp = self.read(size)
return resp

Expand Up @@ -104,10 +104,10 @@ def close(self):
self._conn.close()

def read(self, size):
if (size >= 0):
if size >= 0:
resp = self._conn.read(size)
return resp
elif (size == -1):
elif size == -1:
result = bytearray()
c = 0
while c != self._terminator:
Expand Down

0 comments on commit 4b77e80

Please sign in to comment.