{"action":"created","issue":{"url":"https://api.github.com/repos/pyserial/pyserial/issues/196","repository_url":"https://api.github.com/repos/pyserial/pyserial","labels_url":"https://api.github.com/repos/pyserial/pyserial/issues/196/labels{/name}","comments_url":"https://api.github.com/repos/pyserial/pyserial/issues/196/comments","events_url":"https://api.github.com/repos/pyserial/pyserial/issues/196/events","html_url":"https://github.com/pyserial/pyserial/issues/196","id":200354169,"number":196,"title":"termios.error: (22, 'Invalid argument') with PARITY_ODD/PARITY_EVEN","user":{"login":"girst","id":11820748,"avatar_url":"https://avatars0.githubusercontent.com/u/11820748?v=4","gravatar_id":"","url":"https://api.github.com/users/girst","html_url":"https://github.com/girst","followers_url":"https://api.github.com/users/girst/followers","following_url":"https://api.github.com/users/girst/following{/other_user}","gists_url":"https://api.github.com/users/girst/gists{/gist_id}","starred_url":"https://api.github.com/users/girst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/girst/subscriptions","organizations_url":"https://api.github.com/users/girst/orgs","repos_url":"https://api.github.com/users/girst/repos","events_url":"https://api.github.com/users/girst/events{/privacy}","received_events_url":"https://api.github.com/users/girst/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-01-12T12:25:42Z","updated_at":"2017-08-18T13:26:34Z","closed_at":null,"body":"Consider this example (sending AT command to UMTS modem):\r\n\r\n```\r\nimport time\r\nimport serial\r\n\r\nser = serial.Serial(\r\n    port='/dev/ttyUSB1',\r\n    baudrate=9600,\r\n    stopbits=serial.STOPBITS_TWO,\r\n    bytesize=serial.EIGHTBITS,\r\n    parity=serial.PARITY_ODD\r\n)\r\n\r\nser.isOpen()\r\n\r\nser.write (\"AT^SYSINFOEX\\r\".encode ())\r\ntime.sleep (.4)\r\nprint (ser.read (ser.inWaiting()))\r\nser.close ()\r\n```\r\n\r\nWhen `parity=serial.PARITY_ODD` is set, the program throws this exception:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 9, in <module>\r\n    parity=serial.PARITY_ODD\r\n  File \"/usr/lib/python3.5/site-packages/serial/serialutil.py\", line 182, in __init__\r\n    self.open()\r\n  File \"/usr/lib/python3.5/site-packages/serial/serialposix.py\", line 251, in open\r\n    self._reconfigure_port(force_update=True)\r\n  File \"/usr/lib/python3.5/site-packages/serial/serialposix.py\", line 404, in _reconfigure_port\r\n    [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])\r\ntermios.error: (22, 'Invalid argument')\r\n```\r\n\r\nSetting `parity=` to `PARITY_NONE`, the exception doesn't throw. `PARITY_EVEN` also throws the exception. \r\n\r\nSystem: Fedora 25, tested both the repository version, as well as the pip version for python2 and python3. \r\n\r\nAny help is highly appreciated, thanks!"},"comment":{"url":"https://api.github.com/repos/pyserial/pyserial/issues/comments/323352979","html_url":"https://github.com/pyserial/pyserial/issues/196#issuecomment-323352979","issue_url":"https://api.github.com/repos/pyserial/pyserial/issues/196","id":323352979,"user":{"login":"SillyFreak","id":1029192,"avatar_url":"https://avatars2.githubusercontent.com/u/1029192?v=4","gravatar_id":"","url":"https://api.github.com/users/SillyFreak","html_url":"https://github.com/SillyFreak","followers_url":"https://api.github.com/users/SillyFreak/followers","following_url":"https://api.github.com/users/SillyFreak/following{/other_user}","gists_url":"https://api.github.com/users/SillyFreak/gists{/gist_id}","starred_url":"https://api.github.com/users/SillyFreak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SillyFreak/subscriptions","organizations_url":"https://api.github.com/users/SillyFreak/orgs","repos_url":"https://api.github.com/users/SillyFreak/repos","events_url":"https://api.github.com/users/SillyFreak/events{/privacy}","received_events_url":"https://api.github.com/users/SillyFreak/received_events","type":"User","site_admin":false},"created_at":"2017-08-18T13:26:34Z","updated_at":"2017-08-18T13:26:34Z","body":"It seems I have a related problem. I'm running Raspbian on a Raspberry Pi 3 Model B v1.2 and Python 3.5.3; pyserial 3.4 is installed in a virtual environment the following is my test code (RX & TX are connected):\r\n\r\n```\r\nimport serial\r\n\r\nSERIAL_PARAMS = dict(\r\n    baudrate=115200,\r\n    bytesize=serial.EIGHTBITS,\r\n    parity=serial.PARITY_EVEN,\r\n    stopbits=serial.STOPBITS_ONE,\r\n    timeout=1,\r\n    xonxoff=False,\r\n    rtscts=False,\r\n    writeTimeout=None,\r\n    dsrdtr=False,\r\n    interCharTimeout=None,\r\n)\r\n\r\ns = serial.Serial('/dev/ttyS0', **SERIAL_PARAMS)\r\ns.write(b'hello')\r\nprint(s.read(5))\r\ns.close()\r\n```\r\n\r\nUsing PARITY_NONE works consistently, but EVEN and ODD only work _once_, then OP's error occurs until I reboot.\r\n\r\nI have tried picocom (`picocom -b 115200 -p ... /dev/ttyS0`) as well to check whether it's a pyserial problem, the behavior seems to be consistently this:\r\n\r\n- using any parity in picocom works; I can quit and restart it, use different parities\r\n- using pyserial without parity works\r\n- after using pyserial at least once (regardless of parity), any further attempt to use parity causes an error\r\n  - for pyserial, `termios.error: (22, 'Invalid argument')`\r\n  - for picocom, `FATAL: failed to config device /dev/ttyS0: Cannot set the device attributes: Invalid argument`\r\n- not using parity continues to work with both pyserial and picocom"}}
{"actor":{"display_login":"SillyFreak"}}