GithubHelp home page GithubHelp logo

icb-client's Introduction

icb-client

Helper library for controlling MIBIScope

example

import datetime
import shutil
import time
import requests
from icb import ICB

# connect to ICB
icb = ICB("ws://localhost:8088")

# create/get HV resources
hv_state_resource = icb.get_resource('/hv-state')
hv_adc_resource = icb.get_resource('/hv-adc')

# power HV on
hv_state_resource.put({'state': 'POWER_ON'})

# subscribe to incoming HV messages
state_subscription = hv_state_resource.subscribe(lambda msg: print('> HV STATE: ', msg['body']['state']))
adc_subscription = hv_adc_resource.subscribe(lambda msg: print('> ADC VALUES: ', msg['body']['hvChannels']))

# more advanced subscription using RxPY (see https://github.com/ReactiveX/RxPY/tree/release/v1.6.x fro more details)
dac_subscription = icb \
    .get_resource('/hv-dac') \
    .messageSubject \
    .map(lambda msg: msg['body']['hvChannels']) \
    .filter(lambda data: True) \
    .subscribe(lambda data: print('> DAC VALUES: ', data))

# throttled stream
throttle = datetime.timedelta(seconds=1)
gascontrol_subscription = icb \
    .get_resource('/gascontrol') \
    .messageSubject \
    .throttle_first(throttle) \
    .subscribe(lambda msg: print(msg['body']))

# give ICB some time to open DAC, in real code it should be guarded by getting real HV state
time.sleep(2)

# power HV off later
time.sleep(10)
hv_state_resource.put({'state': 'POWER_OFF'})

# save attached tiff image 
url = 'http://localhost:9099/api/runs'
r = requests.get(url, stream=True)
if r.status_code == 200:
    print(r)

# unsubscribe (if you really need it for some reason)
state_subscription.dispose()
adc_subscription.dispose()
dac_subscription.dispose()

# close connection and exit
icb.close()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.