diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-08-02 00:00:11 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-08-02 00:00:11 +0000 |
commit | e73ca9e6a6d6df369703f5dff08d9681c94fea61 (patch) | |
tree | db9615732e34c29f253e5111be41d2d31946d36b /serial/__init__.py | |
parent | 3d4603434e2515967883e86fe28d98453f7e3672 (diff) | |
download | pyserial-e73ca9e6a6d6df369703f5dff08d9681c94fea61.tar.gz |
add helper function to automatically select native or RFC2217 implementation of Serial object
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@269 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'serial/__init__.py')
-rw-r--r-- | serial/__init__.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/serial/__init__.py b/serial/__init__.py index 6e160e0..acda005 100644 --- a/serial/__init__.py +++ b/serial/__init__.py @@ -24,3 +24,17 @@ else: else: raise Exception("Sorry: no implementation for your platform ('%s') available" % os.name) + +def serial_class_for_url(url, do_not_open=False, *args, **kwargs): + """Get a native or a RFC2217 implementation of the Serial class, depending + on port/url. The port is not opened when do_not_open is true, by default it is.""" + if url.lower().startswith('rfc2217://'): + import rfc2217 # late import, so that users that don't use it don't have to load it + klass = rfc2217.Serial # RFC2217 implementation + else: + klass = Serial # 'native' implementation + instance = klass(None, *args, **kwargs) + instance.port = url + if not do_not_open: + instance.open() + return instance |