User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

problem with Serial

Wed Sep 23, 2015 7:14 pm

Hi
I want to send and recieve by serial port but in python when I type following code:

import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)

while True:
port.write("\r\nSay something:")
rcv = port.read(10)
port.write("\r\nYou sent:" + repr(rcv))


it has one Syntax error in (baudrate=115200) because of = !!!!!

can you help me??
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: problem with Serial

Wed Sep 23, 2015 7:49 pm

Could you cut&paste the script and put it within

Code: Select all

[/b] [b]
[/b] quotes?

Similarly could you cut&paste the exact error message?

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: problem with Serial

Thu Sep 24, 2015 5:36 am

this is my code:

Code: Select all

import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)

while True:
    port.write("\r\nSay something:")
    rcv = port.read(10)
    port.write("\r\nYou sent:" + repr(rcv))
there is no error message.I have a syntax error
when I run the code, a Syntax error apear,because of = in line : baudrate=115200

Thank you
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
rpdom
Posts: 16087
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: problem with Serial

Thu Sep 24, 2015 5:52 am

I think you don't need to put the "baudrate=" part, just the number.

Code: Select all

port = serial.Serial("/dev/ttyAMA0", 115200, timeout=3.0)

User avatar
joan
Posts: 14668
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: problem with Serial

Thu Sep 24, 2015 6:23 am

Cut&paste the syntax error.

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: problem with Serial

Tue Sep 29, 2015 6:48 am

I change the code and have not syntax error but I have another error
my simple code is:

Code: Select all

import serial
import os

ser=serial.Serial('/dev/ttyAMA0',115200)
ser.write ('Mahan')
and when I run it :

Code: Select all

Traceback (most recent call last):
  File "/home/pi/test.py", line 5, in <module>
    ser.write ('Mahan')
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 471, in write
    n = os.write(self.fd, d)
TypeError: 'str' does not support the buffer interface
I cant use the serial port and I dont know why !!!
If your Dreams Don't Scare You , They Aren't Big Enough

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: problem with Serial

Tue Sep 29, 2015 6:57 am


Return to “Beginners”