esc_pos_printer icon indicating copy to clipboard operation
esc_pos_printer copied to clipboard

USB printing on LINUX, WINDOWS over USB port

Open kzmKZuzmo opened this issue 2 years ago • 4 comments

Is there a way to print over usb cabel based on windows and linux app ?

kzmKZuzmo avatar Apr 07 '22 20:04 kzmKZuzmo

Hi @kzmKZuzmo Did you get anything related to printing with windows?

Thanks in advance

EwertonDutra avatar Apr 17 '22 11:04 EwertonDutra

Up!!

thanhhuy0611 avatar Jun 28 '22 09:06 thanhhuy0611

Does there is any solution?

Would allow using cheaper printing devices, such as Epson : TM-T88IV TM-T20III

flutter-painter avatar Jul 16 '22 10:07 flutter-painter

most of the pos are using USB connection with their printer. supporting USB is a must

marwenbk avatar Dec 31 '22 10:12 marwenbk

this is how to send the comand to the printer to print your lable

for windows File('\computer-name\printerName').writeAsBytes(bytes);

for Linux File(printPort).writeAsBytes(bytes);

make this on your device

Identify the USB device: Use tools like lsusb or dmesg to identify the USB device and find its vendor and product IDs. For example, if you run lsusb, you'll get a list of connected USB devices with their IDs.

lsusb Alternatively, check the kernel log using dmesg:

dmesg | grep USB Find the device node: Once you have identified the USB device, find its associated device node under the /dev directory. This node might be named something like /dev/ttyUSB0, /dev/sdX, or similar.

Set permissions (if needed): Depending on your use case, you might need to set the correct permissions on the device node to allow access. You can use the chmod command for this purpose.

sudo chmod 666 /dev/ttyUSB0 Be cautious with permissions, and only grant the necessary access to users or groups.

Persistent naming with udev: If you want to ensure that a USB device always gets the same port name, you can create a udev rule. Udev rules are stored in the /etc/udev/rules.d/ directory. Create a new rule file, for example, 99-usb-serial.rules:

sudo nano /etc/udev/rules.d/99-usb-serial.rules Add a rule based on the device's attributes. For example:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", SYMLINK+="my_usb_device" Replace 1234 and 5678 with the actual vendor and product IDs of your device. The SYMLINK creates a symbolic link with a custom name (my_usb_device in this case).

After creating the rule, reload udev rules:

sudo udevadm control --reload-rules Now, whenever the specified USB device is connected, it should have a consistent and custom-named port under /dev. Adjust the udev rule and other settings according to your specific requirements and device characteristics.

and dart code (flutter) .env PRINT_PORT=/dev/usb/my_usb_device

import 'package:esc_pos_utils_plus/esc_pos_utils.dart'; import 'package:flutter/material.dart'; import 'dart:io';

...

String printPort = dotenv.env['PRINT_PORT'].toString(); Future testTicket() async { final profile = await CapabilityProfile.load(); final generator = Generator(PaperSize.mm80, profile);

List bytes = []; bytes += generator.text("test", linesAfter: 1);

  bytes += generator.cut();


if(Platform.isLinux){

  File(printPort).writeAsBytes(bytes);
}

 

} }

kzmKZuzmo avatar Jan 11 '24 14:01 kzmKZuzmo

Hi @kzmKZuzmo, Thank you for providing this complete guideline. I havent tried it yet but wonder if these preliminary steps can be tackled using dart the same way that bluetooth device recognition is handled ?

How about identifying the device using : https://pub.dev/packages/quick_usb Or even https://github.com/woodemi/libusb.dart/blob/master/example/listDeviceProducts.dart

?

flutter-painter avatar Jan 16 '24 18:01 flutter-painter