iOS Question [SOLVED]ible:problem with writeData

Blu Blu

Member
Licensed User
Dear everyone,
i try to make an app that can send data to my zebra zq220 printer and im using ible library

code to print my data:
Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)
'    clv.Add(CreateServiceItem(ServiceId), "")
'    For Each id As String In Characteristics.Keys
'        clv.Add(CreateCharacteristicItem(id, Characteristics.Get(id)), "")
'    Next


    manager.SetNotify(ServiceId, ReadChar, True)
    Log("ServiceId"&ServiceId)
    SerId=ServiceId
    Log("Characteristics"&Characteristics)
    Dim  bc As ByteConverter
    For Each id As String In Characteristics.Keys
        Log("ID="&id)
        Log("**********")
        Log(Characteristics.Get(SerId))
        Log("**********")
        Log("get(id)"&Characteristics.Get(id))
        Log(UUID(Characteristics.Get(id)))
   
'        WriteChar=UUID(getHexFromChara(Characteristics.Get(id)))
       
    Next
   
   
End Sub



Sub Manager_Disconnected
    l2.Clear
    connected = False
    StateChanged
    StartScan
  
End Sub

Sub Manager_Connected (services As List)

    connected = True
    For i=0 To services.Size-1
        Log("***************")
        Log(services.Get(i))
        SerId=services.Get(i)
    Next
    hd.ProgressDialogHide
    manager.ReadData(SerId)
    StateChanged

End Sub




Private Sub b_stampa_Click
    PrintDocument
End Sub



Public Sub SendMessage(msg() As Byte)
    messageToSend.Add(msg)
    If messageToSend.Size = 1 Then
        manager.WriteDataWithResponse(SerId, WriteChar, msg)
    End If
End Sub





Private Sub Manager_WriteComplete (Characteristic As String, Status As Int)
    If connected = False  Then Return
    If messageToSend.Size > 0 Then
        Try
            manager.WriteDataWithResponse(SerId, WriteChar, messageToSend.Get(0))
        Catch
            Log(LastException)
        End Try
    End If
End Sub








Sub PrintDocument

    messageToSend.Clear
    If l_id.Text="" Then Return
    If t_sl.Text="" Then
        t_sl.RequestFocus
        Return
    End If
    If l_id.Text="" Then
        t_code.RequestFocus
        t_code.SelectAll
        Return
    End If
    If t_sl.Text.Length>2 Then
        hd.ToastMessageShow(y(lg,24),True)
        t_sl.RequestFocus
        t_sl.SelectAll
        Return
    End If
    If connected = False Then
        hd.ToastMessageShow(y(lg,23),True)
        Return
    End If
  
    DateTime.DateFormat = "dd/MM/yy"
    Dim lst As List
    lst.Initialize
    lst.Add("! 0 200 200 380 "& t_sl.Text  &"")'初始化  380 纸张高度
    lst.Add("SETBOLD 1")'粗体
    lst.Add("TEXT 7 1 100 0 "&pub.Left(l_mc.Text.Trim,32)  &"")
    If l_mc.Text.Trim.Length>32 Then
        lst.Add("TEXT 7 1 100 40 "&pub.Left(l_mc.Text.SubString(32).Trim,32)  &"")
    End If
  
    lst.Add("SETBOLD 0")'取消粗体
  
    If l_jg_of_fine.Text="" Then
        'lst.Add("SETMAG 2 2")'字体放大
        lst.Add("CENTER")'居中
        lst.Add("SETMAG 1 1")'字体放大
        lst.Add("TEXT 4 2 0 80 € "& l_jg.Text.Replace(".",",") &"")
        lst.Add("SETMAG 0 0")'取消放大
        lst.Add("LEFT")'恢复左对齐
    Else'有活动价格
        lst.Add("SETMAG 1 1")'字体放大
        lst.Add("TEXT 4 0 110 80 "& l_jgyj.Text.Replace(".",",") &"")
        lst.Add("LINE 100 100 220 100 1")
        lst.Add("TEXT 4 0 100 125 - "&  NumberFormat((l_jgyj.Text - l_jg.Text) / l_jgyj.Text * 100, 0,0) & "%")
        lst.Add("SETMAG 1 2")'字体放大
        lst.Add("SETBOLD 2")'粗体
        lst.Add("SETSP 6")'字间距
        lst.Add("TEXT 4 0 300 70 € "& l_jg.Text.Replace(".",",") &"")
        lst.Add("SETSP 0")'字间距
        lst.Add("SETBOLD 0")'取消粗体
        lst.Add("SETMAG 0 0")'取消放大
        lst.Add("TEXT 7 0 280 155 FINE: "& l_jg_of_fine.Text )
    End If
  
    lst.Add("BARCODE-TEXT 7 0 5")
    lst.Add("BARCODE EAN13 1 1 50 130 180 "& t_code.Text  &"")
    lst.Add("TEXT 7 0 350 180 "& l_id.Text   &"")
    lst.Add("TEXT 7 0 350 200 "& l_sj.Text   &"")
    lst.Add("TEXT 7 0 350 220 "& DateTime.Date(DateTime.Now)   &"")
    lst.Add("FORM")
    lst.Add("PRINT")
  
    Dim i As Int
    For i = 0 To lst.Size - 1
        Dim s As String = lst.Get(i)
        Dim msg() As Byte=s.GetBytes("GB2312")
        SendMessage(msg)
'        Peripheral_NewData(msg)
        Sleep(10)
    Next
    rest
' 
End Sub

Above are my codes copied from the exemple of tutorial
and i try to send ,but it gives me this error:


B4X:
Error occurred on line: 677 (B4XMainPage)
Characteristic not found:
Stack Trace: (
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 627356
  libobjc.A.dylib      objc_exception_throw + 60
  CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 983952
  B4i Example          -[BleManager getChar::] + 568
  B4i Example          -[BleManager writeData::::] + 268
  B4i Example          -[BleManager WriteDataWithResponse:::] + 84
  B4i Example          -[b4i_b4xmainpage _sendmessage::] + 608
  B4i Example          -[ResumableSub_b4xmainpage_PrintDocument resume::] + 9344
  B4i Example          -[b4i_b4xmainpage _printdocument:] + 312
  B4i Example          -[b4i_b4xmainpage _b_stampa_click:] + 304
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 138020
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 259600
 B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1300
 B4i Example          -[B4IShell runMethod:] + 416
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 1488
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1580
 B4i Example          __33-[B4I raiseUIEvent:event:params:]_block_invoke + 52
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 7788
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 14896
 libdispatch.dylib    355ACCF4-3917-3730-BC55-EF7003887ABE + 73544
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 44
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 333824
 CoreFoundation       5198FB57-5645-3B34-A49F-F32B52256CF3 + 46852
 CoreFoundation       CFRunLoopRunSpecific + 600
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            3ED35565-456D-33CB-B554-6C567FA81585 + 5326408
 UIKitCore            UIApplicationMain + 364
 B4i Example          main + 104
 dyld                 start + 520
)
Class (b4i_httpjob) instance released.


maybe i have found the exact characteristic, and i see that my printer get some data from my app, but it doesn't print like it used do in my b4a app

58366a4ee83185198790e9df3f42f86.jpg




Thanks very very much in advance
Best regards
 
Last edited:

Blu Blu

Member
Licensed User
Where are the full logs? What is the value of WriteChar?
Thanks very much Erel , maybe i find the problem ,because i have restarted my printer and then it print normaly.So i think the problem is that i have sended wrong commands that block printer , and then every commands i sended didn't work because the printer is blocked


Now the last problem is only to print euro currency symbol with the cpcl commands i have in above ,it works with b4a and not with b4i so i need to find another solution

Thanks very much
Best regards
 
Upvote 0
Top