Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: [SerialConnection] Help Date: Thu, 9 Apr 2015 16:28:26 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1428596906 28554 67.130.15.94 (9 Apr 2015 16:28:26 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 9 Apr 2015 16:28:26 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:88736 On 2015-04-09, Travis Griggs wrote: > >> On Apr 7, 2015, at 8:42 AM, Hugo Caldas wrote: >> >> read and write the port values with multi threading > > Care to elaborate what you mean by this part? In general, serial > ports and multi threading don’t mix well. IOW, you’ll need to use > multithreading pieces to make sure you serialize your access to your > serial port. One thing that does work well (and is used by lots of apps) is to use one thread for reading and a different thread for writing. If that's what you want to do, then you don't need to add any mutexes or any sort of application-level serialization. At least on Unix, the basic read/write calls should be thread-safe, _but_not_necessarily_atomic_. If two threads call write() "at the same time", all the data will go out, and the order of bytes within each written block will be preserved, but there's no guarantee that the blocks won't get interleaved. If you've got two threads blocking on a read, only one thread will read any particular byte of data, but there's no guarantee which bytes will go to which thread. > As other have pointed out, pyserial is the package you want. > Documentation is pretty good. We use it a lot. -- Grant Edwards grant.b.edwards Yow! Don't hit me!! I'm in at the Twilight Zone!!! gmail.com