Ejemplo n.º 1
0
def main():
    tornado.options.parse_command_line()

    loop = tornado.ioloop.IOLoop.current()
    printer = SerialDevice()

    serial_port_func = functools.partial(json_handle_set_serial_port, printer)

    # dispatcher.add_dict({"set-serial-port": serial_port_func })

    #----------------------------------------
    # THIS DEFINES THE JSON-RPC API:
    #----------------------------------------
    async def r_creator(request):
        params = request.params

        if request.method == "set-serial-port":
            result = await serial_port_func(*params)
            return result
        elif request.method == "get-serial-ports":
            result = await json_handle_portslist()
            return result
        elif request.method == "send-gcode":
            result = await json_handle_gcode(printer, *params)
            return result
        elif request.method == "get-printer-state":
            result = await json_handle_printer_state(printer)
            return result
        elif request.method == "close-serial-port":
            result = await json_handle_close_serial(printer)
            return result

        else:
            raise MethodNotFound("{}".format(request.method))

    settings = dict(
        cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        xsrf_cookies=False,
    )
    handlers = [
        (r"/", MainHandler),
        (r"/test", TestHandler, dict(printer=printer)),
        (r"/jsontest", JsonTestHandler),
        (r"/jsonqtest", JsonQueueTestHandler),
        # (r"/jsonrpc", JSONHandler),
        (r"/jsonrpc", JSONRPCHandler, dict(response_creator=r_creator)),
    ]
    application = tornado.web.Application(handlers=handlers,
                                          debug=True,
                                          **settings)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)

    tornado.ioloop.IOLoop.current().start()
Ejemplo n.º 2
0
import time
from SerialDevice import SerialDevice

imu = SerialDevice("COM3",
                   19200,
                   buffer_read_len=10,
                   buffer_write_len=10,
                   debug=True)
imu.start()
time.sleep(1)
print(imu.get())
time.sleep(1)
print(imu.get())
time.sleep(1)
print(imu.get())
time.sleep(1)
imu.pause()
time.sleep(1)
print(imu.get())
time.sleep(1)
imu.resume()
time.sleep(1)
imu.pause()
time.sleep(1)
imu.stop()
Ejemplo n.º 3
0
serialdevice = None

zstart = 100
zend = 120
zstep = 1

xstart = 500
xend = 2500
xstep = 50
# Very hacky to have always the same Serial device..
serialdevice = serial.Serial(serialadress, 115200, timeout=.1)

time.sleep(2)

try:
    ledarr = SerialDevice(serialdevice)  # normally 0x07
except Exception as e:
    print(e)
    ledarr = False
    logger.debug("LEDARray is not connected!")

# connect to Motors
try:
    motors = SerialDevice(serialdevice)  # normally 0x08
except:
    motors = False
    logger.debug("Motors are not connected!")

# connect to Fluo
try:
    fluo = SerialDevice(serialdevice)
Ejemplo n.º 4
0
            "powershell.exe",
            "Function Set-Speaker($Volume){$wshShell = new-object -com wscript.shell;1..50 | % {$wshShell.SendKeys([char]174)};1..$Volume | % {$wshShell.SendKeys([char]175)}} ; Set-Speaker("
            + winVolume + ")"
        ],
                        shell=True)
    elif os == "darwin":
        subprocess.call("osascript -e 'set volume output volume " +
                        str(percent) + "'",
                        shell=True)
    elif os == "linux":
        val = float(int(percent))
        proc = subprocess.Popen('/usr/bin/amixer sset Master ' + str(val) +
                                '%',
                                shell=True,
                                stdout=subprocess.PIPE)
        proc.wait()


def cb(event):
    try:
        print(event)
        if (event.startswith("set_volume_")):
            percent = event.split("_")[-1]
            setVolume(percent)
    except:
        traceback.print_exc()


pidVid = (32799, 9114)
mediaDevice = SerialDevice(cb, pidVid)
is_serial = True
serialadress = '/dev/ttyUSB0'
serialdevice = None

zstart = 100
zend = 120
zstep = 1

xstart = 1200
xend = 1900
xstep = 50
# Very hacky to have always the same Serial device..
serialdevice = serial.Serial(serialadress, 115200, timeout=.1)

time.sleep(2)

try:
    ledarr = SerialDevice(serialdevice)  # normally 0x07
except Exception as e:
    print(e)
    ledarr = False
    logger.debug("LEDARray is not connected!")

for iz in range(zstart, zend, zstep):
    fluo.send("LENS1Z", int(iz))
    time.sleep(0.1)
    for ix in range(xstart, xend, xstep):
        fluo.send("LENS1X", int(ix))
        time.sleep(0.1)
Ejemplo n.º 6
0
serialdevice = None

global lensX1
lensX1 = 0
global lensZ1
lensZ1 = 0

# Very hacky to have always the same Serial device..
try:
    serialdevice = serial.Serial(serialadress, 115200, timeout=.1)
    time.sleep(2)
except:
    serialdevice = 1

try:
    esp_lens = SerialDevice(serialdevice)  # normally 0x07
except Exception as e:
    print(e)
    esp_lens = False
    logger.debug("esp_lens is not connected!")
'''
for iz in range(zstart,zend,zstep):
    fluo.send("LENS1Z", int(iz))
    time.sleep(0.1)
    for ix in range(xstart,xend,xstep):
        fluo.send("LENS1X", int(ix))
        time.sleep(0.1)
'''


# This callback will be bound to the LED toggle and Beep button: