Main Site Documentation

Esc/pos


#1

hi i’m trying to write ESC/POS Codes to a VKP80II printer, using the printer class form GHIE but it doesn’t seem to print when i send the data any ideas someone.
this is the code i’m using

        static USBH_Printer printer;
        static AutoResetEvent printerConnected = new AutoResetEvent(false);

        public static void Main()
        {
            // Subscribe to USBH event.
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;

            // wait for printer to be connectoed.
            printerConnected.WaitOne();
       
            // Get file to print
            //byte[] buffer = Resources.GetBytes(Resources.BinaryResources.beep);
            byte[] buffer = StrToByteArray("$0C");

            // Printing can take a long time, give it a 5 seconds timeout here
            printer.SendData(buffer, 0, buffer.Length, 5000);


            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }

thanx


#2

The tutorial here works fine, correct?
http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/html/f91875f6-a934-f1dc-6041-40f9cf5b1140.htm

I am not sure how printer specific protocols work. You can find some information online…


#3

Can you show StrToByteArray code?


#4

yes mike this is the tutorial i used it works great, but when i use the printer protocol to print the symbols for the printer, it doesn’t seem to work i think is got something to do with my strtobyte function.

Here is the StrToByte function :

  static byte [] StrToByteArray(string str)
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            return encoding.GetBytes(str);
        }

#5

You need to send actual byte(s) for each command.

So in your example,this should work



byte[] buffer = new byte[]{ 0x0C };
 
// Printing can take a long time, give it a 5 seconds timeout here
printer.SendData(buffer, 0, buffer.Length, 5000);



#6

Or change


StrToByteArray("$0C");

to


StrToByteArray("\f");


#7

thanx Gentlemen

i will test this tomorrow, and get back to you.
8)


#8

Hey Architect,
I just tested the actual bytes for each commands and it works fine,
thanx for the help. FEZ Hero
8)


#9

You are welcome!