Why do my Epson Thermal printers work (print) inconsistently?

63 Views Asked by At

My printer setup is as follows:

2x Epson TM-t20III thermal printers.

1x ZATECH USB Printer Cable (20m)

1x Belkin USB 2.0 premium printer cable (3m)

I split orders between two printers using a USB hub. Printer 1 prints first followed by a 10 second delay then printer 2 prints

Printing is initiated as follows: After clicking the Accept button for an order the following code is executed

            onPressed: () async {
                                    
                                    //mapping the details need for printing
                                    Map<String, dynamic> pendingData = {
                                      "productList": productList,
                                      'dateTime': dateTime,
                                      'time': time,
                                      'orderNum': orderNum,
                                      'total price': totalPrice,
                                    };
                                    
                                    //I then use this method to start printing
                                    await printBuffer(
                                        pendingData, orderID, customerID);


                                    if (recentOrders.length == 1) {
                                      setState(() {
                                        recentOrders = [];
                                      });
                                    }
                                  },

The print bugger displays a loading icon until printing is complete to prevent another print execution from causing issues.

Future printBuffer(Map<String, dynamic> pendingData, String orderID,
      String customerID) async {
    PrinterSetup printerItemClass = PrinterSetup();
    acceptOrder(context, orderID, customerID);

    showDialog(
        context: context,
        builder: (context) {
          return StatefulBuilder(builder: (context, setState) {
            return Center(
              child: SizedBox(
                width: 200,
                height: 200,
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: const [
                      CircularProgressIndicator(),
                      SizedBox(height: 20),
                      Text(
                        'Printing Please Wait',
                        style: TextStyle(
                            fontSize: 20,
                            fontWeight: FontWeight.bold,
                            color: Colors.white),
                      )
                    ]),
              ),
            );
          });
        });
    bool status = true;
    //initiating print
    status = await printerItemClass.printOrder(pendingData);
    //When status == false the indicator disappears 
    await waitWhile(() => status);
    if (!mounted) return;
    Navigator.of(context, rootNavigator: true).pop();

  }

The actual printing process:

  Future<bool> printOrder(Map<String, dynamic> pendingData) async {
    await getPrinters();
    await openPrinters();
    List<dynamic> productList = pendingData['productList'];
    
    //separates order items between two printers via lists
    await seperateThenCount(productList);

    //waits 3 seconds then prints on one printer
    await Future.delayed(const Duration(seconds: 3), () async {
      await initStream1(pendingData);
    });

    waits 10 seconds then prints on second printer
    await Future.delayed(const Duration(seconds: 10), () async {
      print('==========xxx 15 sec');
      await initStream2(pendingData);
    });

    //waits another 5 seconds to allow all printing to finish
    await Future.delayed(const Duration(seconds: 5), () async {
      print('==========OOO 18 sec');
    });
    await closePrinters();
    return false;
  }

After this the user can print again

I am able to print successfully 90% of the time but occasionally one printer will not print at all or prints the date followed by nothing.

The reason I implemented delays was to avoid interference between print orders to the different printers during and after printing but the problem still persists.

What could be the cause of the printer failing to print (I once had 21 successful split prints).

Is there a way to check when the printers are completely done with their task before initiating another print.

I did print immediately after the time delay as well. Could it be a heat issue?

The information for the slips work every time so I don't think it is an issue with the code breaking.

0

There are 0 best solutions below