joan2937 / lg

Linux C libraries and Python modules for manipulating GPIO
The Unlicense
57 stars 20 forks source link

multiple i2c_open() calls for same I2C port/address returns valid handles - should be single valid handle for each I2C Port/Address #10

Closed PSkeberdis closed 2 years ago

PSkeberdis commented 2 years ago

Expecting that the first i2c_open for s specific port/address would provide a valid handle, but that a second i2c_open for the same port/address without a close would not provide a valid handle.

First instance of program run well, then second instance stomps the first instance as it also receives a valid handle.

Am testing on Pi4B+ running Ubuntu 21.04: Distributor ID: Ubuntu Description: Ubuntu 21.04 Release: 21.04 Codename: hirsute

Code snippet from lcd_i2c.py: ... import lgpio import time from RPLCD.i2c import CharLCD

from datetime import datetime

address = 0x27

cols = 20 rows = 4

lcd = CharLCD(i2c_expander='PCF8574', address=address, port=1, cols=cols, rows=rows, charmap='A02', # A00, A02 or ST0B backlight_enabled=True) ...

Fix would be to only issue a valid handle for I2C Port/address if a current handle for the same I2C Port/Address did not exist.

joan2937 commented 2 years ago

That is by design. If the underlying operating system is happy to have the same device opened multiple times then so is lg.

PSkeberdis commented 2 years ago

I don’t agree with your design philosophy in that regard. The device driver is part of the OS and should be responsible for deconflicting device access.

Here’s a reference for Linux device drivers from https://www.linuxjournal.com/article/2476:

Do I Really Need to Write a Driver?

There are several reasons for writing our own device driver:

From: joan2937 @.> Sent: Thursday, August 05, 2021 3:30 AM To: joan2937/lg @.> Cc: PSkeberdis @.>; Author @.> Subject: Re: [joan2937/lg] multiple i2c_open() calls for same I2C port/address returns valid handles - should be single valid handle for each I2C Port/Address (#10)

That is by design. If the underlying operating system is happy to have the same device opened multiple times then so is lg.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joan2937/lg/issues/10#issuecomment-893232840 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AUUJEBRQTEZ3ZEHP5TCT3FTT3I4XDANCNFSM5BSTWIWA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .