Go Down

Topic: Yet another Serial Proxy :)  Python success!!! (Read 1 time) previous topic - next topic

dcb

After softening my forehead on serial port/windows/python/proxy issues I decided to write my own java proxy:

http://www.arduino.cc/playground/Interfacing/JavaProxy

The java proxy really simplifies the problem domain of connecting to an arduino from any "modern" language.

Here is the python I put together, still learning :) :
Code: [Select]

import socket
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 8225))
n = 3

while 1==1:
     v = sock.recv(1)
     d = ''
     while v != '\n':
           d = d + v
           v = sock.recv(1)
     print d
     n = n + 1
     st='line ' + str(n) +'\n'
     sock.send (st)


And here is the test pde:
Code: [Select]

void setup(){
Serial.begin(9600);
Serial.println("Hello Proxy!");
}

char buff[60];
void loop(){
delay(1000);
char c = Serial.read();
int n = 0;
while (c != '\n'){
buff[n++]=c;
c = Serial.read();
}
buff[n]=0;
Serial.println(buff);
}



And here is the output in case you don't believe me :)
Code: [Select]

C:\Python26>proxytst.py
Hello Proxy!
Hello Proxy!
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
line 13
line 14
Traceback (most recent call last):
 File "C:\Python26\proxytst.py", line 8, in <module>
   v = sock.recv(1)
KeyboardInterrupt


Go Up