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

Bluetooth Printer Selection Exception #226

Open
Cruik opened this issue Mar 31, 2023 · 3 comments
Open

Bluetooth Printer Selection Exception #226

Cruik opened this issue Mar 31, 2023 · 3 comments
Labels
question Further information is requested

Comments

@Cruik
Copy link

Cruik commented Mar 31, 2023

I try to print something on a thermal printer with my .NET MAUI App.
How can i specify my Bluetooth-Printer which is already connected to my device?

// USB, Bluetooth, or Serial
var printer = new SerialPrinter(portName: "COM5", baudRate: 115200);

The documentation is not that helpful, when i am using this code snippet, i 'm getting the following Exception thrown

{System.DllNotFoundException: libSystem.IO.Ports.Native
at System.IO.Ports.SafeSerialDeviceHandle.Open(String portName)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at ESCPOS_NET.SerialPrinter..ctor(String portName, Int32 baudRate)
at Lobi.Pos.Printer.PrintWorker.GetBTPrinter(LobiPrinterSettings printerSetting) in D:\work\awagd\LOBI\New\src\Lobi.Pos.Printer\PrintWorker.cs:line 187
at Lobi.Pos.Printer.PrintWorker.InitiatePrinterConnection(LobiPrinterSettings lobiPrinterSettings, String deviceName) in D:\work\awagd\LOBI\New\src\Lobi.Pos.Printer\PrintWorker.cs:line 134}

@lukevp
Copy link
Owner

lukevp commented Jun 17, 2023

@Cruik this is an os-specific implementation detail that you'll have to figure out and adapt to the library, unfortunately. This library just uses System.IO.Ports for the Serial implementation, so you will need to figure out how to get the correct path and interface technology that your printer needs. For example, on Linux, you would only use the Serial implementation if your printer exposed itself as a Bluetooth Serial device, but some devices expose themselves as /dev/ filesystem items on Linux, and in that case you'd use FilePrinter. It depends on the drivers for your printer and how they pair.

Are you trying to do this from Windows? or from a phone OS?

@lukevp lukevp added the question Further information is requested label Jun 17, 2023
@Cruik
Copy link
Author

Cruik commented Jun 17, 2023

I am trying to use it from android

@lukevp
Copy link
Owner

lukevp commented Jun 17, 2023

I've successfully done this in a Xamarin Forms application, so I believe you should be able to do the same in MAUI. Maybe there's something wrong with your build or with the DLL loading, because I see it says that the DLL for System.IO.Ports.Native wasn't found (which is probably the Android-specific implementation).

Regarding connecting to the printer, I would suggest using BLE - then you need to use a library that supports BLE to find devices, connect to them (you'd make a UI to display a list of printers when scanned from bluetooth, for example), and then you can send bytes to them.

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

No branches or pull requests

2 participants