diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-12-03 11:00:35 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2018-12-03 12:04:32 -0500 |
| commit | 80db2cec99ca5c995a0302b1d6d00ad77cfcd736 (patch) | |
| tree | 023d45974945a347590808e114843d2100cfc66e /py | |
| parent | 57c2c4134c52405b78e8d9cd8ed0ed05fefc2827 (diff) | |
UART changes: timeout in secs, write bytes, etc.
Diffstat (limited to 'py')
| -rw-r--r-- | py/stream.c | 6 | ||||
| -rw-r--r-- | py/stream.h | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/py/stream.c b/py/stream.c index 8cf375b16..aca9b8460 100644 --- a/py/stream.c +++ b/py/stream.c @@ -250,6 +250,9 @@ void mp_stream_write_adaptor(void *self, const char *buf, size_t len) { STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); + if (!mp_get_stream(args[0])->is_text && MP_OBJ_IS_STR(args[1])) { + mp_raise_ValueError(translate("string not supported; use bytes or bytearray")); + } size_t max_len = (size_t)-1; size_t off = 0; if (n_args == 3) { @@ -282,6 +285,9 @@ STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { // https://docs.python.org/3/library/socket.html#socket.socket.recv_into mp_uint_t len = bufinfo.len; if (n_args > 2) { + if (mp_get_stream(args[0])->pyserial_compatibility) { + mp_raise_ValueError(translate("length argument not allowed for this type")); + } len = mp_obj_get_int(args[2]); if (len > bufinfo.len) { len = bufinfo.len; diff --git a/py/stream.h b/py/stream.h index 7b953138c..bcba4f234 100644 --- a/py/stream.h +++ b/py/stream.h @@ -70,6 +70,7 @@ typedef struct _mp_stream_p_t { mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode); mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode); mp_uint_t is_text : 1; // default is bytes, set this for text stream + bool pyserial_compatibility: 1; // adjust API to match pyserial more closely } mp_stream_p_t; MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj); |
