WinCE自学一周心得体会(Wince蓝牙连接打印机打印一维码和Vin码)

WinCE自学2周心得体会(WinCE蓝牙连接打印机(打印机PCL语言))

                  各位大神们,看见小弟写的博客可不要笑话,小弟也是第一次写博客,初来乍到多多指教,本人也是还没毕业的学生,在一家公司进行实习,实习5个月了,公司主要是做管理系统,跟硬件也有一些接触,一个星期以前老板安排让我做一个WinCE的系统,扫描枪用蓝牙连接打印机打印一维码和Vin码,当时一听这个任务就给我吓蒙圈了,还是实习生刚毕业的我来说还是很有难度的,从开始的demo做起,用扫描枪扫描商品码,通过蓝牙连接打印机,控制打印机打印所扫出来的条形码对WinCE一个星期的接触觉得自己对这个东西还是蛮感兴趣,因为个人比较喜欢玩硬件,这个任务刚好有硬件可以玩,下面给大家分享一下这一个星期所遇到的问题。(此文章纯属笔录,大神看见不要喷)

1、第1个问题就是所编写的程序不能正常在WinCE扫描枪上运行,始终报错无法找到Device.dll文件。

      解决方案:询问供应商所给的文件有问题。

2、第2个问题无法解决扫描时的声音

       解决方案:创建类Sound

public class Sound
    {
        private byte[] m_soundBytes;
        private string m_fileName;
        private enum Flags
        {
            SND_SYNC = 0x0000,  /* play synchronously (default) */
            SND_ASYNC = 0x0001,  /* play asynchronously */
            SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
            SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
            SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
            SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
            SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
            SND_ALIAS = 0x00010000, /* name is a registry alias */
            SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
            SND_FILENAME = 0x00020000, /* name is file name */
            SND_RESOURCE = 0x00040004  /* name is resource name or atom */
        }
        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private extern static int WCE_PlaySoundBytes(byte[] szSound, IntPtr hMod, int flags);
        /// <summary>
        /// Construct the Sound object to play sound data from the specified file.
        /// </summary>
        public Sound(string fileName)
        {
            m_fileName = fileName;
        }
        /// <summary>
        /// Construct the Sound object to play sound data from the specified stream.
        /// </summary>
        public Sound(Stream stream)
        {
            // read the data from the stream
            m_soundBytes = new byte[stream.Length];
            stream.Read(m_soundBytes, 0, (int)stream.Length);
        }
        /// <summary>
        /// Play the sound
        /// </summary>
        public void Play()
        {
            // if a file name has been registered, call WCE_PlaySound,
            //  otherwise call WCE_PlaySoundBytes
            if (m_fileName != null)
                WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
            else
                WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_MEMORY));
        }
    }

运用方法: //播放声音
            Sound sound = new Sound(@"Scan.wav");
            sound.Play();

3、蓝牙打印机PCL语言指令集

       //打印条码
        void Print_Car()
        {

        string MM1 = "";
        string MM2 = "";
        string MM3 = "";
        string MM4 = "";
        string MM5 = "";
        string MM6 = "";
        string MM7 = "";
        string MM8 = "";
        string MM_ALL = "";     

                            MM1 = this.txt_Car1.Text.Trim();
                            MM2 = this.txt_Car2.Text.Trim();
                            MM3 = this.txt_Car3.Text.Trim();
                            MM4 = this.txt_Car4.Text.Trim();
                            MM5 = this.txt_Car5.Text.Trim();
                            MM6 = this.txt_Car6.Text.Trim();
                            MM7 = this.txt_Car7.Text.Trim();
                            MM8 = this.txt_Car8.Text.Trim();
                            MM_ALL = this.txt_Car_All.Text.Trim();     

            string CPCLStr = "! 0 200 200 ALL 1" + "\r\n";
            string CPCLStr1 = "PW 575" + "\r\n" +
                   "TONE 0" + "\r\n" +
                   "SPEED 3" + "\r\n" +
                   "ON-FEED IGNORE" + "\r\n" +
                   "NO-PACE" + "\r\n" +
                   "BAR-SENSE" + "\r\n" +
                     "ENDQR" + "\r\n";
            string CPCLStr2 = "B 128 1 30 55 WB HB Qty1" + "\r\n" +
                    "BT OFF" + "\r\n" +
                   "T 4 0 WT HT Qty1" + "\r\n";
            string CPCLStr3 = "B 128 1 30 55 WB HB Qty_ALL" + "\r\n" +
                   "BT OFF" + "\r\n" +
                   "T 4 0 WT HT Qty_ALL" + "\r\n";
            string CPCLStr4 = "PRINT  " + "\r\n";

            string all = "";
            string TM = "";
            for (int i = 0; i < 8; i++)
            {
                string P = "220";
                string WB = "100";
                string WT = "95";
                string HB = "0";
                string HT = "50";
                if (i == 0)
                {
                    if (MM1 != "")
                    {
                        CPCLStr = CPCLStr.Replace("ALL", P);
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("Qty1", MM1).Replace("WT", WT).Replace("WB", WB).Replace("HB", HB).Replace("HT", HT);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "120").Replace("HT", "170").Replace("Qty_ALL", MM_ALL);
                        all = temp;
                    }

                }
                else if (i == 1)
                {
                    if (MM2 != "")
                    {
                        CPCLStr = CPCLStr.Replace("ALL", P);
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "350").Replace("WT", "345").Replace("HB", "0").Replace("HT", "50").Replace("Qty1", MM2);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "120").Replace("HT", "170").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }

                }
                else if (i == 2)
                {
                    if (MM3 != "")
                    {
                        CPCLStr = CPCLStr.Replace("220", "340");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "100").Replace("WT", "95").Replace("HB", "120").Replace("HT", "170").Replace("Qty1", MM3);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "240").Replace("HT", "290").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
                else if (i == 3)
                {
                    if (MM4 != "")
                    {
                        CPCLStr = CPCLStr.Replace("220", "340");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "350").Replace("WT", "345").Replace("HB", "120").Replace("HT", "170").Replace("Qty1", MM4);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "240").Replace("HT", "290").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
                else if (i == 4)
                {
                    if (MM5 != "")
                    {
                        CPCLStr = CPCLStr.Replace("340", "460");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "100").Replace("WT", "95").Replace("HB", "240").Replace("HT", "290").Replace("Qty1", MM5);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "360").Replace("HT", "410").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
                else if (i == 5)
                {
                    if (MM6 != "")
                    {
                        CPCLStr = CPCLStr.Replace("340", "460");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "350").Replace("WT", "345").Replace("HB", "240").Replace("HT", "290").Replace("Qty1", MM6);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "360").Replace("HT", "410").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
                else if (i == 6)
                {
                    if (MM7 != "")
                    {
                        CPCLStr = CPCLStr.Replace("460", "580");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "100").Replace("WT", "95").Replace("HB", "360").Replace("HT", "410").Replace("Qty1", MM7);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "480").Replace("HT", "530").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
                else if (i == 7)
                {
                    if (MM8 != "")
                    {
                        CPCLStr = CPCLStr.Replace("460", "580");
                        string temp = "";
                        temp = CPCLStr2;
                        temp = temp.Replace("WB", "350").Replace("WT", "345").Replace("HB", "360").Replace("HT", "410").Replace("Qty1", MM8);
                        TM = CPCLStr3;
                        TM = TM.Replace("WB", "230").Replace("WT", "225").Replace("HB", "480").Replace("HT", "530").Replace("Qty_ALL", MM_ALL);
                        all = all + temp;
                    }
                }
            }
            string Both = CPCLStr + CPCLStr1 + all + TM + CPCLStr4;
            byte[] bytes = Encoding.ASCII.GetBytes(Both);
            bth.Port.Write(bytes, 0, bytes.Length);

4、穿件日志文件

创建LogerHelper.cs类文件

 public static void WriteLog(String log)
       {

           //在CE中获取程序所在目录
           string FileDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\lg\\";


           if (!Directory.Exists(FileDir)) Directory.CreateDirectory(FileDir);


           string FileName = FileDir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
           FileName = FileName.Remove(0, 1);// FileName.Substring(1, FileName.Length);
           // MessageBox.Show(FileName);
           try
           {
               using (StreamWriter sw = File.AppendText(FileName))
               {
                   sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  -->  " + log);


               }
           }
           catch (Exception ex)
           {
               MessageBox.Show("写条码配置文件有问题!" + ex.Message, "ScanBarcode");
           }
       }

调用


PCL语言能够进一步提高打印质量,通常在中高端打印机产品中才会出现,是决定打印机输出复杂版面能力的重要指标。 PCL语言 正是Adobe公司的对PostScript语言的收费方式,给HP公司的PCL( Printer CommandLanguage,打印机控制语言)语言提供了发展空间,PCL语言是HP公司于70年代针对其打印机产品推出的一种打印机页面描述语言。HP公司的市场策略与Adobe完全不同,其他厂商可以在他们的打印机产品中自由模仿或使用PCL语言。正是PCL语言的开放性,降低了使用PCL语言的打印机产品的成本,从而使其在打印机产品中的普及程度远远高于PostScript语言。 PCL语言最初也是为点阵打印机设计的,PCL3是第一个得到广泛应用的版本,但它只支持一些简单的打印任务。PCL4虽然还只能应用在个人打印机中,但增加了对图形打印的支持,但由于解释工作比较简单,PCL4比后期的PCL5PCL6对打印控制器的要求要低很多。 PCL5是HP公司为它的激光打印机LaserJetⅢ设计的,它提供了一些与PostScript语言相似的功能,开始支持矢量字库矢量图形描述,实现了WYSIWYG(What You See Is What You Get, 所见即所得),PCL5中也使用了各种压缩技术来减小数据量,加快数据传输。 PCL5e开始支持双向数据通讯,从而使打印机可以向计算机发送打印机的状态信息。PCL5c增加了对彩色打印的支持。 1996年HP公司发布了PCL6,它更加灵活,是一个目标朝向的控制语言,使处理多图形的文件的速度大大加快,实现了更好的WYSIWYG,可以更好地处理Web页面。 两种语言的比较 1.PostScriptPCL两者的工作流程都是首先在计算机的一端将打印内容解释成标准的页面描述文件,这种文件可以被所有采用这种语言的打印机所识别,传送到打印机的核心——控制器中,然后在打印机控制器中将页面描述文件解释成可以打印的图像。从工作流程的角度看,采用这两种语言的打印方式对打印机的“大脑”要求较高,需要打印机能够自己独立处理转换的任务,并且需要打印机本身有足够的内存。 2.PostScriptPCL都具备了标准化与设备无关性的优势,对计算机系统资源占用也较少,两种语言的高版本还提高了对字库、图形图像的解释能力,对于提供了高打印质量的产品,大都采用了此两类语言。但相对来说,由于对打印机核心部分——打印控制器性能的要求较高,一定程度会增加机器成本,尤其是PostScript对打印控制器的性能更高。 3.经过对多款使用PCL语言PostScript语言的黑白彩色激光打印机进行测试。发现,使用PCL语言的打印机在处理文本或一些常见办公应用软件下的文档时具有非常明显的速度优势,在这些应用下,在打印质量方面与使用PostScript语言的打印机也没有差距。使用PostScript语言的打印机在常见办公应用下的打印速度要慢一些,但在处理PDF文件或在Photoshop等软件下打印大的图形图像文件时具有一定的速度优势,同时其在图形表现准确度、色彩表现准确度一些字库表现准确度方面也比PCL语言有优势。所以PCL语言比较适合一些普通的商务办公应用,而PostScript语言更加适合对图形色彩准确度要求比较高的专业应用。这也是目前许多打印机产品同时提供PCLPostScript两个版本的驱动的一个重要原因。 其他相关 其他要说的一点是关于选配打印语言的问题,打印语言有标配选配两种:所谓标配是把打印语言解释成一段程序,加载在打印机主控芯片程序里面,从主机过来的打印语言格式数据流直接在此芯片中解释成机芯所能识别控制的视频数据。而选配则是把打印语言解释器做成了一个相对独立的硬件,插于打印机控制器中预留的解释器插槽中。相对于标配,选配的数据读取速度较慢,数据精确度较低。厂商采取选配打印语言的策略就是为了降低打印机的成本,一般的用户用其自带的打印语言就可以完成相应的工作了,但如果有用户需要其的打印语言,那选购打印语言模块后直接插在打印机上就可以了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值