va3su
Posts: 5
Joined: Tue Jun 21, 2016 6:41 pm

Serial port issue

Tue Jun 21, 2016 6:53 pm

I have a simple serial port program that works perfectly when I run it from a remote serial login from my pc (putty). (not Ethernet). The pc is connected via a ftdi serial to 3.3V usb adapter. All good. But the problem is when I run the same program from the Python Shell running in the Dabian gui, the Python shell gives me an error:

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "/home/pi/my_python/my.py", line 7, in <module>
rcv = port.read(1)
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 460, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
>>>

Thanks for any help.

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Serial port issue

Wed Jun 22, 2016 9:32 am

does is make any difference if you open the terminal as su?
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

va3su
Posts: 5
Joined: Tue Jun 21, 2016 6:41 pm

Re: Serial port issue

Fri Jun 24, 2016 3:57 pm

Below is a simple program that "works" under certain conditions on a RPi3. The Pi3 has updated Debian so all the initial Pi3 serial port issues have been cleared up. First of all it works perfectly when I launch the python code from a Putty serial connection from my pc( using a serial to usb adapter) . This is ok but for the final application I will not be able to launch the program from the serial connection, I want to do it from a hdmi touch screen that I have. I also need to see the serial comms on the screen. I feel that the port command is the problem but don't know how to fix it.

Also... how do I setup up a exit program command? The amount of misinformation on this topic is epic.

Regards,
Kevin

import serial

port = serial.Serial("/dev/serial0", baudrate=115200, timeout=1.0)

while True:
rcv = port.read(1)
port.write(rcv)
if (rcv == "a"):
port.write("aaa")
if (rcv == "b"):
port.write("bbb")
if (rcv == "c"):
port.write("ccc")
if (rcv == "x"):
break

va3su
Posts: 5
Joined: Tue Jun 21, 2016 6:41 pm

Re: Serial port issue

Fri Jun 24, 2016 3:59 pm

... the tabs are correct in my code... the forum seams to hate white space.

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Serial port issue

Fri Jun 24, 2016 5:14 pm

The forum expects you to put in some effort first (Hint: Use Code tags):

viewtopic.php?f=32&t=84477
Account Inactive

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Serial port issue

Sat Jun 25, 2016 8:32 am

SonOfAMotherlessGoat wrote:The forum expects you to put in some effort first (Hint: Use Code tags):

viewtopic.php?f=32&t=84477
Except that post doesn't explain the markup needed to activate "code tags".

If code-tags == "not used":
print "not formatted"
else:
print "formatted nicely"

Wrapped in [code]If code-tags == "not used":
print "not formatted"
else:
print "formatted nicely"[/code] tags it becomes

Code: Select all

If code-tags == "not used":
  print "not formatted"
else:
  print "formatted nicely"
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

va3su
Posts: 5
Joined: Tue Jun 21, 2016 6:41 pm

Re: Serial port issue

Sun Jun 26, 2016 1:11 pm

Well, here's my bit of python and I seam to have sorted the formatting for this forum... Original problem remains however.

Code: Select all

import serial



port = serial.Serial("/dev/serial0", baudrate=115200, timeout=1.0)

while True:
   # port.write("\r\nSay something:")
	rcv = port.read(1)
	port.write(rcv)
	if (rcv == "a"):
		port.write("aaa")
	if (rcv == "b"):
		port.write("bbb")
	if (rcv == "c"):
		port.write("ccc")
	if (rcv == "x"):
		break

quit

Return to “Python”