aeric Expert Licensed User Longtime User Jun 5, 2022 #1 I am trying to use Chr to send my string to thermal printer using ESC/POS commands. I have been using many Chr() and it works in B4J and B4A. However, B4i ignores Chr and convert the unicode into numbers. How to solve this issue? It also happen when I try to display the strings in a label. Attachments TestChr.zip TestChr.zip 14.2 KB · Views: 528
I am trying to use Chr to send my string to thermal printer using ESC/POS commands. I have been using many Chr() and it works in B4J and B4A. However, B4i ignores Chr and convert the unicode into numbers. How to solve this issue? It also happen when I try to display the strings in a label.
Solution Erel Jun 6, 2022 mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27)
mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27)
epiCode Active Member Licensed User Jun 5, 2022 #2 use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Upvote 0
aeric Expert Licensed User Longtime User Jun 5, 2022 #3 mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... I have tried but it doesn't work for me. Upvote 0
mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... I have tried but it doesn't work for me.
Star-Dust Expert Licensed User Longtime User Jun 5, 2022 #4 In my BLE printing library for iOs (found here) I use this method to pass strings (or characters) B4X: BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8")) __________________________________________________ Di perpustakaan saya untuk pencetakan BLE untuk iOs (terdapat di sini) saya menggunakan kaedah ini untuk menghantar rentetan (atau aksara) B4X: BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8")) Last edited: Jun 5, 2022 Upvote 0
In my BLE printing library for iOs (found here) I use this method to pass strings (or characters) B4X: BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8")) __________________________________________________ Di perpustakaan saya untuk pencetakan BLE untuk iOs (terdapat di sini) saya menggunakan kaedah ini untuk menghantar rentetan (atau aksara) B4X: BLEmanager.WriteData(ServiceName, CharatteristicName,Text.GetBytes("UTF8"))
Star-Dust Expert Licensed User Longtime User Jun 5, 2022 #5 As for your source, it works correctly on the label Upvote 0
aeric Expert Licensed User Longtime User Jun 5, 2022 #6 Star-Dust said: As for your source, it works correctly on the label View attachment 130018 Click to expand... The numbers show that the output is incorrect. Upvote 0
Star-Dust said: As for your source, it works correctly on the label View attachment 130018 Click to expand... The numbers show that the output is incorrect.
Star-Dust Expert Licensed User Longtime User Jun 5, 2022 #7 aeric said: The numbers show that the output is incorrect. Click to expand... I thought you were referring to characters. Upvote 0
aeric said: The numbers show that the output is incorrect. Click to expand... I thought you were referring to characters.
Erel B4X founder Staff member Licensed User Longtime User Jun 6, 2022 #8 mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27) Upvote 0 Solution
mohsyn said: use notation like: CHR(0x0027) instead of CHR(27) and it should work just fine Click to expand... Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27)
aeric Expert Licensed User Longtime User Jun 6, 2022 #9 Erel said: Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27) Click to expand... Thanks Erel. Finally I get it to work! I can now build a B4J Print Server to print receipt for B4i app using bluetooth printer with no AirPrint support! B4X: Public Const eLEFT As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x00) ' ESC a NUL Public Const eCENTRE As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x01) ' ESC a SOH Public Const eRIGHT As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x02) ' ESC a STX Public Const eCLEAR As String = "" & Chr(0x1B) & Chr(0x40) ' ESC @ Public Const eLINEFEED As String = "" & Chr(0x0D) & Chr(0x0A) ' CR LF I am wondering why smart string literal is not working. B4X: Public Const eLEFT As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x00)}"$ ' ESC a NUL Public Const eCENTRE As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x01)}"$ ' ESC a SOH Public Const eRIGHT As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x02)}"$ ' ESC a STX Public Const eCLEAR As String = "" & $"${Chr(0x1B)}${Chr(0x40)}"$ ' ESC @ Public Const eLINEFEED As String = "" & $"${Chr(0x0D)}${Chr(0x0A)}"$ ' CR LF Upvote 0
Erel said: Tip: Chr(0x0027) = Chr(0x27) = Chr(39) The issue discussed happens because there is no real char type in OBJC. You need to help the compiler: Code: Dim s As String = "" & Chr(0x27) Click to expand... Thanks Erel. Finally I get it to work! I can now build a B4J Print Server to print receipt for B4i app using bluetooth printer with no AirPrint support! B4X: Public Const eLEFT As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x00) ' ESC a NUL Public Const eCENTRE As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x01) ' ESC a SOH Public Const eRIGHT As String = "" & Chr(0x1B) & Chr(0x61) & Chr(0x02) ' ESC a STX Public Const eCLEAR As String = "" & Chr(0x1B) & Chr(0x40) ' ESC @ Public Const eLINEFEED As String = "" & Chr(0x0D) & Chr(0x0A) ' CR LF I am wondering why smart string literal is not working. B4X: Public Const eLEFT As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x00)}"$ ' ESC a NUL Public Const eCENTRE As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x01)}"$ ' ESC a SOH Public Const eRIGHT As String = "" & $"${Chr(0x1B)}${Chr(0x61)}${Chr(0x02)}"$ ' ESC a STX Public Const eCLEAR As String = "" & $"${Chr(0x1B)}${Chr(0x40)}"$ ' ESC @ Public Const eLINEFEED As String = "" & $"${Chr(0x0D)}${Chr(0x0A)}"$ ' CR LF