>> Why you want to use RS232, i would choose TCP ,UDP or WebServer
Personal preexisting skill set. I have been using serial connections
for 4 years on multiple projects with multiple pieces of hardware. I
wrongly believed that it would be easy to just use serial again.
And I will finally learn a python ;)
Test this: (on linux *telnet ip_of_python_host 5000* on windows with
putty telnet to port 5000 )
|import select
import socket
from timeimport sleep
#telnet escape sequences
CLEAR_SCREEN = chr(27) +"[2J"
MOVE_TO_LINE_1 = chr(27) +"[1;1H"
MOVE_TO_LINE_2 = chr(27) +"[2;1H"
MOVE_TO_LINE_3 = chr(27) +"[3;1H"
MOVE_TO_LINE_4 = chr(27) +"[4;1H"
MOVE_TO_LINE_5 = chr(27) +"[5;1H"
MOVE_TO_LINE_6_ST = chr(27) +"[6;1H"
MOVE_TO_LINE_6 = chr(27) +"[6;15H"
CLEAR_LINE = chr(27) +"[2K"
CLEAR_LINE_TO_END = chr(27) +"[K"
SAVE_CURSOR = chr(27) +"7"
RESTORE_CURSOR = chr(27) +"8"
TXT_CMD ="Enter command:"
#
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setblocking(0)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
server.bind(('0.0.0.0',5000))
server.listen(5)
inputs = [server]
counter1 =0
counter2 =0
counter3 =0
counter4 =0
counter5 =0
addrs = {}
terminalInitOk = []
data =None
while inputs:
readable, writable, exceptional = select.select(inputs, inputs, inputs)
for sin readable:
if sis server:
connection, client_address = s.accept()
connection.setblocking(0)
inputs.append(connection)
print('Client connected...' + str(client_address))
addrs[connection] = client_address
else:
try:
if sin inputs:
data = s.recv(1024)
if data:
print('Client:' + str(addrs[s]) +' Received command:'
+ data +'\n')
if sin terminalInitOk:
s.send(MOVE_TO_LINE_6_ST+ CLEAR_LINE+ TXT_CMD +
MOVE_TO_LINE_6)
except:
inputs.remove(s)
terminalInitOk.remove(s)
c.close();
print('Client' + str(addrs[s]) +' disconnected..')
if len(inputs):
counter1 = counter1 +1 #At least one client is attached make the
calculation
counter2 = counter2 +10
counter3 = counter3 +100
counter4 = counter4 +1000
counter5 = counter5 +10000
for sin writable:
try:
if sin inputs:#send new value to client
if sin terminalInitOk:
s.send(SAVE_CURSOR + MOVE_TO_LINE_1 + CLEAR_LINE +
str(counter1) \
+ MOVE_TO_LINE_2 + CLEAR_LINE + str(counter2) \
+ MOVE_TO_LINE_3 + CLEAR_LINE + str(counter3) \
+ MOVE_TO_LINE_4 + CLEAR_LINE + str(counter4)
+ MOVE_TO_LINE_5 + CLEAR_LINE + str(counter5) +
RESTORE_CURSOR)
else:
#init telnet terminal
s.send(CLEAR_SCREEN +MOVE_TO_LINE_1+ str(counter1) \
+ MOVE_TO_LINE_2 + str(counter2) \
+ MOVE_TO_LINE_3 + str(counter3) \
+ MOVE_TO_LINE_4 + str(counter4) \
+ MOVE_TO_LINE_5 + str(counter5) \
+ MOVE_TO_LINE_6_ST + TXT_CMD + MOVE_TO_LINE_6)
terminalInitOk.append(s)
except:
inputs.remove(s)
terminalInitOk.remove(s)
print('Client' + str(addrs[s]) +' disconnected..')
s.close();
if len(writable):
sleep(0.1)#Slow down writing
for sin exceptional:
if sin inputs:
inputs.remove(s)
terminalInitOk.remove(s)
print('Client' + str(addrs[s]) +' disconnected..')
s.close();
|
arsi
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/590E1F46.20305%40chello.sk.
For more options, visit https://groups.google.com/d/optout.