Pages: [1]   Go Down
Author Topic: Yet another Serial Proxy :)  Python success!!!  (Read 1002 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley :
Code:
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:
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 smiley
Code:
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
Logged

Pages: [1]   Go Up
Jump to: