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
That equates to COM3 on windows; is that correct?
baudrate = 38400
bytesize =serial.EIGHTBITS
parity =serial.PARITY_ODD
stopbits =serial.STOPBITS_TWO
timeout = 1
Why bother defining all these, since you aren't using them in the
next line... In fact, you set up a three second timeout in the next
line.
ser = serial.Serial(2, baudrate=38400, bytesize=8,
parity=serial.PARITY_ODD, stopbits=2, timeout=3)
If you still want the above defined variables, then you want (the
name on the left of the = is the argument placeholder name, the copy on
the right is your predefined variable name -- using placeholder names
lets you leave things out, or change the order):
ser = serial.Serial(port, baudrate=baudrate, bytesize=bytesize,
parity=parity, stopbits=stopbits,
timeout=timeout)
NOTE: you defined "timeout" as 1, but then did the open with a
timeout of 3.
NOTE: I have never seen a stopbits of 2 used on anything faster than
around 300 baud. The most common setup is 8-bit, no parity, 1 stop bit
("8n1"). If the other end is sending with 1 stop-bit, your end may never
be seeing a "stop". It is always safe to SEND a longer stop than the
other end expects, but not the other way around.
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]
c1 = c1[3] + c1[2] + c1[1] + c1[0]
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
I don't even want to think what that is supposed to be doing -- I
bet it can be done much easier....
Let's see... You are taking in some string; splitting it into
2-character chunks, interpreting those as Hex, 1s-complementing them,
making a string of binary from the result, reversing the bit order,
converting back to hex, then joining them, converting back to integer,
just to generate a character value.
It would be cleaner to just predefine a look-up table.
ser.write(ch)
elf.textCtrl2.SetValue(ct)
ser.readline()
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.
ALSO... YOU NEVER SPECIFY A VARIABLE TO RECEIVE THE DATA -- ANYTHING
YOU DO READ IS BEING DUMPED ON THE FLOOR!
ReceiveData = ser.readline()
--