diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2008-06-24 11:32:43 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2008-06-24 11:32:43 +0000 |
commit | 6577139c7a8707fecb2e0752f8bf563a1ff44484 (patch) | |
tree | c0bab08a51cd4be4185c24ef809d9e834074ed64 | |
parent | 8beeec388b35fd140e229084f8d9a57a0b82b68a (diff) | |
download | pyserial-6577139c7a8707fecb2e0752f8bf563a1ff44484.tar.gz |
fix write, so that it is "binary" and not applying any encodings
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@187 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r-- | serial/serialcli.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/serial/serialcli.py b/serial/serialcli.py index af9c553..f31062a 100644 --- a/serial/serialcli.py +++ b/serial/serialcli.py @@ -6,6 +6,8 @@ # (C) 2008 Chris Liechti <cliechti@gmx.net> # this is distributed under a free software license, see license.txt +import clr +import System import System.IO.Ports from serialutil import * @@ -13,6 +15,12 @@ def device(portnum): """Turn a port number into a device name""" return System.IO.Ports.SerialPort.GetPortNames()[portnum] +# must invoke function with byte array, make a helper to convert strings +# to byte arrays +sab = System.Array[System.Byte] +def as_byte_array(string): + return sab([ord(x) for x in string]) + class Serial(SerialBase): """Serial port implemenation for .NET/Mono.""" @@ -33,6 +41,9 @@ class Serial(SerialBase): self._reconfigurePort() self._port_handle.Open() self._isOpen = True + if not self._rtscts: + self.setRTS(True) + self.setDTR(True) self.flushInput() self.flushOutput() @@ -130,6 +141,8 @@ class Serial(SerialBase): return less characters as requested. With no timeout it will block until the requested number of bytes is read.""" if not self._port_handle: raise portNotOpenError + # must use single byte reads as this is the only way to read + # without applying encodings data = [] while size: try: @@ -146,7 +159,9 @@ class Serial(SerialBase): if not isinstance(data, str): raise TypeError('expected str, got %s' % type(data)) try: - self._port_handle.Write(data) + # must call overloaded method with byte array argument + # as this is the only one not applying encodings + self._port_handle.Write(as_byte_array(data), 0, len(data)) except System.TimeoutException, e: raise writeTimeoutError |