Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-25 Thread bino oetomo
Dear Tim Allen and Jean-Paul
I realy appreciate your enlightment .. i try it and it works

Sincerely
-bino-
On 12/23/2011 11:15 AM, Tim Allen wrote:
 It looks like self.writethis is an Element, not a string. Python's
 print statement will automatically call str() on things before it prints
 them, but Twisted's .write() methods do not. You'll have to change your
 code to something like this:

  self.serial.write(str(self.writethis))

 Tim.

 ___
 Twisted-Python mailing list
 Twisted-Python@twistedmatrix.com
 http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-22 Thread bino oetomo
Dear Lucas
I realy appreciate your pastebin
On 12/22/2011 01:12 PM, Lucas Taylor wrote:


 ...and an update to your pastebin that may be helpful for context: 
 http://pastebin.com/2EJ22wXa

When I first try to adapt your script, there is error complaining about 
that serial have no setParent attribute/methode.
Next I found your enlightment at 
http://www.mentby.com/lucas-taylor/serialport-protocol-as-a-service.html

So here is my adaptation at http://pastebin.com/79qi3TfK

currently I just commented the line that send xmpp, I just want to make 
sure that the serial communication is working well.
When there ls line comming via serial line, the script just work as told :
---from the log file 
2011-12-23 09:31:29+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:31+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:33+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:35+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:37+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:39+0700 [-] Line Received from Arduino:  This is arduino
2011-12-23 09:31:41+0700 [-] Line Received from Arduino:  This is arduino
-

The problem is when there is msg coming from XMPP part
It's received by the xmpp client part, but script complaining about 
'SerialPort' object has no attribute 'transport'
I tried to send text from another xmppclient (pidgin)
---from the log file 
2011-12-23 09:31:29+0700 [XmlStream,client] 
2011-12-23 09:31:29+0700 [XmlStream,client]
2011-12-23 09:31:29+0700 [XmlStream,client] oooh
2011-12-23 09:31:29+0700 [XmlStream,client]
2011-12-23 09:31:29+0700 [XmlStream,client] 
2011-12-23 09:31:29+0700 [XmlStream,client]
2011-12-23 09:31:29+0700 [XmlStream,client] Unhandled Error
--
And the traceback is---
   File ./mytac01.tac, line 42, in onMessage
 self.serial.transport.write('some message\n')
 exceptions.AttributeError: 'SerialPort' object has no attribute 
'transport'
--

Line 42 is 
self.serial.transport.write('some message\n')
-

I tried to google with the error msg as keyword ... mostly about Serial 
port loosing connection.
In my case , the serial port still have it's connection . since the 
arduino msg still coming

Sincerely
-bino-

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-22 Thread exarkun
On 02:50 am, b...@indoakses-online.com wrote:
[snip]
The problem is when there is msg coming from XMPP part
It's received by the xmpp client part, but script complaining about
'SerialPort' object has no attribute 'transport'
I tried to send text from another xmppclient (pidgin)

A SerialPort doesn't have a transport.  It is a transport.  Instead of:

self.serial.transport.write(foo)

try

self.serial.write(foo)

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-22 Thread bino oetomo
Dear Jean-Paul
Thankyou for your help.
On 12/23/2011 09:57 AM, exar...@twistedmatrix.com wrote:

 A SerialPort doesn't have a transport.  It is a transport.  Instead of:

  self.serial.transport.write(foo)

 try

  self.serial.write(foo)


Here is my function (edited)
---START---
 def onMessage(self, msg):
 #Will just print the msg body to stdout
 self.writethis = msg.body
 print '\n'
 print self.writethis
 print '\n\n'
 # Send something to serial port
 #self.serial.transport.write('some message\n')
 self.serial.write(self.writethis)
--

the print self.writethis do as told

but the self.serial.write(self.writethis) line raise an exceptions
--START-
   File ./mytac01.tac, line 44, in onMessage
 self.serial.write(self.writethis)
   File 
/usr/lib/python2.6/dist-packages/twisted/internet/abstract.py, line 
191, in write
 self._tempDataLen += len(data)
 exceptions.TypeError: object of type 'Element' has no len()
--

Sincerely
-bino-

 Jean-Paul

 ___
 Twisted-Python mailing list
 Twisted-Python@twistedmatrix.com
 http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-22 Thread Tim Allen
On Fri, Dec 23, 2011 at 11:09:32AM +0700, bino oetomo wrote:
 the print self.writethis do as told
 
 but the self.serial.write(self.writethis) line raise an exceptions
 --START-
File ./mytac01.tac, line 44, in onMessage
  self.serial.write(self.writethis)
File 
 /usr/lib/python2.6/dist-packages/twisted/internet/abstract.py, line 
 191, in write
  self._tempDataLen += len(data)
  exceptions.TypeError: object of type 'Element' has no len()
 --

It looks like self.writethis is an Element, not a string. Python's
print statement will automatically call str() on things before it prints
them, but Twisted's .write() methods do not. You'll have to change your
code to something like this:

self.serial.write(str(self.writethis))

Tim.

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-21 Thread Lucas Taylor


On Dec 21, 2011, at 9:52 PM, bino oetomo wrote:


Dear All ..

A year ago, I need send some defined message to a jabber conference.
The message content will depend on a button-press.
My trick is to use ttyctrl (http://ttyctrl.sourceforge.net/).

So basicaly my system is builded from several parts:
1. TTYCTRL : I made some small python XMLRPC client script, that will
send a msg to my local twisted server
2. Twisted server, contain :
a. an XMLRPC server
b. XMPP Client ... use to send msg to remote jabber conference room

I made a pastebin of that twisted script at : http://pastebin.com/iSRVZNwS

With that script the flow alway one-way only :
serialTwisted_XMLRPC---Twisted_XMPP=Jaber

Now I need to do something different, since it's hard to find a Board
with RS232 onboard.
I Need to replace TTYCTRL with Arduino MCU.
Arduino will Send serial data to my PC.
So I'll need my twisted to able to receive data via serial
There will also incoming XMPP msg from Jabber that will need to be  
send

to arduino via Serial port.

so the flow will be like :
serialTwisted_Serial---Twisted_XMPP=Jaber


My question is, How to make :
1. twisted.internet.serial to send data via an instance of XMPP  
client ? and

2. my EchobotProtocol.onMessage (see pastebin), to write data to the
same serial port used by Point#1 above.




This is a relevant FAQ for this situation:
http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeinputononeconnectionresultinoutputonanother

More specifically:
1. Create a Protocol class for your SerialPort that will communicate  
with the Arduino. Instances of this class will have access to the  
serial transport and can write out to the serial port. Incoming  
messages from the Arduino will be handled by the dataReceived method  
of the protocol.


2. Give your EchoBotProtocol a reference to the SerialPort somehow  
(e.g. via init), and set a reference to the EchoBotProtocol on the  
SerialPort.


Here's a quick sketch:

# Basic line receiver protocol
class ArduinoReceiver(LineReceiver):
def lineReceived(self, line):
print Line Received from Arduino
		self.echobot.send('some xmpp message for which I do not know the  
format')


# Wire up the serial port and protocol...note there are more  
parameters to create the SerialPort (baudrate, etc.)

serial = SerialPort(ArduinoReceiver, '/dev/tty.usbserial', reactor)

# EchoBot gets a reference to the serialport
class EchoBotProtocol(MessageProtocol):
def __init__(self, serial, *args, **kwargs):
self.serial = serial
# Set a reference to self on the serial protocol
self.serial.protocol.echobot = self
MessageProtocol.__init__(self, *args, **kwargs)

def onMessage(self, msg):
self.serial.transport.write('some message\n')

echobot = EchoBotProtocol(serial)

...and an update to your pastebin that may be helpful for context: 
http://pastebin.com/2EJ22wXa



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question : Combining wokel XMPP and twisted.internet.serial

2011-12-21 Thread bino oetomo
Dear Lucas Taylor

Thankyou for your fast enlightment.

It's time for me to re-build my ejabberd turnkey linux

Sincerely
-bino-

On 12/22/2011 01:12 PM, Lucas Taylor wrote:


 This is a relevant FAQ for this situation:
 http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeinputononeconnectionresultinoutputonanother
  


 More specifically:
 1. Create a Protocol class for your SerialPort that will communicate 
 with the Arduino. Instances of this class will have access to the 
 serial transport and can write out to the serial port. Incoming 
 messages from the Arduino will be handled by the dataReceived method 
 of the protocol.

 2. Give your EchoBotProtocol a reference to the SerialPort somehow 
 (e.g. via init), and set a reference to the EchoBotProtocol on the 
 SerialPort.

 Here's a quick sketch:

 # Basic line receiver protocol
 class ArduinoReceiver(LineReceiver):
 def lineReceived(self, line):
 print Line Received from Arduino
 self.echobot.send('some xmpp message for which I do not know 
 the format')

 # Wire up the serial port and protocol...note there are more 
 parameters to create the SerialPort (baudrate, etc.)
 serial = SerialPort(ArduinoReceiver, '/dev/tty.usbserial', reactor)

 # EchoBot gets a reference to the serialport
 class EchoBotProtocol(MessageProtocol):
   def __init__(self, serial, *args, **kwargs):
 self.serial = serial
 # Set a reference to self on the serial protocol
 self.serial.protocol.echobot = self
 MessageProtocol.__init__(self, *args, **kwargs)

 def onMessage(self, msg):
 self.serial.transport.write('some message\n')

 echobot = EchoBotProtocol(serial)

 ...and an update to your pastebin that may be helpful for context: 
 http://pastebin.com/2EJ22wXa






___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python