65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# This file is part of sensors2osc package
|
|
#
|
|
# sensors2osc is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# sensors2osc is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with sensors2osc. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
# Copyright (C) 2014 Stefan Kögl
|
|
|
|
|
|
|
|
import time, select
|
|
|
|
from sensors2osc.common import *
|
|
|
|
|
|
|
|
def main():
|
|
platform = init("ekg2osc")
|
|
|
|
actor = bytes(platform.args.actor, "ascii")
|
|
|
|
while 1:
|
|
try:
|
|
toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.05)
|
|
if toread:
|
|
t = platform.serial_sock.read(1)
|
|
else:
|
|
continue
|
|
except socket.error as msg:
|
|
# got disconnected?
|
|
print("serial socket error!!!", msg)
|
|
platform.reconnect()
|
|
|
|
try:
|
|
t = ord(t)
|
|
except TypeError as e:
|
|
continue
|
|
|
|
try:
|
|
print("got value", t)
|
|
osc_message = OSCMessage(b"/" + actor + b"/ekg")
|
|
osc_message.appendTypedArg(t, b"i")
|
|
platform.osc_sock.sendall(osc_message.encode_osc())
|
|
except socket.error as msg:
|
|
print("cannot connect to chaosc")
|
|
continue
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|