Here is a program to send a file to a PC for either backup or to process the information The first part of this program is just code to show examples of how to save the data from a table or string. Just comment/uncomment the different calls. The data can be either ASCII or Hex or both. If the file is all ASCII, the file will be terminated with hex zeroes. If the file is all hex or ASCII and hex, the first 3 bytes of the file will contain the number of bytes in the file excluding the 3 byte size. Both files will have hex zeroes at the end which were used to fill the remaining bytes of the .png image that wasn’t actual data. The main part of the program is createPNG(strng) . After you create a table or string of the information you want to transfer, call createPNG passing the table or string name. If a table is sent, it will be converted to a string. If you want to take the information into excel, then create the information in the table with comma seperaters (see example function AsciiTable ). The information will be packed into a .png image. The image is saved in Dropbox with the name CodeaFile. If you have Dropbox running on your PC, just sync Dropbox to update the file on your PC. After syncing, load the file CodeaFile.png on your PC into a photo editor and save it as a .raw file. If you can’t save the file as .raw, the .png file will be useless to you. After creating CodeaFile.raw, you can rename it to whatever name you want, changing the extension to .txt for an ASCII file, or .bin for a hex file. The name CodeaFile in this program doesn’t need to be changed because you should always rename the file CodeaFile.raw on the PC to something else before using it. I checked the program for errors, but if you find any, let me know.
EDIT: to view the contents of the hex file on the PC, you’ll have to use a hex editor.
-- start of code for showing examples
function setup()
-- uncomment/comment calls for different test example. Call only one at a time.
AsciiTable() -- test call for Ascii table
--AsciiString() -- test call for Ascii string
--HexTable() -- test call for Hex table
show() -- show hex values stored in .png file
end
function AsciiTable() -- create test data from Ascii table
local tab={}
for z= 1,32 do
tab[z]=z.."," -- create data with comma seperaters
--table.insert(tab,z..",")
end
str=table.concat(tab) -- convert table to a string
print("Ascii file from a table.\
")
print(str.."\
")
createPNG(tab)
end
function AsciiString() -- create test data from Ascii string
str="one,two,3,four,5,six,seven,8,nine"
print("Ascii file from a string.\
")
print(str.."\
")
createPNG(str)
end
function HexTable() -- create test data from a hex table
local tab={}
for z=0,32 do
tab[z+1]=string.char(z)
end
str=table.concat(tab) -- convert table to a string
print("Hex file created from a table\
1st 3 bytes (b1,b2,b3) are the size.")
print("File size = b1+(b2*256)+(b3*256*256)\
")
createPNG(tab)
end
function show() -- show values stored in img1
img1=readImage("Dropbox:CodeaFile")
x1=img1.width
y1=img1.height
print("The Hex values stored in the PNG file. R G B values.\
")
for y=y1,1,-1 do
for x=1,x1 do
r,g,b,a=img1:get(x,y)
str=string.format("%02x %02x %02x",r,g,b)
print(str)
end
end
print("\
Ascii files are terminated with hex zeroes. Hex files have the size in 1st 3 bytes.")
print("\
The remaining image is filled with hex zeroes.")
end
-- end of code for showing examples
-- this function is all that's needed to create the .png image file
function createPNG(strng) -- pass a string or table of information
-- written by: dave1707 12/10/12
local fileName="Dropbox:CodeaFile" -- file name for .png file
local img1,size
local count=0
local x,y,v1,v2,v3,s1,s2,b1,b2,b3,z
local a1=256; local a2=256*256
local ascii=true
if type(strng)=="table" then
strng=table.concat(strng) -- convert a table to a string
end
-- check for all ascii or a mix of ascii and hex
size=#strng
for z=1,size do
x=string.byte(strng,z,z)
if x<32 or x>126 then -- non ascii value
ascii=false
end
end
-- calculate width and height for image size and create img1
x=math.ceil((size+6)/3)
s1=math.ceil(math.sqrt(x))
s2=math.ceil(x/s1)
img1=image(s1,s2)
-- calculate 3 byte size (b1+b2*256+b3*256*256) for hex file
b1=size; b2=0; b3=0
if b1>=a2 then
b3=math.floor(size/a2)
b1=b1-b3*a2
end
if b1>=a1 then
b2=math.floor(size/a1)
b1=b1-b2*a1
end
-- move string data into r,g,b values and set x,y point of img1
for y=s2,1,-1 do
for x=1,s1 do
if x==1 and y==s2 and not ascii then
img1:set(1,s2,b1,b2,b3,255) -- put size in 1st rgb entry of a hex file
else
v1=0;v2=0;v3=0
count = count + 1
if count<=size then
v1=string.byte(strng,count,count)
count = count + 1
if count<=size then
v2=string.byte(strng,count,count)
count = count + 1
if count<=size then
v3=string.byte(strng,count,count)
end
end
img1:set(x,y,v1,v2,v3,255) --save rgb values per x,y point
else
img1:set(x,y,0,0,0,255) -- fill remaining image with 0's
end
end
end
end
saveImage(fileName,img1)
end