Table Of Contents

Previous topic

BitsPlusPlus

Next topic

ColorCAL

This Page

Quick links

BitsSharp

Control a CRS Bits# device. See typical usage in the class summary (and in the menu demos>hardware>BitsBox of PsychoPy’s Coder view).

Attributes

BitsSharp([win, portName, mode, …]) A class to support functions of the Bits#
BitsSharp.mode Get/set the mode of the BitsSharp to one of:
BitsSharp.isAwake() Test whether we have an active connection on the virtual serial
BitsSharp.getInfo() Returns a python dictionary of info about the Bits Sharp box
BitsSharp.checkConfig([level, demoMode, logFile]) Checks whether there is a configuration for this device and
BitsSharp.gammaCorrectFile Get / set the gamma correction file to be used
BitsSharp.temporalDithering Temporal dithering can be set to True or False
BitsSharp.monitorEDID Get / set the EDID file for the monitor.
BitsSharp.beep([freq, dur]) Make a beep of a given frequency and duration
BitsSharp.getVideoLine(lineN, nPixels[, …]) Return the r,g,b values for a number of pixels on a particular
BitsSharp.start() [Not currently implemented] Used to begin event collection by
BitsSharp.stop() [Not currently implemented] Used to stop event collection by

Direct communications with the serial port:

BitsSharp.sendMessage(message[, autoLog]) Send a command to the device (does not wait for a reply or sleep())
BitsSharp.getResponse([length, timeout]) Read the latest response from the serial port

Control the CLUT (Bits++ mode only):

BitsSharp.setContrast(contrast[, LUTrange, …]) Set the contrast of the LUT for ‘bits++’ mode only
BitsSharp.setGamma(newGamma) Set the LUT to have the requested gamma value Currently also resets the LUT to be a linear contrast ramp spanning its full range.
BitsSharp.setLUT([newLUT, gammaCorrect, …]) SetLUT is only really needed for bits++ mode of bits# to set the look-up table (256 values with 14bits each).

Details

class psychopy.hardware.crs.bits.BitsSharp(win=None, portName=None, mode='', checkConfigLevel=1, gammaCorrect='hardware', gamma=None, noComms=False)

A class to support functions of the Bits#

This device uses the CDC (serial port) connection to the Bits box. To use it you must have followed the instructions from CRS Ltd. to get your box into the CDC communication mode.

Typical usage (also see demo in Coder view demos>hardware>BitsBox ):

from psychopy import visual
from psychopy.hardware import crs

# we need to be rendering to framebuffer
win = visual.Window([1024,768], useFBO=True)
bits = crs.BitsSharp(win, mode = 'mono++')
# You can continue using your window as normal and OpenGL shaders
# will convert the output as needed

print(bits.info)
if not bits.OK:
    print('failed to connect to Bits box')
    core.quit()

core.wait(0.1)
# now, you can change modes using
bits.mode = 'mono++' # 'color++', 'mono++', 'bits++', 'status'
Parameters:

win : a PsychoPy Window object, required

portName : the (virtual) serial port to which the device is

connected. If None then PsychoPy will search available serial ports and test communication (on OSX, the first match of /dev/tty.usbmodemfa* will be used and on linux /dev/ttyS0 will be used

mode : ‘bits++’, ‘color++’, ‘mono++’, ‘status’

checkConfigLevel : integer

Allows you to specify how much checking of the device is done to ensure a valid identity look-up table. If you specify one level and it fails then the check will be escalated to the next level (e.g. if we check level 1 and find that it fails we try to find a new LUT):

  • 0 don’t check at all
  • 1 check that the graphics driver and OS version haven’t
    changed since last LUT calibration
  • 2 check that the current LUT calibration still provides
    identity (requires switch to status mode)
  • 3 search for a new identity look-up table (requires
    switch to status mode)
gammaCorrect : string governing how gamma correction is performed
‘hardware’: use the gamma correction file stored on the

hardware

‘FBO’: gamma correct using shaders when rendering the FBO

to back buffer

‘bitsMode’: in bits++ mode there is a user-controlled LUT

that we can use for gamma correction

noComms : bool

If True then don’t try to communicate with the device at all (passive mode). This can be useful if you want to debug the system without actually having a Bits# connected.

beep(freq=800, dur=1)

Make a beep of a given frequency and duration

checkConfig(level=1, demoMode=False, logFile='')

Checks whether there is a configuration for this device and whether it’s correct

Params:

level: integer

0: do nothing

1: check that we have a config file and that the graphics

card and operating system match that specified in the file. Then assume identity LUT is correct

2: switch the box to status mode and check that the

identity LUT is currently working

3: force a fresh search for the identity LUT

driverFor = []
gammaCorrectFile

Get / set the gamma correction file to be used (as stored on the device)

getInfo()

Returns a python dictionary of info about the Bits Sharp box

getResponse(length=1, timeout=0.1)

Read the latest response from the serial port

Params:
length determines whether we expect:

1: a single-line reply (use readline()) 2: a multiline reply (use readlines() which requires timeout) -1: may not be any EOL character; just read whatever chars are

there
getVideoLine(lineN, nPixels, timeout=1.0, nAttempts=10)

Return the r,g,b values for a number of pixels on a particular video line

Parameters:
  • lineN – the line number you want to read
  • nPixels – the number of pixels you want to read
  • nAttempts – the first time you call this function it has to get to status mode. In this case it sometimes takes a few attempts to make the call work
Returns:

an Nx3 numpy array of uint8 values

isAwake()

Test whether we have an active connection on the virtual serial port

longName = ''
mode

Get/set the mode of the BitsSharp to one of: “bits++” “mono++” (not currently working?) “color++” (not currently working?) “status” “storage” “auto”

monitorEDID

Get / set the EDID file for the monitor. The edid files will be located in the EDID subdirectory of the flash disk. The file “automatic.edid” will be the file read from the connected monitor.

name = 'CRS Bits#'
next()
pause()

Pause for a default period for this device

read(timeout=0.1)

Get the current waiting characters from the serial port if there are any

reset()

Deprecated: This was used on the old Bits++ to power-cycle the box It required the compiled dll, which only worked on windows and doesn’t work with Bits#

sendMessage(message, autoLog=True)

Send a command to the device (does not wait for a reply or sleep())

setContrast(contrast, LUTrange=1.0, gammaCorrect=None)

Set the contrast of the LUT for ‘bits++’ mode only

Parameters:
contrast : float in the range 0:1

The contrast for the range being set

LUTrange : float or array

If a float is given then this is the fraction of the LUT to be used. If an array of floats is given, these will specify the start / stop points as fractions of the LUT. If an array of ints (0-255) is given these determine the start stop indices of the LUT

Examples:
setContrast(1.0,0.5)
will set the central 50% of the LUT so that a stimulus with contr=0.5 will actually be drawn with contrast 1.0

setContrast(1.0,[0.25,0.5])

setContrast(1.0,[63,127])
will set the lower-middle quarter of the LUT (which might be useful in LUT animation paradigms)
setGamma(newGamma)

Set the LUT to have the requested gamma value Currently also resets the LUT to be a linear contrast ramp spanning its full range. May change this to read the current LUT, undo previous gamm and then apply new one?

setLUT(newLUT=None, gammaCorrect=False, LUTrange=1.0, contrast=None)

SetLUT is only really needed for bits++ mode of bits# to set the look-up table (256 values with 14bits each).

For the BitsPlusPlus device the deafult is to perform gamma correction here but on the BitsSharp it seems better to have the device perform that itself as the last step so gamma correction is off here by default.

If no contrast has yet been set (it isn’t needed for other modes) then it will be set to 1 here.

start()

[Not currently implemented] Used to begin event collection by the device

stop()

[Not currently implemented] Used to stop event collection by the device

temporalDithering

Temporal dithering can be set to True or False

win

The window that this box is attached to