Пример #1
0
        private void btnBinary_Click(object sender, EventArgs e)
        {
            myFont theFont = (myFont)(lstFonts.SelectedItem);

            /*
             * the default printer code page is MacRoman
             * the other one is MacRoman
             */
            if (_serial == null || !_serial.IsOpen)
            {
                addLog("Open COM first");
                return;
            }
            List <byte> buf = new List <byte>();

            //reset
            byte[] bReset = { 0x1b, 0x40 }; // esc @
            //select font
//            byte[] bSetFont = { 0x1B, 0x77, 0x2B }; //esc w plus one of 0x2b, 0x22, 0x6d, 0x21
            byte[]   bSetFont = { 0x1B, 0x77, 0x21 }; //esc w with US Standard
            myFont[] fonts    = { theFont };
            //new myFont(0x2B, '+', "Monospace821 Bold 26")};
            //,new myFont(0x22, 'm', "Monospace821 WLG4 16"),
            //new myFont(0x6d, '"', "Monospace821 WLG4 24"),
            //new myFont(0x26, '&', "Roman Bold 26"),
            //new myFont(0x21, '!', "US Standard CP437/EU"),
            //new myFont(0x42, 'B', "Enhanced CNDS")};
            foreach (myFont mf in fonts)
            {
                buf.Clear();
                bSetFont[2] = mf.id;
                //tab spacing
                //byte[] bSetTabPos ={ 0x1B, 0x44,
                //                      2, 4, 6, 8, 10, 12, 14, 16, 18, 20,
                //                      22, 24, 26, 28, 30, 32, 34, 46, 48, 50,
                //                      0x00}; //esc D n1...nk 0x00
                buf.AddRange(bReset);
                buf.Add(0x0d);
                buf.Add(0x0a);
                buf.AddRange(Encoding.ASCII.GetBytes(mf.name));
                buf.AddRange(bSetFont);
                buf.Add(0x0d);
                buf.Add(0x0a);
                //buf.AddRange(bSetTabPos);

                buf.AddRange(getAsciiTable(new byte[] { 0x20 }));
                buf.Add(0x0d);
                buf.Add(0x0a);

                dumpBytes(buf.ToArray());

                _serial.Write(buf.ToArray(), 0, buf.Count);
            }
        }
Пример #2
0
        void wThread()
        {
            try
            {
                addLog("start printing...");
                String toPrinter = "";
                if (_testID < 4)
                {
                    toPrinter = _test[_testID].Replace("<--", "\x1B");
                }
                else if (_testID == 4)
                {
                    toPrinter = getFontTestLines();
                }
                else if (_testID == 5)
                {
                    toPrinter = getCharSets();
                }
                else if (_testID == 6)
                {
                    for (int x = 0; x < allRomanFonts.Length; x++)
                    { // for each font
                        toPrinter += "\r\n\x1b" + "w" + allRomanFonts[x].idChar + allRomanFonts[x].name + "\r\n";
                        toPrinter += myEncoding.GetString(getAsciiTable(new byte[] { 0x09 }));
                    }
                }
                else if (_testID == 7)                            //single ASCII chart
                {
                    myFont mFont = (myFont)getSelectedFontItem(); // lstFonts.SelectedItem;
                    toPrinter += "\r\n\x1b" + "w" + mFont.idChar + mFont.name + "\r\n";
                    toPrinter += myEncoding.GetString(getAsciiTable(new byte[] { 0x09 }));
                }
                addLog(toPrinter);
                byte[] buf = myEncoding.GetBytes(toPrinter);

                dumpBytes(buf);
                _serial.Write(buf, 0, buf.Length);
                _serial.Write(new byte[] { 0x0c }, 0, 1);
                //            dumpBytes(TestBuff);
                //            _serial.Write(TestBuff, 0, TestBuff.Length);
                //_serial.BaseStream.Write(buf, 0, buf.Length);
                //_serial.BaseStream.Flush();

                addLog("printing done...");
            }
            catch (Exception ex)
            {
                addLog("Exception-wThread: " + ex.Message);
            }
        }