Best Regards
Luca
best regards-
Just
Luca
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(port, baudrate) # Open the port
for i in range(100):
s.flushInput()
line= s.readline()
print line
Many Thanks
Best Regards
Luca
Try swapping pins 2 and 3 in the lead.
--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick
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
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
Sorry missed that bit!
Pyserial works very well in my experience (under linux).
Serial ports are generally a pain though ;-)
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.EIGHTBITS
parity =serial.PARITY_ODD
stopbits =serial.STOPBITS_TWO
timeout = 1
ser = serial.Serial(2, baudrate=38400, bytesize=8,
parity=serial.PARITY_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.SetValue(ct)
ser.readline()
Pls.Note i hove also try with read(number of byte ) with inWaiting(),
flush etc........
But no result.
Thanks Luca
>> 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).
I've used it extensively under both Linux and Win32, and it
works very well under both.
> Serial ports are generally a pain though ;-)
That's the truth.
--
Grant Edwards grante Yow! Somewhere in Tenafly,
at New Jersey, a chiropractor
visi.com is viewing "Leave it to
Beaver"!
import serial
s = serial.Serial(port=2,baudrate=38400, timeout=20)
while 1:
print s.readline()
Petr Jakes
Is port = 2 correct?
I thought that com ports under windows are designated as a string
"com1","com2",..etc.
You might want to try using ser.read() instead of ser.readline() as
you may not be getting linefeed carrage return characters . I usually
setup a buffer to scan for the characters I expect.
>
>
>
> Pls.Note i hove also try with read(number of byte ) with inWaiting(),
> flush etc........
>
>
> But no result.
>
> Thanks Luca
Hope this helps
Sam Schulenburg
Read the fine documentation at http://pyserial.sourceforge.net/:
Parameters for the Serial class
ser = serial.Serial(
port=None, #number of device, numbering starts at
#zero. if everything fails, the user
#can specify a device string, note
#that this isn't portable anymore
#if no port is specified an unconfigured
#an closed serial port object is created
baudrate=9600, #baudrate
bytesize=EIGHTBITS, #number of databits
parity=PARITY_NONE, #enable parity checking
stopbits=STOPBITS_ONE, #number of stopbits
timeout=None, #set a timeout value, None for waiting forever
xonxoff=0, #enable software flow control
rtscts=0, #enable RTS/CTS flow control
)
> I thought that com ports under windows are designated as a string
> "com1","com2",..etc.
You can use those as well, but they're non-portable.
serial.Serial(port=0) will open the first serial port on either
windows or linux.
--
Grant Edwards grante Yow! Ha ha Ha ha Ha ha
at Ha Ha Ha Ha -- When will I
visi.com EVER stop HAVING FUN?!!
Sam
I see the read data with a sniffer.
with the same serial caracteristic in delphi i obtain the right answer.
I use serial writestr and serial readstr.
If the serial package is anything like regular file I/O, that
line will buffer/block until a new-line character is received, then
return data upto/including the new-line. If the inbound data has
multiple lines, you need individual readlines.
For example i i send D0360000EC the right answer is
D0360000EC0000FFBC35DC44 etc...
i need new Line?
why if i use ser.read(10) i see only the first 5 byte and not the rest,
why if i use the inwaigth i answer that i have only 5 byte to read.
Regards
Luca
By the way, for future reference, this way beats the above hands down:
>>> import binascii
>>> binascii.unhexlify("D0360000EC")
'\xd06\x00\x00\xec'
-Peter
i how can set with pyserial the following data?
> byte delay= 40000
> serial control line:
> dtr = high
> rts= low
Thanks Luca