473,699 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyserial - send and receive characters through linux serial port

Hi,

I am trying to send a character to '/dev/ttyS0' and expect the same
character and upon receipt I want to send another character. I tired
with Pyserial but in vain.

Test Set up:

1. Send '%' to serial port and make sure it reached the serial port.
2. Once confirmed, send another character.

I tried with write and read methods in Pyserial but no luck.

Can you help?

Thanking you all.
T
Jun 27 '08 #1
6 6662
En Fri, 25 Apr 2008 20:22:37 -0300, terry <it*********@gm ail.comescribió :
I am trying to send a character to '/dev/ttyS0' and expect the same
character and upon receipt I want to send another character. I tired
with Pyserial but in vain.
I assume you have a device attached to /dev/ttyS0 that echoes back the
received characters?
Test Set up:

1. Send '%' to serial port and make sure it reached the serial port.
2. Once confirmed, send another character.

I tried with write and read methods in Pyserial but no luck.
Check the communication parameters (baud rate, parity, etc.), cable,
connectors, your device... AFAIK a lot of people is using pyserial so I'd
look the problem elsewhere. Try posting a short code example showing your
problem.

--
Gabriel Genellina

Jun 27 '08 #2
terry wrote:
I am trying to send a character to '/dev/ttyS0' and expect the
same character and upon receipt I want to send another character.
I tired with Pyserial but in vain.
Pyserial works very well for me (despite the device I connect to has
quite a screwed protocol and implementation) .
Test Set up:

1. Send '%' to serial port and make sure it reached the serial
port. 2. Once confirmed, send another character.

I tried with write and read methods in Pyserial but no luck.
Are you actaully trying to get lucky by doing this, or are you
observing a specific problem, e.g. nothing is received or wrong
characters are received? Also, by what are they received?

Regards,
Björn

--
BOFH excuse #139:

UBNC (user brain not connected)

Jun 27 '08 #3
On 2008-04-25, terry <it*********@gm ail.comwrote:
I am trying to send a character to '/dev/ttyS0' and expect the
same character and upon receipt I want to send another
character. I tired with Pyserial but in vain.
Pyserial works. I've been using it almost daily for many
years. Either your program is broken, your serial port is
broken, or the device connected to the serial port is broken.
Test Set up:

1. Send '%' to serial port and make sure it reached the serial port.
2. Once confirmed, send another character.

I tried with write and read methods in Pyserial but no luck.

Can you help?
Ah yes, the problem is in line 89 of your program.



We've no way to help if you don't provide details. If you
really want help, write as small a program as possible that
exhibits the problem. I'd like to emphasize _small_. The
larger the program the less likely people are to look at it,
and the less likely they are to find the problem if they do
look at it.

Much of the time the exercise of writing a small demo program
will lead you to the answer. If not, then post it, along with
the output from the program that shows the problem.

Then we can tell you what you did wrong.

--
Grant Edwards grante Yow! I'm also against
at BODY-SURFING!!
visi.com
Jun 27 '08 #4
On Apr 26, 8:21*am, Grant Edwards <gra...@visi.co mwrote:
On 2008-04-25, terry <itskrith...@gm ail.comwrote:
I am trying to send a character to '/dev/ttyS0' and expect the
same character and upon receipt I want to send another
character. I tired withPyserialbut in vain.

Pyserialworks. *I've been using it almost daily for many
years. *Either your program is broken, your serial port is
broken, or the device connected to the serial port is broken.
Test Set up:
1. Send '%' to serial port and make sure it reached the serial port.
2. Once confirmed, send another character.
I tried with write and read methods inPyserialbut no luck.
Can you help?

Ah yes, the problem is in line 89 of your program.

We've no way to help if you don't provide details. If you
really want help, write as small a program as possible that
exhibits the problem. *I'd like to emphasize _small_. The
larger the program the less likely people are to look at it,
and the less likely they are to find the problem if they do
look at it.

Much of the time the exercise of writing a small demo program
will lead you to the answer. *If not, then post it, along with
the output from the program that shows the problem.

Then we can tell you what you did wrong.

--
Grant Edwards * * * * * * * * * grante * * * * * * Yow! I'm also against
* * * * * * * * * * * * * * * * * at ** * * * * * BODY-SURFING!!
* * * * * * * * * * * * * * * *visi.com * * * * * *
Here is the code.

"""Open serial connection"""
def openSerialConne ction(self,serp t):
try:
s1 = serial.Serial(s erpt,timeout=10 )

except:
self.print_u("F ailed to open serial port %s. " %serpt)

def enterThroughSer ialPort(self,se rpt):
s1 = serial.Serial(s erpt,timeout=10 )
self.print_u('S ending !!!!..')
while True:
s1.write('*')
c = s1.read(1)
if c:
self.print_u('F ound "*" ')
break
print c
s1.write('enter \r')
s1.read('login' )

if __name__ == '__main__':
serpt = '/dev/ttyS0'
x.openSerialCon nection(serpt)
# funtion to reboot the device goes here ---#
x.enterThroughS erialPort(serpt )

After opening the serial connection, the device is rebooted followed
by sending '*' to serial port and reading back the same. I seem to
have problem while trying to read '*' back from serial port. First of
all I am not sure if serial port received the '*'.

Thanks!
Jun 27 '08 #5
On May 2, 10:26*am, terry <itskrith...@gm ail.comwrote:
On Apr 26, 8:21*am, Grant Edwards <gra...@visi.co mwrote:


On 2008-04-25, terry <itskrith...@gm ail.comwrote:
I am trying to send a character to '/dev/ttyS0' and expect the
same character and upon receipt I want to send another
character. I tired withPyserialbut in vain.
Pyserialworks. *I've been using it almost daily for many
years. *Either your program is broken, your serial port is
broken, or the device connected to the serial port is broken.
Test Set up:
1. Send '%' to serial port and make sure it reached the serial port.
2. Once confirmed, send another character.
I tried with write and read methods inPyserialbut no luck.
Can you help?
Ah yes, the problem is in line 89 of your program.
We've no way to help if you don't provide details. If you
really want help, write as small a program as possible that
exhibits the problem. *I'd like to emphasize _small_. The
larger the program the less likely people are to look at it,
and the less likely they are to find the problem if they do
look at it.
Much of the time the exercise of writing a small demo program
will lead you to the answer. *If not, then post it, along with
the output from the program that shows the problem.
Then we can tell you what you did wrong.
--
Grant Edwards * * * * * * * * * grante * * * ** * Yow! I'm also against
* * * * * * * * * * * * * * * * * at * * * * * * * BODY-SURFING!!
* * * * * * * * * * * * * * * *visi.com * * * * * *

Here is the code.

"""Open serial connection"""
* * * * def openSerialConne ction(self,serp t):
* * * * * * try:
* * * * * * * * s1 = serial.Serial(s erpt,timeout=10 )

* * * * * * except:
* * * * * * * * self.print_u("F ailed to open serial port %s. " %serpt)

* * * * def enterThroughSer ialPort(self,se rpt):
* * * * * * s1 = serial.Serial(s erpt,timeout=10 )
* * * * * * *self.print_u(' Sending !!!!..')
* * * * * * *while True:
* * * * * * * * s1.write('*')
* * * * * * * *c = s1.read(1)
* * * * * * * *if c:
* * * * * * * * * self.print_u('F ound "*" ')
* * * * * * * * * * break
* * * * * * print c
* * * * * * *s1.write('ente r\r')
* * * * * * *s1.read('login ')

if __name__ == '__main__':
* * serpt = '/dev/ttyS0'
* * x.openSerialCon nection(serpt)
* * # funtion to reboot the device goes here ---#
* * x.enterThroughS erialPort(serpt )

After opening the serial connection, the device is rebooted followed
by sending '*' to serial port and reading back the same. I seem to
have problem while trying to read '*' back from serial port. First of
all I am not sure if serial port received the '*'.

Thanks!- Hide quoted text -

- Show quoted text -
This is the err message I received:

c = s1.read(1)
File "/usr/local/lib/python2.5/site-packages/serial/serialposix.py" ,
line 275, in read
ready,_,_ = select.select([self.fd],[],[], self._timeout)
Jun 27 '08 #6
En Fri, 02 May 2008 15:44:09 -0300, terry <it*********@gm ail.comescribió :
On May 2, 10:26*am, terry <itskrith...@gm ail.comwrote:
>On Apr 26, 8:21*am, Grant Edwards <gra...@visi.co mwrote:
Much of the time the exercise of writing a small demo program
will lead you to the answer. *If not, then post it, along with
the output from the program that shows the problem.

Here is the code.

"""Open serial connection"""
* * * * def openSerialConne ction(self,serp t):
* * * * * * try:
* * * * * * * * s1 = serial.Serial(s erpt,timeout=10 )

* * * * * * except:
* * * * * * * * self.print_u("F ailed to open serial port %s. " %serpt)

* * * * def enterThroughSer ialPort(self,se rpt):
* * * * * * s1 = serial.Serial(s erpt,timeout=10 )
* * * * * * *self.print_u(' Sending !!!!..')
* * * * * * *while True:
* * * * * * * * s1.write('*')
* * * * * * * *c = s1.read(1)
* * * * * * * *if c:
* * * * * * * * * self.print_u('F ound "*" ')
* * * * * * * * * * break
* * * * * * print c
* * * * * * *s1.write('ente r\r')
* * * * * * *s1.read('login ')

if __name__ == '__main__':
* * serpt = '/dev/ttyS0'
* * x.openSerialCon nection(serpt)
* * # funtion to reboot the device goes here ---#
* * x.enterThroughS erialPort(serpt )

After opening the serial connection, the device is rebooted followed
by sending '*' to serial port and reading back the same. I seem to
have problem while trying to read '*' back from serial port. First of
all I am not sure if serial port received the '*'.

This is the err message I received:

c = s1.read(1)
File "/usr/local/lib/python2.5/site-packages/serial/serialposix.py" ,
line 275, in read
ready,_,_ = select.select([self.fd],[],[], self._timeout)
If you want some help, you have to help us to diagnose the problem.
The above lines are just a small excerpt of the complete error report that
surely you got; usually it includes the exception *type*, the exception
*value*, and the whole *stack trace*. Now we have to *guess* what happened
in that select call.
Also, when posting code, try to post the *actual* code you run - copy and
paste it. Do not retype it again. The code you posted has indentation
errors, uninitialized variables...
Try to make a *small*, runnable example that reproduces the problem;
remove anything that isn't esential to the issue being discussed. Write
down what is your expected behaviour, and what actually happens. If the
program halts due to an error, copy the *whole* report including the
exception type, message, and the complete traceback.

In this particular case, due to the serial device, it's improbable that
someone will be able to execute your program, but anyway try to write the
example code. Sometimes you may find the problem yourself just by trying
to write the example.

A few notes on the code:

- don't create many Serial objects; create only a single instance and use
it everywhere it is needed. (That is, instead of using '/dev/ttyS0' as an
argument, pass the Serial object already created, or save it as an
instance attribute: self.serial = Serial(...) )

- ensure you're using the right protocol parameters (baud rate, bits,
parity...) for the device. That's why it helps to create the Serial object
in a single place.

--
Gabriel Genellina

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
11026
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip creates a "normal" comm port (like COM3). There is a C++ program that has no problem talking to the equipment, but two Python programs have trouble. One is a big, scary, controller program, and the other, since that is the one I'm having trouble...
6
17691
by: googlinggoogler | last post by:
Hiya, I've got a PIC microcontroller reading me humidity data via rs232, this is in ASCII format. I can view this data easily using hyperterminal or pyserial and convert it to its value (relative humidty with ord(input)) But what im trying to do is plot the data in real time, ideally with pylab - as it looks simple to use and simple is the way i want to go! My code is below, it doesnt show a graph, I was wondering whether
17
7918
by: luca72 | last post by:
Hello at all sorry for my english but i'm Italian. I use pyserial to communicate via rs232 with an extarnal device called smartmouse. I write the exact line that i want , but when i read i read only the echo ond not the other bytes. When i meke the same project with delphi i solve this problem with the call of the sleep. But in python it don't work. Have you got some ideas for solve my problem?
8
9167
by: Alejandro | last post by:
Hi: I'm using pySerial to talk to a RS232 to RS485 converter. In order to control the converter, I need to control the DTR line to enable/disable de RS485 driver. In particular, I need to : write a character to the serial port set the DTR line to level 1 _after_ the last bit of the character is send
7
4865
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the DS1615 docs, writing to the chip is performed one byte at a time. To read from the chip, one must issue the "read page" command (33h), followed by the two-byte address of the requested page (pages are 32 bytes long). After receiving this, the...
0
2075
by: [david] | last post by:
http://pyserial.sourceforge.net/ "port numbering starts at zero, no need to know the port name in the user program" But the implementation in SerialWin32 is just (Portnum +1)
3
11611
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to be working fine when I test it with Hyperterminal . I am using the example program that comes with pyserial, as below. --------------- import serial
0
1920
by: Kineta | last post by:
Hello all, I am attempting to send commands to the firmware on my PIC18F4550 (usb port) microcontroller using Pyserial. If I open Hyperterminal, I can send the following commands and it works beautifully: set_dac(0,1500,0) report_smu Then I went to Python with Pyserial, and nothing happens. I get no errors, but at the same time the board does not respond to the input, and python prints no output. Here is my code:
1
4291
by: rfarley | last post by:
Hi, I am using the pyserial module and am trying to read the serial port from an accelerometer (LIS302DL). It has an option in which you write "*debug\r\n" and then you read the data (three axes output) from the output. I use hyperterminal with the below settings and it works fine: baudrate=115200 databits=8
0
8703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4389
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.