BITalinoWorld / revolution-python-api

Python API for BITalino (r)evolution
GNU General Public License v3.0
21 stars 19 forks source link

Does this not work on Mac? #9

Closed TiborUdvari closed 1 year ago

TiborUdvari commented 3 years ago

I'm trying the example and I'm getting

This platform does not support bluetooth connection.
hugoslv commented 3 years ago

Hi Tibor,

On Mac OS you should use the Virtual COM Port (e.g. /dev/tty.BITalino...).

Best regards, Hugo Silva

On 21/04/2021, at 07:46, Tibor Udvari @.***> wrote:

I'm trying the example and I'm getting

This platform does not support bluetooth connection. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

piaoziyue commented 1 year ago

Hi Hugo,

I also meet with the problem, bitalino cannot successfully connect with my computer. I have tried the two bitalino macAddress "/dev/tty.BITalino-XX-XX" "/dev/cu.BITalino-XX-XX"

After using the device = BITalino(macAddress) it will have no response.

my macos is the latest version ventura 13.0.1

piaoziyue commented 1 year ago

@hugoslv

DFNOsorio commented 1 year ago

Hi piaoziyue,

In Ventura (at to some extent Monterrey), bluetooth performance has been a source of many headaches. I was able to reproduce your problems some of the times. On other occasions, re-pairing the device using the system manager seems to solve the problem.

craigvear commented 1 year ago

I am also getting the same error code

_" File "/Users/craigvear/PycharmProjects/jess_plus/bitalino.py", line 93, in init raise Exception(ExceptionCode.INVALIDPLATFORM) Exception: This platform does not support bluetooth connection."

Examining BITalino script there seems to be no provision for a Mac OS platform ("Darwin") (lines 82 - 93)

if checkMatch: if platform.system() == "Windows" or platform.system() == "Linux": try: import bluetooth except Exception as e: raise Exception(ExceptionCode.IMPORT_FAILED + str(e)) self.socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM) self.socket.connect((macAddress, 1)) self.wifi = False self.serial = False else: raiseException(ExceptionCode.INVALID_PLATFORM)``

Is there a Mac OS specific solution?

DFNOsorio commented 1 year ago

On MacOS the find device method is not available since the connection is made using the Virtual COM Port (e.g. /dev/tty.BITalino...).

craigvear commented 1 year ago

I understand. Can you advise a fix around, as the API seems to ignore darwin OS as an option.

DFNOsorio commented 1 year ago

Line 114-119 is the connection flow for macOS, since the regex fails. It connects using serial.Serial method in line 117.

craigvear commented 1 year ago

Thanks. But how do I get it to not raise an exception at line 113 ? As the logic stands if checkMatch = True and if platform != "windows" or "linux" then it raises an INVALID PLATFORM error.

DFNOsorio commented 1 year ago

Sorry, I'm not understanding your question. The checkMatch will only the True when passing a MAC address, which is not supported on MacOS. It will return None if a /dev/tty.BITalino virtual com port is passed.

For example:

print(re.match(regCompiled, "/dev/tty.bitalino-DevB")) None print(re.match(regCompiled, "00:00:00:00:00:00")) <re.Match object; span=(0, 17), match='00:00:00:00:00:00'>

craigvear commented 1 year ago

Ahhh - That is clear now. And it works. Thank you for your patience.

piaoziyue commented 1 year ago

I have tried re-pair the device and it may work (once in 10 times). And every time I re-run my code I should re-pair the device several times. It's very unreliable...

DFNOsorio commented 1 year ago

Unfortunately, with the new release of MacOS, the serial port method to connect to Bitalino is broken.

We recommend using Plux Pythons API to interact with your BITalino.