I have this:
writeBytes([\x01])
If I write a byte in hexadecimal I should receive the same ,but why the response is 127.
Can anyone tell me, please?
Sorry, you’ll need to provide a little more detail about what you’re doing.
Tip: please copy the code from your screen and post it using the </>
code formatting button. That way we can copy and paste and edit it in our answers.
One problem you have is stopBis
. It should be stopBits
.
I am using an interface USB to SR485
The ports, I am using a converter
import time
with system.serial.port(
port = "COM3",
bitrate = system.serial.BIT.RATE_19200,
databits = system.serial.DATA.BITS_8,
handshake = system.HANDSHAKE_NONE,
hardwareFlowControl = False,
parity = system.serial.PARITY_MARK,
stopBits = system.serial.STOP_BITS_1) as portOutAddress:
portOutAddress.writeBytes([\x01])
time.sleep(0.1)
with system.serial.port(
port="COM9",
bitrate = system.serial.BIT.RATE_19200,
databits = system.serial.DATA.BITS_8,
handshake = system.HANDSHAKE_NONE,
hardwareFlowControl = False,
parity= system.serial.PARITY_NONE,
stopbits = system.serial.STOP_BITS_1) as port:
L= port.readBytes(1, 10000)
print L
Your erroneous transcription and screenshots also use bitrate
instead of bitRate
for the parameter.
See system.serial.port - Ignition User Manual 8.1 - Ignition Documentation for the parameter names.
I think you may have a configuration or hardware issue. I don’t have any real hardware to test with, but it seems fine with a pair of virtual ports:
import time
with system.serial.port(
port = "/tmp/vserial33",
bitRate = system.serial.BIT_RATE_38400) as p1:
p1.writeBytes([\x01])
time.sleep(0.1)
with system.serial.port(
port = "/tmp/vserial44",
bitRate = system.serial.BIT_RATE_38400) as p2:
print p2.readBytes(1, 1000)
Output:
>>>
array('b', [1])
>>>
Let me check the hardware, I changed bitrate for bitRate, thanks