-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple i2c_open() calls for same I2C port/address returns valid handles - should be single valid handle for each I2C Port/Address #10
Comments
That is by design. If the underlying operating system is happy to have the same device opened multiple times then so is lg. |
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:
* To solve concurrency problems when two or more processes try to access a device at the same time.
* To use hardware interrupts: as the kernel runs in protected mode, the user cannot manage interrupts directly from a program.
* To handle other unusual applications, such as managing a virtual device (a RAM disk or a device simulator).
* To obtain satisfaction as a programmer: writing a driver increases personal motivation as well as control over the computer.
* To learn about the internal parts of the system.
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 <#10 (comment)> , 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> .
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: