DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: cdk19821
今日帖子: 35
在线用户: 11
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
女 xingyunmm (xingyunmm) ★☆☆☆☆ -
普通会员
2016/10/27 18:51:23
标题:
大家多多讨论下,现在是越来越需要到移动设备上去打印了 浏览:1312
加入我的收藏
楼主:

现在有三种方式

1.移动端 wifi 连到windows电脑上的共享打印机,或自带共享服务器的打印机

2.移动端 用蓝牙方式连接打印机

3.移动端 通过usb转接线直连打印机

我看了一下 xe10.1带的例子,BlueChat
想下当年也是在dos 用c写过类似的的这种控制pos58小票打印机打小票
所用的方法类似
TEncoding.UTF8.GetBytes(FStringsToWrite[I]);  //这里是写

还有一个TReadTHread 去读

具体那种命令字符控制打印机,要用到pos小票打印机的sdk文档,

.procedure TWriteThread.Execute;
var
  I: Integer;
  LFailed: Boolean;
  LBytesToSend: TBytes;
  LClientSocket: TBluetoothSocket;
begin
  inherited;
  While not Terminated do
  begin
    if FStringsToWrite.Count > 0 then
    begin
      FDevice.GetServices;
      LClientSocket := FDevice.CreateClientSocket(FGUID, False);
      try
        LClientSocket.Connect;
//        if LClientSocket.Connected then
        begin
          TMonitor.Enter(FLock);
          LFailed := False;
          try
          for I := 0 to FStringsToWrite.Count - 1 do
          begin
          try
          LBytesToSend := TEncoding.UTF8.GetBytes(FStringsToWrite[I]);
          LClientSocket.SendData(LBytesToSend);
          if Assigned(FOnTextSent) then
          FOnTextSent(Self, FStringsToWrite[I], FName);
          except
          LFailed := True;
          Break;
          end;
          end;
          if not LFailed then
          FStringsToWrite.Clear
          else if Assigned(FOnTextSent) then
          FOnTextSent(Self, FStringsToWrite[I] + ' "failed to send"', FName);
          finally
          TMonitor.Exit(FLock);
          end;
        end;
      finally
        LClientSocket.Close;
        FreeAndNil(LClientSocket);
      end;
    end;
    Sleep(500);
  end;
end;
----------------------------------------------
-
作者:
女 xingyunmm (xingyunmm) ★☆☆☆☆ -
普通会员
2016/10/27 18:54:06
1楼: csdn上也有类似的讨论,
http://blog.csdn.net/reality_jie_blog/article/details/11895843

<span style="font-size:14px">public class PrintDataService {    
    private Context context = null;    
    private String deviceAddress = null;    
    private BluetoothAdapter bluetoothAdapter = BluetoothAdapter    
          .getDefaultAdapter();    
    private BluetoothDevice device = null;    
    private static BluetoothSocket bluetoothSocket = null;    
    private static OutputStream outputStream = null;    
    private static final UUID uuid = UUID    
          .fromString("00001101-0000-1000-8000-00805F9B34FB");    
    private boolean isConnection = false;    
    final String[] items = { "复位打印机", "标准ASCII字体", "压缩ASCII字体", "字体不放大",    
          "宽高加倍", "取消加粗模式", "选择加粗模式", "取消倒置打印", "选择倒置打印", "取消黑白反显", "选择黑白反显",    
          "取消顺时针旋转90°", "选择顺时针旋转90°" };    
    final byte[][] byteCommands = { { 0x1b, 0x40 },// 复位打印机    
          { 0x1b, 0x4d, 0x00 },// 标准ASCII字体    
          { 0x1b, 0x4d, 0x01 },// 压缩ASCII字体    
          { 0x1d, 0x21, 0x00 },// 字体不放大    
          { 0x1d, 0x21, 0x11 },// 宽高加倍    
          { 0x1b, 0x45, 0x00 },// 取消加粗模式    
          { 0x1b, 0x45, 0x01 },// 选择加粗模式    
          { 0x1b, 0x7b, 0x00 },// 取消倒置打印    
          { 0x1b, 0x7b, 0x01 },// 选择倒置打印    
          { 0x1d, 0x42, 0x00 },// 取消黑白反显    
          { 0x1d, 0x42, 0x01 },// 选择黑白反显    
          { 0x1b, 0x56, 0x00 },// 取消顺时针旋转90°    
          { 0x1b, 0x56, 0x01 },// 选择顺时针旋转90°    
    };    
    
    public PrintDataService(Context context, String deviceAddress) {    
        super();    
        this.context = context;    
        this.deviceAddress = deviceAddress;    
        this.device = this.bluetoothAdapter.getRemoteDevice(this.deviceAddress);    
    }    
    
    /**  
     * 获取设备名称  
     *   
     * @return String  
     */    
    public String getDeviceName() {    
        return this.device.getName();    
    }    
    
    /**  
     * 连接蓝牙设备  
     */    
    public boolean connect() {    
        if (!this.isConnection) {    
          try {    
          bluetoothSocket = this.device    
          .createRfcommSocketToServiceRecord(uuid);    
          bluetoothSocket.connect();    
          outputStream = bluetoothSocket.getOutputStream();    
          this.isConnection = true;    
          if (this.bluetoothAdapter.isDiscovering()) {    
          System.out.println("关闭适配器!");    
          this.bluetoothAdapter.isDiscovering();    
          }    
          } catch (Exception e) {    
          Toast.makeText(this.context, "连接失败!", 1).show();    
          return false;    
          }    
          Toast.makeText(this.context, this.device.getName() + "连接成功!",    
          Toast.LENGTH_SHORT).show();    
          return true;    
        } else {    
          return true;    
        }    
    }
----------------------------------------------
-
作者:
女 xingyunmm (xingyunmm) ★☆☆☆☆ -
普通会员
2016/10/27 18:55:25
2楼: 不过想打店标,或者打个二维码,还不知道怎么样做
----------------------------------------------
-
作者:
男 luwakin (luwakin) ★☆☆☆☆ -
普通会员
2016/10/31 11:44:58
3楼: 最简单的方法,手机写入数据库打印记录,电脑上写个小程序读取记录,然后打印。
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS