Esempio n. 1
0
        // maybe finish bytes later on
        /// <summary>
        ///
        /// </summary>
        /// <param name="peripheral"></param>
        /// <param name="serviceUuid"></param>
        /// <param name="rxCharacteristicUuid"></param>
        /// <param name="txCharacteristicUuid"></param>
        /// <param name="txNextBytes"></param>
        /// <returns></returns>
        //public static IObservable<Unit> RxFlow(this IPeripheral peripheral,
        //                                       Guid serviceUuid,
        //                                       Guid rxCharacteristicUuid,
        //                                       Guid txCharacteristicUuid,
        //                                       byte[] txNextBytes,
        //                                       Stream writeStream) => Observable.Create<Unit>(ob =>
        //{
        //    var disp = new CompositeDisposable();
        //    IDisposable flowLoop = null;
        //    IGattCharacteristic tx = null;
        //    IGattCharacteristic rx = null;

        //    disp.Add(peripheral
        //        .WhenDisconnected()
        //        .Subscribe(x =>
        //        {
        //            tx = null;
        //            rx = null;
        //            flowLoop?.Dispose();
        //        })
        //    );
        //    disp.Add(peripheral
        //        .WhenKnownCharacteristicsDiscovered(serviceUuid, txCharacteristicUuid, rxCharacteristicUuid)
        //        .Subscribe(x =>
        //        {
        //            if (x.Uuid.Equals(txCharacteristicUuid))
        //                tx = x;

        //            else if (x.Uuid.Equals(rxCharacteristicUuid))
        //                rx = x;

        //            // while connected & not stopped
        //            if (tx != null && rx != null)
        //            {
        //                if (rx.CanNotifyOrIndicate())
        //                {
        //                    flowLoop = rx
        //                        .WhenNotificationReceived()
        //                        .Subscribe(
        //                            y =>
        //                            {
        //                                writeStream.Write(y.Data, 0, y.Data.Length);

        //                                // don't need to await this will progress stream
        //                                tx.Write(txNextBytes).Subscribe();
        //                                //ob.OnNext(Unit.Default);
        //                            },
        //                            ob.OnError
        //                        );
        //                }
        //                else
        //                {
        //                    // TODO: need state hooks so this keeps going like notification pattern
        //                    flowLoop = Observable
        //                        .While(
        //                            () => peripheral.IsConnected() && !disp.IsDisposed,
        //                            Observable.FromAsync(async ct =>
        //                            {
        //                                await tx.Write(txNextBytes).ToTask(ct);
        //                                var result = await rx.Read().ToTask(ct);
        //                                writeStream.Write(result.Data, 0, result.Data.Length);
        //                            })
        //                        )
        //                        .Subscribe(_ => { }, ob.OnError);
        //                }
        //            }
        //        })
        //    );

        //    return () =>
        //    {
        //        disp.Dispose();
        //        flowLoop?.Dispose();
        //    };
        //});


        //public static IObservable<Unit> TxFlow()

        /// <summary>
        /// Used for writing blobs
        /// </summary>
        /// <param name="ch">The characteristic to write on</param>
        /// <param name="value">The bytes to send</param>
        /// <param name="reliableWrite">Use reliable write atomic writing if available (windows and android)</param>
        public static IObservable <BleWriteSegment> BlobWrite(this IGattCharacteristic ch, byte[] value, bool reliableWrite)
        // don't need to dispose of memorystream
        => ch.BlobWrite(new MemoryStream(value), reliableWrite);
Esempio n. 2
0
        void PrintText()
        {
            //设置标签纸尺寸,间隙尺寸,并且清空打印缓冲区
            string printstr = String.Format("SIZE {0} mm, {1} mm \r\n", 74, 56);

            printstr += String.Format("GAP {0} mm \r\n", 2);
            printstr += String.Format("CLS \r\n");
            //第一行数据 名称及单据编号
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 24, "TSS32.BF2", 0, 1, 1, "胜京物流收货凭证");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 324, 24, "4", 0, 1, 1, "8542214");
            //画一条细线
            printstr += String.Format("BAR {0},{1},{2},{3} \r\n", 2, 66, 580, 1);
            //代收款及应收款
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 76, "TSS24.BF2", 0, 1, 1, "代收款:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 92, 76, "3", 0, 1, 1, "11.00");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 76, "TSS24.BF2", 0, 1, 1, "应收款:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 284, 76, "3", 0, 1, 1, "11.00");
            //日期及货品
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 106, "TSS24.BF2", 0, 1, 1, "日期:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 76, 110, "2", 0, 1, 1, "2020-11-12 12:00");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 380, 106, "TSS24.BF2", 0, 1, 1, "货品:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 448, 106, "TSS24.BF2", 0, 1, 1, "服装");
            //发站、到站、件数
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 136, "TSS24.BF2", 0, 1, 1, "发站:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 76, 136, "TSS24.BF2", 0, 1, 1, "保定");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 136, "TSS24.BF2", 0, 1, 1, "到站:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 248, 136, "TSS24.BF2", 0, 1, 1, "北京");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 380, 136, "TSS24.BF2", 0, 1, 1, "件数:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 448, 136, "3", 0, 1, 1, "1");
            //收货人、收货电话
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 166, "TSS24.BF2", 0, 1, 1, "收货人:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 94, 166, "TSS24.BF2", 0, 1, 1, "测试");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 166, "TSS24.BF2", 0, 1, 1, "收货电话:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 288, 166, "3", 0, 1, 1, "15010201672");
            //托运人、托运电话
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 196, "TSS24.BF2", 0, 1, 1, "托运人:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 94, 196, "TSS24.BF2", 0, 1, 1, "测试");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 196, "TSS24.BF2", 0, 1, 1, "托运电话:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 288, 196, "3", 0, 1, 1, "15010201672");
            //付款方式、总运费、备注
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 226, "TSS24.BF2", 0, 1, 1, "付款方式:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 110, 226, "TSS24.BF2", 0, 1, 1, "提付");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 226, "TSS24.BF2", 0, 1, 1, "总运费:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 268, 226, "3", 0, 1, 1, "11.00");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 380, 226, "TSS24.BF2", 0, 1, 1, "备注:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 446, 226, "3", 0, 1, 1, "15010201672");
            //分割线
            printstr += String.Format("BAR {0},{1},{2},{3} \r\n", 0, 260, 580, 1);
            //经办人、发货人签字
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 270, "TSS24.BF2", 0, 1, 1, "经办人:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 94, 270, "TSS24.BF2", 0, 1, 1, "测试");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 270, "TSS24.BF2", 0, 1, 1, "发货人签字:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 312, 270, "TSS24.BF2", 0, 1, 1, "测试");
            //发站电话
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 300, "TSS24.BF2", 0, 1, 1, "发站电话:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 110, 300, "3", 0, 1, 1, "15010201672");
            //发站电话
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 330, "TSS24.BF2", 0, 1, 1, "到站电话:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 110, 330, "3", 0, 1, 1, "15010201672");
            //发货存根
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 360, "TSS24.BF2", 0, 1, 1, "发货存根:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 110, 360, "TSS24.BF2", 0, 1, 1, "保丢不保损!");
            //持卡人、卡号
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 390, "TSS24.BF2", 0, 1, 1, "持卡人:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 92, 390, "TSS24.BF2", 0, 1, 1, "测试");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 180, 390, "TSS24.BF2", 0, 1, 1, "卡号:");
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 252, 393, "3", 0, 1, 1, "1234567890");
            //提示信息
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 6, 420, "TSS24.BF2", 0, 1, 1, "货物查询时间为3日内,过期概不负责!");
            //LOGO字符打印
            printstr += String.Format("TEXT {0},{1},\"{2}\",{3},{4},{5},\"{6}\" \r\n", 300, 300, "TSS24.BF2", 0, 3, 3, "胜");
            //打印二维码
            //printstr += String.Format("QRCODE {0},{1},\"{2}\",{3},\"{4}\",{5},\"{6}\" \r\n",400,390,"H",10,"A",0,"www.azure.cn");
            printstr += String.Format("QRCODE {0},{1},{2},{3},{4},{5},\"{6}\" \r\n", 440, 280, "H", 4, "A", 0, "https://www.azure.cn");
            //打印标签
            printstr += String.Format("PRINT {0} \r\n", 1);

            //打印机指令包含中卫应为GB2312,装换之
            byte[] printbytes = Encoding.GetEncoding("UTF-8").GetBytes(printstr);
            printbytes = Encoding.Convert(Encoding.GetEncoding("UTF-8"), Encoding.GetEncoding("GB2312"), printbytes);
            MemoryStream stream = new MemoryStream(printbytes);

            //打印后续操作
            //Write(bs)     小文本打印方式
            _savedCharacteristic?.BlobWrite(stream).Subscribe(
                result => {
                Debug.WriteLine(result.Position);
            },
                exception => {
                ShowMessage("错误", "无法完成打印");
            }
                );
            ShowMessage("信息", "打印完毕");
        }