@@ -36,10 +36,11 @@ def read(self, size: int = 1) -> bytes:
3636
3737class SerialPortOsdpConnection (OsdpConnection ):
3838
39- def __init__ (self , port : str , baud_rate : int ):
39+ def __init__ (self , port : str , baud_rate : int , raspberry_pi : bool = False ):
4040 self ._port = port
4141 self ._baud_rate = baud_rate
4242 self .serial_port = None
43+ self .raspberry_pi = raspberry_pi
4344
4445 @property
4546 def baud_rate (self ) -> int :
@@ -51,12 +52,13 @@ def is_open(self) -> bool:
5152
5253 def open (self ):
5354 self .serial_port = serial .Serial (port = self ._port , baudrate = self ._baud_rate , timeout = 2.0 )
54- fd = self .serial_port .fileno ()
55- # See struct serial_rs485 in linux kernel.
56- # SER_RS485_ENABLED = 1 and SER_RS485_RTS_ON_SEND = 1
57- # https://www.kernel.org/doc/Documentation/serial/serial-rs485.txt
58- serial_rs485 = struct .pack ('IIIIIIII' , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
59- fcntl .ioctl (fd , 0x542F , serial_rs485 )
55+ if self .raspberry_pi :
56+ fd = self .serial_port .fileno ()
57+ # See struct serial_rs485 in linux kernel.
58+ # SER_RS485_ENABLED = 1 and SER_RS485_RTS_ON_SEND = 1
59+ # https://www.kernel.org/doc/Documentation/serial/serial-rs485.txt
60+ serial_rs485 = struct .pack ('IIIIIIII' , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
61+ fcntl .ioctl (fd , 0x542F , serial_rs485 )
6062
6163 def close (self ):
6264 if self .serial_port is not None :
0 commit comments