Re: [Tutor] question about serial coms
The device at the far end of the serial connection is echoing what you write back to you. This is a convenience for someone typing at a terminal, but a nuisance when you are programming. The easier way out is to turn echoing off at the far device. Failing that, you will want to provide a copy of your output to the read routine so that it can filter your output out of the data stream coming back to you. Unfortunately there is no reliable error detection on a serial line, so line errors can complicate the task of matching the echoes to your output. On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote: I have been working with pyserial. One question I have is this. I have a loop that writes to the serial port and then waits about 500ms and then reads from the serial port. The first thing read from the serial port is ALWAYS the data written to the serial port... I must be missing something obvious, but I thuoght the two buffers were separate... (snipped) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Yeah, i am using pyserial, i think, in debian its called python serial and i use import serial to get things going. Really easy, just wanted to know about this stuff before i start scrambling this like so many eggs. i will not be using two different scripts, but likely two threads in the same script. not sure i really get what select() is all about great link by the way, thanks. shawn On Mon, 2005-11-14 at 12:35 -0600, Hugo González Monteverde wrote: Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
ok, i think i got it. Thanks so much. let you know how it turns out. shawn On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
I have been working with pyserial. One question I have is this. I have a loop that writes to the serial port and then waits about 500ms and then reads from the serial port. The first thing read from the serial port is ALWAYS the data written to the serial port... I must be missing something obvious, but I thuoght the two buffers were separate... Here is the code I'm using if that helps: while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == : i = 1 break else: ser.write(line + \r) #ser.write(\r\n) print Sending: + line time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) print Closing Serial Port\n ser.close() -Joe --- nephish [EMAIL PROTECTED] wrote: ok, i think i got it. Thanks so much. let you know how it turns out. shawn On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] question about serial coms
oh yeah, i will need this too! sk On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote: I have been working with pyserial. One question I have is this. I have a loop that writes to the serial port and then waits about 500ms and then reads from the serial port. The first thing read from the serial port is ALWAYS the data written to the serial port... I must be missing something obvious, but I thuoght the two buffers were separate... Here is the code I'm using if that helps: while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == : i = 1 break else: ser.write(line + \r) #ser.write(\r\n) print Sending: + line time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) print Closing Serial Port\n ser.close() -Joe --- nephish [EMAIL PROTECTED] wrote: ok, i think i got it. Thanks so much. let you know how it turns out. shawn On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script that is reading from it. I guess my question is, do i have to interrupt the reading script to write to the same RS232 device ? and if so, how do i do that? thanks, shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist
Re: [Tutor] question about serial coms
Just to make sure that I understood it right, Does this snippet mimic the problem that you have? Ive hardcoded line. x= import serial import time ser=serial.Serial(0,57600,timeout=0.1) i=0 line = [Hi,There,Hans] while i = (len(line)-1): ser.write(line[i] + \r) print Sending: + line[i] time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) i = i + 1 print Closing Serial Port\n ser.close() =x= Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 2:10 p.m. To: [EMAIL PROTECTED] Cc: Hans Dushanthakumar; tutor Subject: Re: [Tutor] question about serial coms oh yeah, i will need this too! sk On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote: I have been working with pyserial. One question I have is this. I have a loop that writes to the serial port and then waits about 500ms and then reads from the serial port. The first thing read from the serial port is ALWAYS the data written to the serial port... I must be missing something obvious, but I thuoght the two buffers were separate... Here is the code I'm using if that helps: while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == : i = 1 break else: ser.write(line + \r) #ser.write(\r\n) print Sending: + line time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) print Closing Serial Port\n ser.close() -Joe --- nephish [EMAIL PROTECTED] wrote: ok, i think i got it. Thanks so much. let you know how it turns out. shawn On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote: Lock() is provided by the threading module. see http://docs.python.org/lib/module-threading.html http://docs.python.org/lib/lock-objects.html Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 11:23 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms ok, lock is something you wrote yourself ? i can't find it in the docs. However, i think i can essentially build the same thing. the serial module i use is pyserial. pyserial.sourceforge.net. the docs are a wee bit on the sparce side. But i think i can pull it off. Thanks for your help. shawn On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote: I believe that the drivers take care of that, however, I did use locks to make sure that there were no conflicts. In the listener thread I had something along the lines of: Acquire lock readline() from the ser port Release lock And in the sender thread, Acquire lock send msg over ser port Release lock Cheers Hans -Original Message- From: nephish [mailto:[EMAIL PROTECTED] Sent: Tuesday, 15 November 2005 10:47 a.m. To: Hans Dushanthakumar Cc: Hugo González Monteverde; tutor Subject: RE: [Tutor] question about serial coms well thats encouraging, did you have to do anything special to prevent an error when trying to read or write at the same time ? thanks sk On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote: Ive worked on a similar application. I used one thread to read from the serial port and another one to handle the writes. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González Monteverde Sent: Tuesday, 15 November 2005 7:36 a.m. To: nephish Cc: tutor Subject: Re: [Tutor] question about serial coms Hi Nephish, Are you using pyserial or rolling your own? Normally you can write and read to the /dev/ttySXX file at the same time; since they're special files, not ordinary files, the driver handles that. Handling both writing and reading in your program's flow control is a wholly different matter, though. You might need to use select() to avoid blocking. Are you using two completely different scripts for reding and writing? There is some valuable info, if not about python, in the Serial Programming howto, at: http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/ Hugo nephish wrote: Hey there, i am developing on a linux computer with the serial module. Now, i already am able to recieve info from a serial RS232 device and process everything ok. What i need to do now is write to the serial device, but i also need to be able to not interrupt the script
Re: [Tutor] question about serial coms
I think so, what I'm doing is opening a text file, reading line 1 and writing that text to the serial port. Then read line 2 and so on... So it mimics a string rather than a list or dictionary. But I would think this would give you a similiar result. I can try it to confirm. Here is the entire code: import serial import string import time parmfile = open('command_1.txt') ser = serial.Serial('/dev/ttyS1', 9600, timeout=1) ser.setRTS(1) ser.setDTR(1) i = 0 while i == 0: line = parmfile.readline() line = string.rstrip(line) #print line if line == : i = 1 break else: ser.write(line + \r) #ser.write(\r\n) print Sending: + line time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) print Closing Serial Port\n ser.close() The 'command_1.txt' file is literally a text file with lines of text like such: command1 on command2 off command3 %4 command5 on etc -Joe --- Hans Dushanthakumar [EMAIL PROTECTED] wrote: Just to make sure that I understood it right, Does this snippet mimic the problem that you have? Ive hardcoded line. x= import serial import time ser=serial.Serial(0,57600,timeout=0.1) i=0 line = [Hi,There,Hans] while i = (len(line)-1): ser.write(line[i] + \r) print Sending: + line[i] time.sleep(1) data_in = ser.read(100) print Response: + data_in time.sleep(.2) i = i + 1 print Closing Serial Port\n ser.close() =x= Cheers Hans ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor