Owning /dev/ttyATH0 for use with Python (Tornado)


i'm trying take control on serial port , effect have commented out appropriate line in /etc/inittab

#ttyath0::askfirst:/bin/ash --login

i'm running own python code using tornado framework working fine (most of time).

i have pushing data arduino bounces back:

result: put/id/86:::10
result: put/id/87:::10
result: put/id/88:::10
result: put/id/89:::10
result: put/id/90:::10
result: put/id/91:::10
result: put/id/92:::10

where 'put/id/92' data.
occasionally see 'result: [ 2414.120000] eth1: link down:::30'
this indicates not writing serial port other process writing serial port.
how can find out other processes using , can make them stop?

my python code shown below reference.

code: [select]

import tornado.web
import tornado.httpserver
import tornado.websocket
import tornado.ioloop

import serial
import multiprocessing
import time

class serialprocess(multiprocessing.process):
def __init__(self, queuea):
multiprocessing.process.__init__(self)
self.queuea = queuea
self.ser = serial.serial(port='/dev/ttyath0', baudrate=9600, bytesize=serial.eightbits, parity=serial.parity_none, stopbits=serial.stopbits_one, timeout=1)
self.ser.isopen()
self.ser.flushinput()
self.ser.flushoutput()

def close(self):
self.ser.close()

def run(self):
while true:
# data needs writing down serial link
if not self.queuea.empty():
datastring = self.queuea.get()
for datachar in datastring:
self.ser.write(chr(datachar))
# data seen on serial link written console
if (self.ser.inwaiting() > 0):
result = self.ser.readline().replace('\r', '')
print 'result: %s:::%s' %(result, len(result))
time.sleep(0.25)

data = {}

queuea = multiprocessing.queue()
serialtask = serialprocess(queuea)
serialtask.daemon = true
serialtask.start()

################################################################################
class getresthandler(tornado.web.requesthandler):
def get(self, key):
httpjsondata = {'key': key, 'value': data.get(key, 'undefined'), 'response': 'get'}

self.write(httpjsondata)

class putresthandler(tornado.web.requesthandler):
def get(self, key, value):
global data
data[key] = value
# construct serial string , place on queue
serialdata = [ord(item) item in ('put/' + key + '/' + data[key])]
serialdata.extend(bytearray('\0\r\n'))
queuea = self.application.settings.get('queue')
queuea.put(serialdata)
# construct json data http , return it
httpjsondata = {'key': key, 'value': data[key], 'response': 'put'}
self.write(httpjsondata)
################################################################################

application = tornado.web.application(handlers=[(r'/data/get/(\w+$)', getresthandler), (r'/data/put/(\w+)/(\w+$)', putresthandler)], queue=queuea)
http_server = tornado.httpserver.httpserver(application)
http_server.listen(8080)
tornado.ioloop.ioloop.instance().start()

that sent kernel command line,  either @ boot or error.

code: [select]
nano target/linux/ar71xx/image/makefile

code: [select]
...
$(eval $(call singleprofile,yunlzma,$(fs_64k),yun_8m,yun-8m,yun,ttyath0,250000,$$(yun_mtdlayout_8m),1310720,6619136,rkuimage))
$(eval $(call singleprofile,yunlzma,$(fs_64k),yun_16m,yun-16m,yun,ttyath0,250000,$$(yun_mtdlayout_16m),1310720,15007744,rkuimage))
...


change ttyath0 ttyath1  ( second uart port if have ) or  ttys0  ( if you  have usb device port)

or

make cpu , mcu communication take place @ i2c, spi, phy.


Arduino Forum > Products > Arduino Yún (Moderator: fabioc84) > Owning /dev/ttyATH0 for use with Python (Tornado)


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support