PRINT THE LABEL PRINTER WITH ARDUINO TO SATO PRINTER

Hello, i want to print the data from barcode reader, weigh scale and ds3231(for date) to SATO printer CG408TT. i dont have the problem with data from barcode reader, weigh scale and ds3231. and i just test to print the data from barcode reader and the SATO printer cant print anything.
and this is the code

#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <Usb.h>
#include <hidboot.h>
#include <avr/pgmspace.h>

#include <DS3231.h>
DS3231  rtc(SDA, SCL);

String s = "<ESC>";

const byte BarcodeLength = 11;
const byte WeightLength = 15;
const int buzzer = 2;

class BarcodeReader : public KeyboardReportParser
{
    USB Usb;
    USBHub Hub;
    HIDUniversal Hid;
    HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard;

    uint8_t buffer[BarcodeLength + 1];
    byte length;
    bool valid;

    void addCharacter(uint8_t c);

  public:
    BarcodeReader();
    void begin();
    void task();
    const uint8_t* barcode();
    void reset();

  protected:
    virtual void OnKeyDown(uint8_t mod, uint8_t key);
};

BarcodeReader::BarcodeReader()
  : Usb()
  , Hub(&Usb)
  , Hid(&Usb)
  , Keyboard(&Usb)
  , length(0)
  , valid(false)
{
}

void BarcodeReader::begin()
{
  if (Usb.Init() == -1) {
    Serial.println("OSC did not start.");
  }
  Hid.SetReportParser(1, this);
}

void BarcodeReader::task()
{
  Usb.Task();
}

void BarcodeReader::addCharacter(uint8_t c)
{
  if (valid) {
    // already have a barcode, new one will overwrite it
    reset();
  }

  // could check for \n or \r if necessary, or even implement a timing
  // mechanism for detecting end of barcode input, but for now we just
  // assume fixed width field with no output separators

  buffer[length++] = c;
  buffer[length] = '\0';

  if (length == BarcodeLength) valid = true;
};

// return value no longer valid after another call to task()
const uint8_t* BarcodeReader::barcode()
{
  return (valid) ? buffer : 0;
}

void BarcodeReader::reset()
{
  length = 0;
  valid = false;
}

void BarcodeReader::OnKeyDown(uint8_t mod, uint8_t key) {
  uint8_t c = OemToAscii(mod, key);
  if (c) addCharacter(c);
}

class WeightReader
{
    uint8_t buffer[WeightLength + 1];
    byte length;
    bool valid;

  public:
    WeightReader();
    void begin();
    void task();
    const uint8_t* weight();
    void reset();
};

WeightReader::WeightReader()

  :length(0)
  ,valid(false)
{
}

void WeightReader::begin()
{
  
  Serial2.begin(9600);
}

void WeightReader::task()
{
  if (Serial2.available()) {
    uint8_t c = Serial2.read();
    if (valid) {
      // already have a weight, new one will overwrite it
      reset();
    }

    switch (c) {
      case '\r': // discard carriage return
        break;
      case '\n': // end of weight
        if (length == WeightLength) {
          valid = true;
        } else {
          // missed the beginning of the weight
          reset();
        }
        break;
      default: // store weight characters
        if (length < WeightLength) {
          buffer[length++] = c;
          buffer[length] = '\0';
        } else 
        {
          // unexpected output from scales; should never happen
          reset();
        }
    }
  }
}
// return value no longer valid after another call to task()
const uint8_t* WeightReader::weight()
{
  return (valid) ? buffer : 0;
}

void WeightReader::reset()
{
  length = 0;
  valid = false;
}

BarcodeReader barcodeReader;
WeightReader weightReader;

void setup() {

  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600);
  
  barcodeReader.begin();
  weightReader.begin();
  rtc.begin();
  
   //The following lines can be uncommented to set the date and time
//  rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
//  rtc.setTime(11, 55, 0);     // Set the time to 12:00:00 (24hr format)
//  rtc.setDate(07, 12, 2017);   // Set the date to January 1st, 2014
}

void loop() {
  barcodeReader.task();
  weightReader.task();
  const char* barcode = barcodeReader.barcode();
  const char* weight = weightReader.weight();

  if(barcode){

    Serial.println(barcode);
    Serial.println(weight);
    Serial.println(rtc.getDateStr());
    //Serial.println(s);

//    Serial3.println("<ESC>A<ESC>H0000<ESC>V0000<ESC>BC0310008<ESC>1234ABCD");
    Serial3.println("<ESC>");
    Serial3.println("A");
    Serial3.println("<ESC>");
    Serial3.println("H0025");
    Serial3.println("<ESC>");
    Serial3.println("V0075");
    Serial3.println("<ESC>");
    Serial3.println("barcode");
    Serial3.println("<ESC>");
    Serial3.println("Q1");
    Serial3.println("<ESC>");
    Serial3.println("Z");
    //Serial3.println("H0155V0240XS1234ABCD");
    //Serial3.println(barcode);

//  Serial3.println("H060V080XS");
//  Serial3.println(barcode);
  
  barcodeReader.reset();
  weightReader.reset();
}
  if ( (barcode) && weight[0] =='U') 
  {
    Serial.println("alarm euy");
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  delay(200);
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  barcodeReader.reset();
  weightReader.reset();  
  }
}
  • just focus on SATO printer

i think the problem is SATO programming language. can you help me?

i think the problem is SATO programming language.

Well, you won't be using the SATO programming language on the Arduino, so that is not the problem.

The code you posted does something. You did not tell us what it does.
You want the code to do something. You did not tell us what you want to do.

PaulS:
Well, you won’t be using the SATO programming language on the Arduino, so that is not the problem.

Well actually OP will. Not to Program the arduino but to send SATO Command Codes to the printer through serial line apparently

———

The commands contain non-printable ASCII characters (such as , , ) and printable characters. These commands must be assembled into an organized block of code to be sent as one data stream to the printer, which in turn interprets the command codes and generates the desired label output.

The printer command codes used are based upon “Escape” (1B hexadecimal) sequences. Typically there are four types of command sequences:
{Command}
These commands generally tell the printer to perform a specific action, like “clear the memory.”

{Command} {Data}
Commands with this format tell the printer to perform a specific action which is dependent upon the following data, like “print X labels”, where the value for X is contained in the data.

{Command} {Parameter}
These commands set the operational parameters of the printer, like “set the print speed to 3.”

{Command} {Parameter} {Data}
Some commands can contain both Parameter and Data elements, such as “print a Code 39 symbol containing the data.”

————

So your issue is that you don’t send binary commands like 0x1B for escape but you send ascii text…Serial3.println("<ESC>");is not the same as Serial3.write(0x1B); // escape

So you need to read the documentation and send the right codes…

J-M-L:
Well actually OP will. Not to Program the arduino but to send SATO Command Codes to the printer through serial line apparently

———

The commands contain non-printable ASCII characters (such as , , ) and printable characters. These commands must be assembled into an organized block of code to be sent as one data stream to the printer, which in turn interprets the command codes and generates the desired label output.

The printer command codes used are based upon “Escape” ([xolor=red]1B hexadecimal[/color]) sequences. Typically there are four types of command sequences:
{Command}
These commands generally tell the printer to perform a specific action, like “clear the memory.”

{Command} {Data}
Commands with this format tell the printer to perform a specific action which is dependent upon the following data, like “print X labels”, where the value for X is contained in the data.

{Command} {Parameter}
These commands set the operational parameters of the printer, like “set the print speed to 3.”

{Command} {Parameter} {Data}
Some commands can contain both Parameter and Data elements, such as “print a Code 39 symbol containing the data.”

————

So your issue is that you don’t send binary commands like 0x1B for escape but you send ascii text…Serial3.println("<ESC>");is not the same as Serial3.write(0x1B); // escape

So you need to read the documentation and send the right codes…

thanks for your advice, it’s working.
and how about print the variable(in arduino) into barcode in SATO?

i try this code, and the printer cant print the barcode

    Serial3.write (0x1B);
    Serial3.write ("BC0310010"); Serial3.write (barcode);

what should i do?
(variable barcode is 10 digit numbers)

i try this code, and the printer cant print the barcode

The code does something. We can NOT see what it does.

what should i do?

Give up, since you don't seem willing to share critical information, and can't solve the problem(s) yourself.

Is barcode a cstring?

Please do your part

  • post full working code, no snippet. When you want to try something out, just do a small sketch; put what you want to print just in the setup() after the initialisation and keep the loop() empty.
  • escape being used a lot, have a function or macro to se d escape.
  • I gave you a reference to the doc, put comments on what page of the doc you are referring to for the type of barcode command you want to use.

For example after setting up everything if you do

void escape()
{
   Serial3.write (0x1B); // sens escape
}

// do the same for startcommand and stopCommand

void setup()
{
    // here do your initialization for Serial and Serial3

   // send Start Command: <ESC>A
   startCommand();


   // test sending CODE93 barcode with texte under
   // <ESC>H0100<ESC>V0125<ESC>BC03100081234ABCD     
   // <ESC>H0155<ESC>V0240<ESC>XS1234ABCD
   escape();
   Serial3.print(“H0100”);
   escape();
   Serial3.print(“V0125”);
   escape();
   Serial3.println(“BC03100081234ABCD”);
   escape();
   Serial3.print(“H0155”);
   escape();
   Serial3.print(“V0240”);
   escape();
   Serial3.println(“XS1234ABCD”);
   
  // send Stop Command: <ESC>Z
  stopCommand();

}

void loop() {}

PaulS:
The code does something. We can NOT see what it does.
Give up, since you don’t seem willing to share critical information, and can’t solve the problem(s) yourself.

i try this code for print data from barcode scanner( i scan 009285201 barcode), the output is just " id : 009285201*. not print the barcode CODE93
(i use code CODE93(example from doc:
H0100V0125BC03100081234ABCD (i change 1234ABCD to variable barcode)

#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <Usb.h>
#include <hidboot.h>
#include <avr/pgmspace.h>

#include <DS3231.h>
DS3231  rtc(SDA, SCL);

String s = "<ESC>";

const byte BarcodeLength = 11;
const byte WeightLength = 15;
const int buzzer = 2;

class BarcodeReader : public KeyboardReportParser
{
    USB Usb;
    USBHub Hub;
    HIDUniversal Hid;
    HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard;

    uint8_t buffer[BarcodeLength + 1];
    byte length;
    bool valid;

    void addCharacter(uint8_t c);

  public:
    BarcodeReader();
    void begin();
    void task();
    const uint8_t* barcode();
    void reset();

  protected:
    virtual void OnKeyDown(uint8_t mod, uint8_t key);
};

BarcodeReader::BarcodeReader()
  : Usb()
  , Hub(&Usb)
  , Hid(&Usb)
  , Keyboard(&Usb)
  , length(0)
  , valid(false)
{
}

void BarcodeReader::begin()
{
  if (Usb.Init() == -1) {
    Serial.println("OSC did not start.");
  }
  Hid.SetReportParser(1, this);
}

void BarcodeReader::task()
{
  Usb.Task();
}

void BarcodeReader::addCharacter(uint8_t c)
{
  if (valid) {
    // already have a barcode, new one will overwrite it
    reset();
  }

  // could check for \n or \r if necessary, or even implement a timing
  // mechanism for detecting end of barcode input, but for now we just
  // assume fixed width field with no output separators

  buffer[length++] = c;
  buffer[length] = '\0';

  if (length == BarcodeLength) valid = true;
};

// return value no longer valid after another call to task()
const uint8_t* BarcodeReader::barcode()
{
  return (valid) ? buffer : 0;
}

void BarcodeReader::reset()
{
  length = 0;
  valid = false;
}

void BarcodeReader::OnKeyDown(uint8_t mod, uint8_t key) {
  uint8_t c = OemToAscii(mod, key);
  if (c) addCharacter(c);
}

BarcodeReader barcodeReader;

void setup() {

  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600);
  
  barcodeReader.begin();
  weightReader.begin();
  rtc.begin();
  
   //The following lines can be uncommented to set the date and time
//  rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
//  rtc.setTime(11, 55, 0);     // Set the time to 12:00:00 (24hr format)
//  rtc.setDate(07, 12, 2017);   // Set the date to January 1st, 2014
}

void loop() {
  barcodeReader.task();
  const char* barcode = barcodeReader.barcode();\

  if(barcode)
{
    Serial.println(barcode);
    Serial.println(rtc.getDateStr());
    //Serial.println(s);

    Serial3.write (0x1B);
    Serial3.write ("A");
    Serial3.write (0x1B);
    Serial3.write ("%2");
    ////FROM barcode SCANNER
    Serial3.write (0x1B); Serial3.write("H0620"); Serial3.write (0x1B); Serial3.write("V00270");   Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU"); Serial3.write ("ID  : ");
    Serial3.write (0x1B); Serial3.write ("H0570"); Serial3.write (0x1B); Serial3.write("V00270");  Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU");  Serial3.write (barcode);
    ////CREATE BARCODE
    ///<ESC>H0100<ESC>V0125<ESC>BC03100081234ABCD
    Serial3.write (0x1B); Serial3.write("H0620"); Serial3.write (0x1B); Serial3.write("V00220");   //Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("BC0310010"); Serial3.write (barcode);

 
//    Serial3.write (0x1B);
//    Serial3.write ("XU");  Serial3.write (rtc.getDateStr());
    
    Serial3.write (0x1B);
    Serial3.write("Z");

  
  barcodeReader.reset();
  weightReader.reset();
}
  if ( (barcode) && weight[0] =='U') 
  {
    Serial.println("alarm euy");
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  delay(200);
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  barcodeReader.reset();
  weightReader.reset();  
  }
}

i use CODE93 code from doc :

H0100V0125BC03100081234ABCD

and the output is "id : 0009285201 and the barcode of 1234ABCD*

#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <Usb.h>
#include <hidboot.h>
#include <avr/pgmspace.h>

#include <DS3231.h>
DS3231  rtc(SDA, SCL);

String s = "<ESC>";

const byte BarcodeLength = 11;
const int buzzer = 2;

class BarcodeReader : public KeyboardReportParser
{
    USB Usb;
    USBHub Hub;
    HIDUniversal Hid;
    HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard;

    uint8_t buffer[BarcodeLength + 1];
    byte length;
    bool valid;

    void addCharacter(uint8_t c);

  public:
    BarcodeReader();
    void begin();
    void task();
    const uint8_t* barcode();
    void reset();

  protected:
    virtual void OnKeyDown(uint8_t mod, uint8_t key);
};

BarcodeReader::BarcodeReader()
  : Usb()
  , Hub(&Usb)
  , Hid(&Usb)
  , Keyboard(&Usb)
  , length(0)
  , valid(false)
{
}

void BarcodeReader::begin()
{
  if (Usb.Init() == -1) {
    Serial.println("OSC did not start.");
  }
  Hid.SetReportParser(1, this);
}

void BarcodeReader::task()
{
  Usb.Task();
}

void BarcodeReader::addCharacter(uint8_t c)
{
  if (valid) {
    // already have a barcode, new one will overwrite it
    reset();
  }

  // could check for \n or \r if necessary, or even implement a timing
  // mechanism for detecting end of barcode input, but for now we just
  // assume fixed width field with no output separators

  buffer[length++] = c;
  buffer[length] = '\0';

  if (length == BarcodeLength) valid = true;
};

// return value no longer valid after another call to task()
const uint8_t* BarcodeReader::barcode()
{
  return (valid) ? buffer : 0;
}

void BarcodeReader::reset()
{
  length = 0;
  valid = false;
}

void BarcodeReader::OnKeyDown(uint8_t mod, uint8_t key) {
  uint8_t c = OemToAscii(mod, key);
  if (c) addCharacter(c);
}

BarcodeReader barcodeReader;

void setup() {

  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600);
  
  barcodeReader.begin();
  weightReader.begin();
  rtc.begin();
  
   //The following lines can be uncommented to set the date and time
//  rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
//  rtc.setTime(11, 55, 0);     // Set the time to 12:00:00 (24hr format)
//  rtc.setDate(07, 12, 2017);   // Set the date to January 1st, 2014
}

void loop() {
  barcodeReader.task();
  weightReader.task();
  const char* barcode = barcodeReader.barcode();
  const char* weight = weightReader.weight();

  if(barcode)
{
    Serial.println(barcode);
    Serial.println(weight);
    Serial.println(rtc.getDateStr());
    //Serial.println(s);

    Serial3.write (0x1B);
    Serial3.write ("A");
    Serial3.write (0x1B);
    Serial3.write ("%2");
    ////FROM barcode SCANNER
    Serial3.write (0x1B); Serial3.write("H0620"); Serial3.write (0x1B); Serial3.write("V00270");   Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU"); Serial3.write ("ID  : ");
    Serial3.write (0x1B); Serial3.write ("H0570"); Serial3.write (0x1B); Serial3.write("V00270");  Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU");  Serial3.write (barcode);
    ////CREATE BARCODE
    ///<ESC>H0100<ESC>V0125<ESC>BC03100081234ABCD
    Serial3.write (0x1B); Serial3.write("H0620"); Serial3.write (0x1B); Serial3.write("V00220");   //Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("BC0310008"); Serial3.write ("1234ABCD");

 
//    Serial3.write (0x1B);
//    Serial3.write ("XU");  Serial3.write (rtc.getDateStr());
    
    Serial3.write (0x1B);
    Serial3.write("Z");

  
  barcodeReader.reset();
  weightReader.reset();
}
  if ( (barcode) && weight[0] =='U') 
  {
    Serial.println("alarm euy");
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  delay(200);
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  barcodeReader.reset();
  weightReader.reset();  
  }
}

and my question is why the code of U93 cant print 10 digits number and cant print the variable(barcode)?

PaulS:
The code does something. We can NOT see what it does.
Give up, since you don’t seem willing to share critical information, and can’t solve the problem(s) yourself.

sorry my bad.
this is the code and the output can print data from barcode scanner, weighing scale and ds 3231.

#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <Usb.h>
#include <hidboot.h>
#include <avr/pgmspace.h>

#include <DS3231.h>
DS3231  rtc(SDA, SCL);

String s = "<ESC>";

const byte BarcodeLength = 11;
const byte WeightLength = 15;
const int buzzer = 2;

class BarcodeReader : public KeyboardReportParser
{
    USB Usb;
    USBHub Hub;
    HIDUniversal Hid;
    HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard;

    uint8_t buffer[BarcodeLength + 1];
    byte length;
    bool valid;

    void addCharacter(uint8_t c);

  public:
    BarcodeReader();
    void begin();
    void task();
    const uint8_t* barcode();
    void reset();

  protected:
    virtual void OnKeyDown(uint8_t mod, uint8_t key);
};

BarcodeReader::BarcodeReader()
  : Usb()
  , Hub(&Usb)
  , Hid(&Usb)
  , Keyboard(&Usb)
  , length(0)
  , valid(false)
{
}

void BarcodeReader::begin()
{
  if (Usb.Init() == -1) {
    Serial.println("OSC did not start.");
  }
  Hid.SetReportParser(1, this);
}

void BarcodeReader::task()
{
  Usb.Task();
}

void BarcodeReader::addCharacter(uint8_t c)
{
  if (valid) {
    // already have a barcode, new one will overwrite it
    reset();
  }

  // could check for \n or \r if necessary, or even implement a timing
  // mechanism for detecting end of barcode input, but for now we just
  // assume fixed width field with no output separators

  buffer[length++] = c;
  buffer[length] = '\0';

  if (length == BarcodeLength) valid = true;
};

// return value no longer valid after another call to task()
const uint8_t* BarcodeReader::barcode()
{
  return (valid) ? buffer : 0;
}

void BarcodeReader::reset()
{
  length = 0;
  valid = false;
}

void BarcodeReader::OnKeyDown(uint8_t mod, uint8_t key) {
  uint8_t c = OemToAscii(mod, key);
  if (c) addCharacter(c);
}

class WeightReader
{
    uint8_t buffer[WeightLength + 1];
    byte length;
    bool valid;

  public:
    WeightReader();
    void begin();
    void task();
    const uint8_t* weight();
    void reset();
};

WeightReader::WeightReader()

  :length(0)
  ,valid(false)
{
}

void WeightReader::begin()
{
  
  Serial2.begin(9600);
}

void WeightReader::task()
{
  if (Serial2.available()) {
    uint8_t c = Serial2.read();
    if (valid) {
      // already have a weight, new one will overwrite it
      reset();
    }

    switch (c) {
      case '\r': // discard carriage return
        break;
      case '\n': // end of weight
        if (length == WeightLength) {
          valid = true;
        } else {
          // missed the beginning of the weight
          reset();
        }
        break;
      default: // store weight characters
        if (length < WeightLength) {
          buffer[length++] = c;
          buffer[length] = '\0';
        } else 
        {
          // unexpected output from scales; should never happen
          reset();
        }
    }
  }
}
// return value no longer valid after another call to task()
const uint8_t* WeightReader::weight()
{
  return (valid) ? buffer : 0;
}

void WeightReader::reset()
{
  length = 0;
  valid = false;
}

BarcodeReader barcodeReader;
WeightReader weightReader;

void setup() {

  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600);
  
  barcodeReader.begin();
  weightReader.begin();
  rtc.begin();
  
   //The following lines can be uncommented to set the date and time
//  rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
//  rtc.setTime(11, 55, 0);     // Set the time to 12:00:00 (24hr format)
//  rtc.setDate(07, 12, 2017);   // Set the date to January 1st, 2014
}

void loop() {
  barcodeReader.task();
  weightReader.task();
  const char* barcode = barcodeReader.barcode();
  const char* weight = weightReader.weight();

  if((barcode)&&(weight[0] =='S'))
{
    Serial.println(barcode);
    Serial.println(weight);
    Serial.println(rtc.getDateStr());
    //Serial.println(s);

    Serial3.write (0x1B);
    Serial3.write ("A");
    Serial3.write (0x1B);
    Serial3.write ("%2");
    ////barcode
    Serial3.write (0x1B); Serial3.write("H0580"); Serial3.write (0x1B); Serial3.write("V0150");   Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU"); Serial3.write ("ID  : ");
    Serial3.write (0x1B); Serial3.write ("H0520"); Serial3.write (0x1B); Serial3.write("V0150");  Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU");  Serial3.write (barcode);
    ////timbangan
    Serial3.write (0x1B); Serial3.write("H0580"); Serial3.write (0x1B); Serial3.write("V0125");   Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU"); Serial3.write ("W   : ");
    Serial3.write (0x1B); Serial3.write ("H0520"); Serial3.write (0x1B); Serial3.write("V0125");  Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU");  Serial3.write (weight);
    ////ds3231
    Serial3.write (0x1B); Serial3.write("H0580"); Serial3.write (0x1B); Serial3.write("V0100");   Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU"); Serial3.write ("TGL: ");
    Serial3.write (0x1B); Serial3.write ("H0520"); Serial3.write (0x1B); Serial3.write("V0100");  Serial3.write (0x1B); Serial3.write("L0202");
    Serial3.write (0x1B);
    Serial3.write ("XU");  Serial3.write (rtc.getDateStr());
    
    Serial3.write (0x1B);
    Serial3.write("Z");

  
  barcodeReader.reset();
  weightReader.reset();
}
  if ( (barcode) && weight[0] =='U') 
  {
    Serial.println("alarm euy");
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  delay(200);
  tone(buzzer,1500);
  delay(200);
  noTone(buzzer);
  barcodeReader.reset();
  weightReader.reset();  
  }
}

It really seems to me that you ought to be trying to get the printer to print KNOWN strings, NOT strings you have no control over.

When you can get the printer to print "JACKSHIT" and "1234DCBA" and "4321ABCD" when it is supposed to, THEN you can work on getting it to print other data, like that from the barcode scanner or the scale.

Until then, there are TOO many unknowns.

So, create a new sketch that ONLY prints "12345678" to the printer. Of course, you can print stuff to the Serial port, so you can see that the program IS going to try to print "12345678" on the printer.

Be sure to keep the printer in the drawer, closed and locked, so you can't see what it is actually printing either.

i use code CODE93(example from doc:
H0100V0125BC03100081234ABCD (i change 1234ABCD to variable barcode)

Well why the F**K do you mess around with dynamic stuff without getting static things to work first as suggested in #5?

And why the F**K don’t you RTFM and I would have to read it for you ?? Can’t you do your part of the job?

Here is what the Fine documentation states (there is a hint in blue)

FORMAT
BCaabbbccn~n
a =Narrow bar width (01 to 12 dots)
b =Barcode Height (001 to 999 dots)
cc= Data Digit Number (01 to 99)
n~n = Print Data (barcode data)

NOTES
The quantity of digit data and input data must be equal. A command error will occur if the digit data and input data are not equal.