Skip to content
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

running on OSX #23

Closed
MoonshineSG opened this issue Apr 29, 2024 · 19 comments
Closed

running on OSX #23

MoonshineSG opened this issue Apr 29, 2024 · 19 comments

Comments

@MoonshineSG
Copy link

Unable run due to error "AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'"

Any ideas how to fix ? Installed "original" from python.org - had to downgrade from 3.12 to 3.11 (?!) as well as brew version and both give the same error... help please

@TheZoc
Copy link

TheZoc commented Apr 29, 2024

AF_BLUETOOTH isn't available on macOS (as far as I could find out on Google) - Bluetooth support would added using CoreBluetooth API.

In the short term, you can try using the serial connection through a USB connection. You'd need to find your serial port - in the format described in README.md - and add it to the command line.
Optionally, you can try this experimental fork with auto detection on serial port, but keep in mind it wasn't tested in macOS yet: https://github.com/TheZoc/niimprint

@MoonshineSG
Copy link
Author

MoonshineSG commented Apr 29, 2024

Oh... I didn't even bother reading the USB part as B1 has no USB connection...Silly of me.

So choosing usb and providing the /dev/tty.B1-.... address does connect to the printer (it beeps and LED changes color!), but there

in set_label_density
   return bool(packet.data[0])

(printer.py", line 253,) error...

It sure is a step forward. A big one.

@TheZoc
Copy link

TheZoc commented Apr 29, 2024

I also have a B1 :)
Could you paste the entire error message for me, please?

@MoonshineSG
Copy link
Author

python3 -m niimprint -m b1 -c usb -a /dev/tty.B1-G12*** -d 1 -r 90 -i /Users/***/Downloads/B21_80x50mm_640x384px.png
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/niimprint/__main__.py", line 96, in <module>
    print_cmd()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/niimprint/__main__.py", line 92, in print_cmd
    printer.print_image(image, density=density)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/niimprint/printer.py", line 104, in print_image
    self.set_label_density(density)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/niimprint/printer.py", line 253, in set_label_density
    return bool(packet.data[0])
                ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'data'

tried with and without -d 1


Hardware version: 5.10
Firmware version: 5.14

@TheZoc
Copy link

TheZoc commented Apr 29, 2024

This is an interesting one.
I got my old MacBookPro (late 2013) and tried with Python 3.12. I currently have Big Sur installed.

I wrote a simple script to list the serial ports on my mbp and it would randomly fail to list my B1 printer in there. I couldn't find a pattern to why.
Strangely enough, when I put that detection in a loop, it didn't fail once. Even played with random sleep() times to see if I could make it fail consistently - but it didn't. Removing the loop and calling the program through the command line would cause it to randomly fail again.

I even managed to see it was missing once with ls -la /etc/tty*

Upon trying multiple times, when I connect to it, I usually get "OSError: [Errno 6] Device not configured". I did try using my fork as well, as it has more checks, but no success. By spamming the command I couldn't print the sticker once :/

Hopefully someone more experienced with RS232 and macOS can contribute here

@MoonshineSG
Copy link
Author

MoonshineSG commented Apr 29, 2024

i think this is kinda obvious, but i’ll still say it… i had the mac connected to the b1 via bluetooth first.. then ran the cook and line to print…

@MoonshineSG
Copy link
Author

I gave up running it over a Mac, and setup an old RPi... Connection over Bluetooth works fine, but it just prints a blank label ... So close... 😂😂

@MoonshineSG
Copy link
Author

python3 -m niimprint -m b1 -c bluetooth -a "13:26:01:73:1E:B0" -d 1 -r 90 -i B21_80x50mm_640x384px.png --verbose 
DEBUG | PngImagePlugin:call:191 - STREAM b'IHDR' 16 13
DEBUG | PngImagePlugin:call:191 - STREAM b'pHYs' 41 9
DEBUG | PngImagePlugin:call:191 - STREAM b'IDAT' 62 8192
DEBUG | printer:_log_buffer:146 - send: 55:55:21:01:01:21:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:31:01:01:31:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:23:01:01:23:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:33:01:01:33:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:01:01:01:01:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:02:01:01:02:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:03:01:01:03:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:04:01:01:04:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:13:04:02:80:01:80:14:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:14:02:01:00:17:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:e3:01:01:e3:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:d3:03:00:c7:01:16:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:d3:03:01:8f:01:5f:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:d3:03:02:57:01:84:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:d3:03:02:7f:01:ac:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:e4:01:01:e4:aa:aa
DEBUG | printer:_log_buffer:146 - send: 55:55:f3:01:01:f3:aa:aa
DEBUG | printer:_log_buffer:146 - recv: 55:55:f4:01:01:f4:aa:aa

tried different "D" params, all with the same result

@TheZoc
Copy link

TheZoc commented Apr 30, 2024

Looks like a duplicate of #17
Try printing with a serial cable if you can, it will probably work :)

@MoonshineSG
Copy link
Author

cable? b1 supports USB printing? 🤔

@TheZoc
Copy link

TheZoc commented May 1, 2024

It does - and I thought you attempted to do that when you used the parameter -c usb 😅

A somewhat shameless plug, I'm currently maintaining a fork that has more cable/serial/usb capabilities such as auto-detection. Works great on windows, but seems to have the same issues on macOS. Hopefully it will work nicely in Linux as well: https://github.com/TheZoc/niimprint

@AndBondStyle
Copy link
Owner

@TheZoc I'm experiencing a severe lack of time recently, but it would be nice if we can merge at some point :)

@MoonshineSG
Copy link
Author

the usb address /dev/tty.B1… was created by the bluetooth connection … I will try again… and will try the fork as well

@TheZoc
Copy link

TheZoc commented May 1, 2024

@AndBondStyle Happy to have it merged if you like the changes and code style :)
I'm trying to use ruff to format it and keep it to a standard, but some of the formulas being broken in multiple lines are annoying me right now :(

@TheZoc
Copy link

TheZoc commented May 1, 2024

@MoonshineSG I wasn't aware macOS would convert a bluetooth device to a USB-like port, interesting.
Hoepfully the fork and the cable solution solves the issue :)

@MoonshineSG
Copy link
Author

@TheZoc so found couple of errors in your fork, but all in the '_detect_port_and_model' which I don't need, so I just removed that whole function. And it work! It printed nicely but only via USB. I would prefer BT, but I can live with the USB as well. Thanks for the help.

File "~/niimbot/printer.py", line 134
    error += f"\t{devices["device"]}: {devices["model"]} (Serial No. {devices["serial_number"]})\n"
                           ^^^^^^
SyntaxError: f-string: unmatched '['
File "~/niimbot/printer.py", line 140
    logging.warning(f"Detected model '{detected_devices[0]["model"]}', but {self._model} was specified. Using model set on command line.")
                                                            ^^^^^
SyntaxError: f-string: unmatched '['
 File "~/niimbot/printer.py", line 96, in _detect_port_and_model
    com_ports = list(comports_grep(port))
                                   ^^^^^^
NameError: name 'port' is not defined

@TheZoc
Copy link

TheZoc commented May 2, 2024

Oh thanks for the report. It seems I did use double quotes inside double quotes and that's apparently only supported in python 3.12

Not sure why I missed that port not being self._port as well, and why it's working locally o.O

I'll add a fix for both of those tomorrow :)

@nobMatsushima
Copy link

@MoonshineSG
Please let me clarify since the issue has been closed.
Have you successfully printed from macOS via USB-C?
According to the logs, it seems like you are using a Raspberry Pi after all.

@MoonshineSG
Copy link
Author

@MoonshineSG Please let me clarify since the issue has been closed. Have you successfully printed from macOS via USB-C? According to the logs, it seems like you are using a Raspberry Pi after all.

No, I gave up on trying on MacOS...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants