/cricketlib

Python based API for controlling MCCI USB Switches. Models supported are 3141, 2101, 3201, 2301.

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

cricketlib

This is a Python library to control MCCI USB Switches and supports to Cricket UI.

Introduction

This repository is supports the Cricket UI and switching the MCCI USB Switches.

Install Python3.7 (32-bit) package

install python package from python.org

Install Python3.7 (64-bit) package

install python package from python.org

Install pip package

pip --version
python -m pip install --upgrade pip

Prerequisites for running or building

On Windows:

Development environment

  • OS - Windows 10 and 11 64 bit
  • Python - 3.7.8
  • pyserial - 3.5
  • pyusb - 1.2.1
  • hidapi - 0.11.2
pip install pyserial
pip install pyusb
pip install hidapi==0.11.2

On Linux:

Development environment

  • OS - Ubuntu 20.04 and Ubuntu 22.04 64 bit
  • Python - 3.9.10
  • pyserial - 3.4
  • pyusb - 1.0.2
  • libusb - 1.0.22b9
  • libusb1 - 3.0.0
  • hidapi - 0.11.2
sudo apt-get install python3-pip
sudo pip3 install pyserial
sudo pip3 install pyusb
sudo pip3 install libusb
sudo pip3 install libusb1
sudo pip3 install hidapi==0.11.2

On Mac:

Development environment

  • OS - Mac OS - Catalina 10.15.7 64 bit
  • Python - 3.6.9
  • pyserial - 3.4
  • pyusb - 1.0.2
  • libusb - 1.0.22b9
  • libusb1 - 3.0.0
  • hidapi - 0.10.1 for Mac OS
sudo apt-get update
sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install pyserial
sudo pip3 install pyusb
brew install libusb
sudo pip3 install libusb1
brew install hidapi - Only for Mac OS

Installing cricketlib Packages

  1. Clone the repository from github

  2. Open a cmd terminal and change directory to {path_to_repository}/cricketlib. using cd into the root directory where setup.py is located

  3. To install the library in your local Python setup, enter the command in Windows OS

python setup.py install
  1. To install the library in your local Python setup, enter the command in Linux OS.
sudo python3 setup.py install
  1. To install the library in your local Python setup, enter the command in Mac OS
sudo python3 setup.py install

Please navigate to dist/ directory and you will find the files .egg file. Example: cricketapi-1.5.0-py3.7.egg

package usage

Create a Python file named Simpletest.py and open in text editor and import the cricketlib modules.

# avalaible list of MCCI Switches with port number
from cricketlib import searchswitch
# import lib for switch 3142, switch3201, switch 2101, 2301
from cricketlib import switch3141
from cricketlib import switch3201
from cricketlib import switch2101 as S2101
from cricketlib import switch2301
# found a list of available switches.
# using the port number open the switch.
dev_list = searchswitch.get_switches()
print(dev_list)
# Serial Communication---
# windows Platform
# here COM5, COM8, COM13...etc are exapmple ports.
sw1 = switch3201.Switch3201('COM5') 
(or)
sw1 = switch3141.Switch3141('COM8')
(or)
sw1 = switch2101.Switch2101('0002CC0014FF')
(or)
sw1 = switch2301.Switch2301('COM13')
# ---Linux Platform Serial Communication---
# here /dev/ttyACMO, /dev/ttyACMO.etc are exapmple ports number.
sw1 = switch3201.Switch3201('/dev/ttyACMO') 
(or)
sw1 = switch3141.Switch3141('/dev/ttyACMO')

Connect the USB Switch to particular port number.

# Connect the USB Switch
sw1.connect()

port on command using parameters depends upon switches

# port on with port number
# sw1.port_on(1) first port ON
# sw1.port_on(2) second port ON
# sw1.port_on(3) third port 
# sw1.port_on(4) fourth port ON
# for switch3201, switch2301 have 4 ports
# for switch3141, switch3142 have 2 ports
# for switch2101 have 1 port

sw1.port_on(1)

Switching the port OFF

# port off with port number default empty or 0.
sw1.port_off()

Requested commands

Set Speed information

# Set High Speed
sw1.set_speed("HS")
# Set Super Speed
sw1.set_speed("SS")

Get Status

# Get the status of current port number.
sw1.get_status()

Get the Volts and Amps information

# get the voltage reading only for switch 3201, switch2301 and Switch3142
sw1.get_volts()
# get the amps reading only for switch 3201, switch2301 and switch3142
sw1.get_amps()

Switch 2101 ports switching

sw3 = S2101.Switch2101('0002CC0014FF')
sw3.connect()
sw3.port_on("ss")
time.sleep(2)
sw3.port_off()
time.sleep(1)
sw3.port_on("hs")
time.sleep(1)
sw3.port_off()

Release History

  • v1.0.5 update hidapi package.
  • v1.0.4 Support for Switch 2101 port status and implenting hidapi for windows and linux
  • v1.0.3 Support python 64-bit
  • v1.0.2 update speed change in switch2101
  • v1.0.0 initial release