B4R Question Progmem, save/restore string

Mostez

Well-Known Member
Licensed User
Longtime User
Hello,
I use Mega 2560 and I need to store large string variable (Zebra ZPL label code) and send it to serial label printer after altering specific bytes(label parameters i.e. barcode value, company name...etc).

In this tutorial Erel saved/restored array of long, kindly give short example how to save/restore string. Example of lablel code and image attached.

Thanks
 

Attachments

  • label.zip
    7.5 KB · Views: 366

Mostez

Well-Known Member
Licensed User
Longtime User
i will not alter progmem data at runtime, here is exactly what i want to do:
the string(ZPL code) consists of 2 parts, the big part is graphics data, no need to change it, and fields properties just 30 or 40 bytes, will change only it's text.
So i will send graphics part with no changes, after that, load fields part into tmp array and change needed bytes and then send it to printer.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this B4J code to generate the PROGMEM data string:
B4X:
Sub StringToBytes(s As String)
   Dim sb As StringBuilder
   sb.Initialize
   Dim bytes() As Byte = s.GetBytes("ascii")
   For Each b As Byte In bytes
     sb.Append("0x").Append(Bit.ToHexString(b)).Append(", ")
   Next
   sb.Remove(sb.Length - 2, sb.Length)
   Log(sb.ToString)
End Sub
 
Upvote 0
Top