文件“/home/pond/.local/lib/python3.8/site-packages/can/interfaces/socketcan/socketcan.py”,第 778 行,发送 ready = select.select([], [self.socket], [], time_left)[1] ValueError: 文件描述符不能为负整数 (-1)
这是发生的错误。我应该如何修改代码?谁能帮帮我。
在 Library socketcan 中显示如下:
def send(self, msg: Message, timeout: Optional[float] = None) -> None:
"""Transmit a message to the CAN bus.
:param msg: A message object.
:param timeout:
Wait up to this many seconds for the transmit queue to be ready.
If not given, the call may fail immediately.
:raises ~can.exceptions.CanError:
if the message could not be written.
"""
log.debug("We've been asked to write a message to the bus")
logger_tx = log.getChild("tx")
logger_tx.debug("sending: %s", msg)
started = time.time()
# If no timeout is given, poll for availability
if timeout is None:
timeout = 0
time_left = timeout
data = build_can_frame(msg)
while time_left >= 0 :
# Wait for write availability
ready = select.select([], [self.socket], [], time_left)[1]
if not ready:
# Timeout
break
channel = str(msg.channel) if msg.channel else None
sent = self._send_once(data, channel)
if sent == len(data):
return
# Not all data were sent, try again with remaining data
data = data[sent:]
time_left = timeout - (time.time() - started)
def _send_once(self, data: bytes, channel: Optional[str] = None) -> int:
try:
if self.channel == "" and channel:
# Message must be addressed to a specific channel
sent = self.socket.sendto(data, (channel,))
else:
sent = self.socket.send(data)
except OSError as error:
raise can.CanOperationError(
f"Failed to transmit: {error.strerror}", error.errno
)
return sent
我正在尝试通过 canbus 运行一个命令来控制转向角,并通过 GNSS 模块进行连接,但出现上述错误。