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-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 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 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