473,581 Members | 3,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyserial never read

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?

Best Regards

Luca

Feb 16 '06 #1
17 7907
I don't know alot about python but I could help you with english?
eventhough it was really good

best regards-
Just

Feb 17 '06 #2
Thanks

Luca

Feb 17 '06 #3
Hello,

I'm not sure I understand precisely your question but maybe you can try
a readline and a flushinput like that:

import serial

port= 0 # or the port where you're device is connected
baudrate=9600 # or the baudrate of your device

s = serial.Serial(p ort, baudrate) # Open the port

for i in range(100):
s.flushInput()
line= s.readline()
print line

Feb 17 '06 #4
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.

Many Thanks

Best Regards

Luca

Feb 18 '06 #5
luca72 <lu*******@libe ro.it> wrote:
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.


Try swapping pins 2 and 3 in the lead.

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Feb 21 '06 #6
Nick Craig-Wood wrote:
luca72 <lu*******@libe ro.it> wrote:
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.


Try swapping pins 2 and 3 in the lead.


Anything's possible, but given that in his original post he says it
works when he uses Delphi, it seems unlikely making a change to the
hardware is necessary.

-Peter

Feb 21 '06 #7
luca72 wrote:
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.


If you want help, you'll do better to post small pieces of code that you
are actually using, rather than making us guess or imagine what you are
doing. There are perhaps a dozen things that can go wrong with serial
communications, and it's not efficient for us to start suggesting them
one at a time...

-Peter

Feb 21 '06 #8
Peter Hansen <pe***@engcorp. com> wrote:
Nick Craig-Wood wrote:
luca72 <lu*******@libe ro.it> wrote:
Thanks for your help, but it don't solve the problem.
I receive only the echo and full stop.


Try swapping pins 2 and 3 in the lead.


Anything's possible, but given that in his original post he says it
works when he uses Delphi, it seems unlikely making a change to the
hardware is necessary.


Sorry missed that bit!

Pyserial works very well in my experience (under linux).

Serial ports are generally a pain though ;-)

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Feb 22 '06 #9

Thanks to all for the help,

here you find the code, pls note if i use handshaking = 1 the
application don't start.
in the delphi configuratio of com port if i use or not handshaking the
application work.
Best Regards at all

Luca

import serial
import win32file
port = 2
baudrate = 38400
bytesize =serial.EIGHTBI TS
parity =serial.PARITY_ ODD
stopbits =serial.STOPBIT S_TWO
timeout = 1
ser = serial.Serial(2 , baudrate=38400, bytesize=8,
parity=serial.P ARITY_ODD, stopbits=2, timeout=3)
ct = ''
ch = ''
a = self.textCtrl1. GetValue()
ind = 0
ind1 = 2
lunghezza = len(a)
while ind < lunghezza :
b = a[ind:ind1]
b = int(b,16)
b = ~b
c = ''.join([str((b >> Digit) & 1) for Digit in range(7,
-1, -1)])
c1 = c[0:4]
c2 = c[4:]
c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1]
c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1]
c1 = hex(int(c1,2))
c2 = hex(int(c2,2))
c1 = c1[2:]
c2 = c2[2:]
c = c2+c1
ct = ct + c
ind = ind + 2
ind1 = ind1 + 2
c = int(c,16)
c = chr(c)
ch = ch + c
ser.write(ch)

elf.textCtrl2.S etValue(ct)
ser.readline()

Pls.Note i hove also try with read(number of byte ) with inWaiting(),
flush etc........
But no result.

Thanks Luca

Feb 22 '06 #10

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

Similar topics

13
10999
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. ...
5
9939
by: Mimi | last post by:
Hi, I use the pyserial to read data from a serial port. My code is in window Xp and python 2.4. when I use Hyperteminal I can read data without try and try again that it is not the case with pyserial library. anyone can help me ? this is a part of my code: self.ser = serial.Serial() self.ser.baudrate = 9600
7
4854
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...
2
3734
by: Jon | last post by:
Hi, I wrote some code to read in info from a port using pyserial. the code reads info sent by a box that is connected to my computer by an rs232-to usb adapter. When I was writing the code and testing it on my computer it worked fine. I ran py2exe on the program (which uses wxpython for its gui) and sent the output from the py2exe to...
15
16832
by: Lone Wolf | last post by:
I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated by spaces as follows: M xxx xxx xxx xxx xxx xxx xxx xxx Here is the code I am using (python v24): import serial
3
3204
by: Lone Wolf | last post by:
I want to thank everybody who tried to help me, and also to post my solution, even though I don’t think it is a very good one. Many of you correctly guessed that there was an “\r” included with the packet from the CUMcam, and you were correct. The actual format of the packet is: M xxx xxx xxx xxx xxx xxx xxx xxx\r. Unfortunately,...
0
596
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source and found (to take with care!) :
6
6644
by: terry | last post by:
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.
3
6198
by: Rainy | last post by:
Hello! I'm having some trouble with pyserial package, I'm sending commands and reading responses from a custom pcb, and sometimes I get a proper response, at other times I get nothing, and sometimes I get about half of the response string with beginning cut off. About half the time an empty string is returned, the other ~half time good...
2
4150
by: bryanleo | last post by:
We are trying to read data from a microcontroller and interface it through serial port. The output is then displayed in Python using Pyserial or the hyperterminal, the former is more important When you touch the input pins of the microcontroller the value changes real time in hyper terminal. But In the case of the pyserial module, even though...
0
7886
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...
0
7809
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...
1
7920
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...
0
8183
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...
0
6569
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3809
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...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.