But there are ways to simulate multithreading at the software level, and python does this.) A multi-threaded solution to your problem can get complex. That is true for most arduinos at the hardware level. Another answer here indicated that arduinos do not support multithreading. Multithreaded programming with python is possible on most arduinos. In that case, your options are either multi-threading or doing writing/reading sequentially without the reads blocking your program indefinitely.
If the serial device you are working with is such that you can write at any time and you can independently expect to receive something from the device at any time, then you are working with a full duplex serial device. However, you shouldn't be closing and reopening the serial port. This is sometimes referred to as half-duplex and this is what your current program example is doing. For example, you send a command (write), and then expect a response (read). Most simpler two-way serial devices will only respond after receiving a command. Separately, to make use of full-duplex communications, your serial library and program itself must be written to support full-duplex. True full-duplex serial communications requires hardware level support. It can be confusing because people tend to mix the meanings of full-duplex/half-duplex when switching back-and-forth in discussion of the hardware and software layers.
Twisted - Uses pySerial to provide an asynchronous serial port transport which can be used like any other stream-oriented transport (eg TCP, SSL).īluetooth connections can also be handled using the socket module, provided that support for Bluetooth is present in the underlying operating system and has been compiled into the Python distribution being used.It's not entirely clear what you mean by "write and read at the same time" because that can refer to different contexts. Jaraco.nxt - a package implementing low-level API communication with the LEGO Mindstorms NXT robot kit.
T616hack - a distribution providing access to the contacts, phonebook and messages on the Sony Ericsson T610/T616 and compatible mobile telephones
RFIDIOt - an open source python library for exploring RFID devices (see also "RFID enabled e-passport skimming proof of concept code released (RFIDIOt)" and "Code highlights e-passport eavesdropping risk") It also supports remote serial ports via RFC 2217 (since V2.5).īitPim - crossplatform application to view and manipulate data on CDMA phones from LG, Samsung, Sanyo and other manufacturers. PySerial is a library which provides support for serial connections ("RS-232") over a variety of different devices: old-style serial ports, Bluetooth dongles, infra-red ports, and so on.