File tree Expand file tree Collapse file tree 6 files changed +91
-1
lines changed
Expand file tree Collapse file tree 6 files changed +91
-1
lines changed Original file line number Diff line number Diff line change 55
66__all__ = ['Printer' ]
77
8+ import base64
9+ from io import BytesIO
810from typing import Any , BinaryIO
911
1012from bambulabs_api .ams import AMSHub
1416from .ftp_client import PrinterFTPClient
1517from .mqtt_client import PrinterMQTTClient
1618from .filament_info import Filament , AMSFilamentSettings
19+ from PIL import Image
1720
1821
1922class Printer :
@@ -492,8 +495,23 @@ def get_camera_frame(self) -> str:
492495 str
493496 Base64 encoded image of the camera frame.
494497 """
498+ return self .get_camera_frame_ ()
499+
500+ def get_camera_frame_ (self ) -> str :
495501 return self .__printerCamera .get_frame ()
496502
503+ def get_camera_image (self ) -> Image .Image :
504+ """
505+ Get the camera frame of the printer.
506+
507+ Returns
508+ -------
509+ Image.Image
510+ Pillow Image of printer camera frame.
511+ """
512+ im = Image .open (BytesIO (base64 .b64decode (self .get_camera_frame_ ())))
513+ return im
514+
497515 def get_current_state (self ) -> PrintStatus :
498516 """
499517 Get the current state of the printer.
Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ dependencies:
1111 - flake8
1212 - webcolors
1313 - pip :
14- - paho_mqtt
14+ - paho_mqtt
15+ - pillow
Original file line number Diff line number Diff line change 1+ import time
2+ import bambulabs_api as bl
3+
4+ IP = '192.168.1.200'
5+ SERIAL = 'AC12309BH109'
6+ ACCESS_CODE = '12347890'
7+
8+ if __name__ == '__main__' :
9+ print ('Starting bambulabs_api example' )
10+ print ('Connecting to Bambulabs 3D printer' )
11+ print (f'IP: { IP } ' )
12+ print (f'Serial: { SERIAL } ' )
13+ print (f'Access Code: { ACCESS_CODE } ' )
14+
15+ # Create a new instance of the API
16+ printer = bl .Printer (IP , ACCESS_CODE , SERIAL )
17+
18+ # Connect to the Bambulabs 3D printer
19+ printer .connect ()
20+
21+ time .sleep (5 )
22+ frame = printer .get_camera_image ()
23+ frame .save ("image.png" )
24+
25+ printer .disconnect ()
Original file line number Diff line number Diff line change 1+ import time
2+ import bambulabs_api as bl
3+ import os
4+
5+ IP = '192.168.1.200'
6+ SERIAL = 'AC12309BH109'
7+ ACCESS_CODE = '12347890'
8+
9+ env = os .getenv ("env" , "debug" )
10+
11+ if __name__ == '__main__' :
12+ print ('Starting bambulabs_api example' )
13+ print ('Connecting to Bambulabs 3D printer' )
14+ print (f'IP: { IP } ' )
15+ print (f'Serial: { SERIAL } ' )
16+ print (f'Access Code: { ACCESS_CODE } ' )
17+
18+ # Create a new instance of the API
19+ printer = bl .Printer (IP , ACCESS_CODE , SERIAL )
20+
21+ # Connect to the Bambulabs 3D printer
22+ printer .connect ()
23+
24+ try :
25+ while True :
26+ time .sleep (5 )
27+
28+ # Get the printer status
29+ status = printer .get_state ()
30+ bed_temperature = printer .get_bed_temperature ()
31+ nozzle_temperature = printer .get_nozzle_temperature ()
32+ print (
33+ f'Printer status: { status } , Bed temp: { bed_temperature } , '
34+ f'Nozzle temp: { nozzle_temperature } ' )
35+
36+ if env == "debug" :
37+ print ("=" * 100 )
38+ print ("Printer MQTT Dump" )
39+ print (printer .mqtt_dump ())
40+ print ("=" * 100 )
41+ finally :
42+ # Disconnect from the Bambulabs 3D printer
43+ printer .disconnect ()
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ classifiers = [
1919]
2020dependencies = [
2121 " paho-mqtt>=2.0.0" ,
22+ " pillow>=11.0.0" ,
2223]
2324
2425[project .urls ]
@@ -29,3 +30,4 @@ Issues = "https://github.com/acse-ci223/bambulabs_api/issues"
2930[tool .poetry .dependencies ]
3031python = " ^3.10"
3132paho-mqtt = " ^2.0.0"
33+ pillow = " ^11.0.0"
Original file line number Diff line number Diff line change 44sphinx_rtd_theme
55paho_mqtt
66webcolors
7+ pillow
You can’t perform that action at this time.
0 commit comments