Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add twisted support for asynchronous programming #21

Open
GoogleCodeExporter opened this issue Apr 11, 2015 · 5 comments
Open

Add twisted support for asynchronous programming #21

GoogleCodeExporter opened this issue Apr 11, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Hi, I know it's difficult to implement(maybe out of scope) but I think a 
twisted transport will be wonderful to have.

Can I fork this to implement an XBEE twisted transport?

Original issue reported on code.google.com by [email protected] on 23 Jun 2011 at 9:04

@GoogleCodeExporter
Copy link
Author

Hi. Any luck with that?

I'll take this opportunity to introduce something I'm working on: 
http://code.google.com/p/open-zb-home/
(before I try make it more public..)

Please feel free to check it out and let me know what you think.

I've got a little work-around that I'm suing in the meantime:

{{{

def getFromXBeeThread():
        while True:
                response = xbee.wait_read_frame()
                if response ["id"]=="rx":
                        print response["rf_data"],
                        threads.deferToThread(getFromXBeeThread).addCallback(dispatchTCP)
                        return response["rf_data"]
}}}

you just have to call it once to start it, then it will loop itself.

Original comment by [email protected] on 12 Aug 2011 at 11:02

@GoogleCodeExporter
Copy link
Author

I have done this twisted protocol:
http://pastebin.com/fUcuexHW

An implementation example:
http://pastebin.com/pLdVV4gn

Original comment by [email protected] on 12 Aug 2011 at 7:23

@GoogleCodeExporter
Copy link
Author

Hi all,

Sorry for responding so late; it slipped my mind a while back.

I'm not sure I quite understand what you asking, wsartori. Do you want to make 
a whole new XBee library for Twisted? 

Now, I don't know much about Twisted and how it does things; would it be 
possible to get the functionality you want by making a package within the 
helpers package of python-xbee? If all you need is to wrap an XBee instance 
such that Twisted can access it, then checking it in here would ensure that you 
get the latest fixes/updates/etc. without regularly pulling from upstream.

What do you think?

Thanks,
~Paul Malmsten

Original comment by [email protected] on 13 Aug 2011 at 8:44

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Thanks wsartori. I've implemented your snippets and it's working well. I was 
using the defereToThread before but it was blocking the shutdown.. 
daemonizing..etc.. you solved it:)

Paul, Twisted is a "network-engine", it's a bunch of tools that simplify doing 
loads of things like creating web servers, tcp servers, clients, etc. It's 
completely asynchronous and non-blocking and works best when the rest of the 
code is too.

Your library has asynchronous calls in it that also defer but I didnt get 
around to trying it out.  

This is only relevant to receiving since sending is asynchronous anyway...

Original comment by [email protected] on 14 Aug 2011 at 1:28

@GoogleCodeExporter
Copy link
Author

I decided to make it a separated project to don't add a dependency to twisted 
on python-xbee.

I made the package and it's available on pypi:
http://pypi.python.org/pypi/txXBee/

source: https://github.com/trunet/txXBee

you can close this issue.

Original comment by [email protected] on 3 Oct 2011 at 1:37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant