Re: [Tutor] error_connection_refused

2012-06-06 Thread BILAL Mustapha

Hello,

 Thank you for your reply.

 Please read underlines.

Le 05/06/2012 23:12, Alan Gauld a écrit :

On 05/06/12 12:53, BILAL Mustapha wrote:

Hello,


Hi, Its best not to hijack somebody else's thread coz it messes up all 
the threaded mail/news readers out there. (At least you changed the 
subject though!). Please start with a fresh mail for a new topic.




Oops, sorry I didn't pay attention to it..

I am trying to lunch a small python program but I am always getting this
error:


How are you launching it? From a batch file or shell script?
From another Python program? From the Python prompt?


s.connect((IP, PORT))
File /usr/lib/python2.7/socket.py, line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

What's weird that it doesn't even print the line test sending data so
how it could get to s.connect() without passing through this line!!


It sounds like you might be using  a Python  prompt and not 
reloading the module after making changes. importing a second time 
won't work as Python knows you already have it and ignores it. You 
must use reload() for changes to take effect.


If thats not it then we need more details about what you are doing.

I actually found the solution which was somehow trivial, I was not 
listening to an open port so I changed the port and it worked fine.


Thank you again

Regards

HTH,



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] connecting to USB

2012-06-06 Thread BILAL Mustapha

Hello,

 I am working to connect to a serial link (USB). In order to do that I 
have to write this command:


sudo ../../tools/stm32w/serialdump-linux -b115200 -d1 (keeping in 
mind dat*serialdump-linux*, which is in the path, is not a folder, it's 
an executable)


To get to the root, I have used: returncode = 
subprocess.call([/usr/bin/sudo, /usr/bin/id])


Then to connect to the USB through the command above I tried the following:

usb = 
Popen(['../../tools/stm32w/serialdump-linux','-b115200','-d1'], 
stdout=PIPE, stdin=PIPE, stderr=STDOUT)


usb.communicate()[0]

 But I am getting an error, it's considering that serialdump-linux as a 
folder!!


 Any help how I can run the command?

 Many thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connecting to USB

2012-06-06 Thread BILAL Mustapha

Le 06/06/2012 11:02, BILAL Mustapha a écrit :

Hello,

 I am working to connect to a serial link (USB). In order to do that I 
have to write this command:


sudo ../../tools/stm32w/serialdump-linux -b115200 -d1 (keeping in 
mind dat*serialdump-linux*, which is in the path, is not a folder, 
it's an executable)


To get to the root, I have used: returncode = 
subprocess.call([/usr/bin/sudo, /usr/bin/id])


Then to connect to the USB through the command above I tried the 
following:


usb = 
Popen(['../../tools/stm32w/serialdump-linux','-b115200','-d1'], 
stdout=PIPE, stdin=PIPE, stderr=STDOUT)


usb.communicate()[0]

 But I am getting an error, it's considering that serialdump-linux as 
a folder!!


 Any help how I can run the command?

 Many thanks


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

I resolved the issue, you can do the following:

First method:
args = (sudo, ../../tools/stm32w/serialdump-linux, -b115200, 
-d1)

usb = Popen(args, stdout=PIPE, stdin=PIPE)
usb.wait()
usb.communicate()[0]

Second method:
cmd = 'sudo ../../tools/stm32w/serialdump-linux -b115200 -d1'
os.system(cmd)

you can run it using cmd and os or using Popen if you need to use stdout 
and stdin in your application (which is my case)


PS. -b115200 -d1 are two options related to USB so you can change 
the whole command and use any option you would like to.


Regards

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] error_connection_refused

2012-06-05 Thread BILAL Mustapha

Hello,

 I am trying to lunch a small python program but I am always getting 
this error:


s.connect((IP, PORT))
  File /usr/lib/python2.7/socket.py, line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

What's weird that it doesn't even print the line test sending data so 
how it could get to s.connect() without passing through this line!!


Here is the code:

#!/usr/bin/python
import socket
import thread
import time
from threading import Thread
import threading
import sys
IP = 130.190.31.167
PADDING = a * 1000
DATA = PADDING + this is sentence number = 
PORT = 8000
killed = False
count=0

def main():
print(the network manager process is created)
send_data()
def send_data():
*print(test sending data)*
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
*s.connect((IP, PORT))*
while killed==False:
 count= count+1
 sent = s.send(DATA+ str(count) + \n)
 if sent == 0:
  print 'The connection is died'
  killed=True
  s.close()

if __name__ == __main__:
main()

Many thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] packets_USB_python

2012-06-04 Thread BILAL Mustapha

Hello,

 I am beginner with python and I recently started to use it in order to 
achieve a small part of something I am working on.


 I have 2 processes (process 1 and process 2). I am wondering if you 
can provide me with some example or sample code of how I can do the 
following:


 - Process 2 receives icmpv6 (or any packet) from process1 and 
retransmit it to a serial link (USB)
 - Process 2 receives icmpv6 (or any packet) from the serial link (USB) 
and restransmit it to process 1.


 I had tried to write some code to, at least, ping but apparently I am 
missing something.


 Many thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] packets_USB_python

2012-06-04 Thread BILAL Mustapha

Le 04/06/2012 16:10, Alan Gauld a écrit :

On 04/06/12 14:58, BILAL Mustapha wrote:


- Process 2 receives icmpv6 (or any packet) from process1 and retransmit
it to a serial link (USB)
- Process 2 receives icmpv6 (or any packet) from the serial link (USB)
and restransmit it to process 1.


Oddly, Python does not have ICMP support in its standard library 
however there is an icmpv6 module on Activestate:


http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/ 



And there is also a module for reading/writing to usb ports (pyusb)...

http://pyusb.sourceforge.net/docs/1.0/tutorial.html

hth,


Thank you for your reply and for the useful links.

However Can't I use the popen() to lunch the process1 and write on its 
standard input? same thing for the process1 when it wants to sends 
infos(or packets) to process2 then it will use its standard output!


Best regards
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor