Text file read/write

Questions on Palette and Light Palette operation and features
Post Reply
jltsale
Posts: 29
Joined: Fri Apr 30, 2010 1:07 pm
Primary Venue / Use: Architectural
Where I Am: Denver, Colorado
Location: Denver, Colorado

Text file read/write

Post by jltsale » Fri Aug 27, 2010 1:39 pm

My Marquee system, almost identical to the rack pallete. The system runs 24/7. There are occasional power outages but the system computer is on a UPS. I can trap the power outage with a closed contact but would like to document power on/off in a file. I can do this in a variable page but if the marquee crashes, I lose the info. So, I would like to write lines to a text file such as "power off August 27 9:23 am" How do I open a text file, write to it, save it, and then close it with Marquee?

User avatar
MickCrozier
Posts: 288
Joined: Tue Mar 31, 2009 3:10 am
Primary Venue / Use: Professional Theatre
Where I Am: Melbourne, Australia
Location: Melbourne, Australia

Re: Text file read/write

Post by MickCrozier » Sat Aug 28, 2010 1:43 am

Hi jt
This is what I would do on the palette - pretty sure marquee will be the same, these are all standard lua functions i think

:!: I havn't tested this code

Code: Select all

local logdir = 'd:\\mylogs\\'
local f

-- Check directory exists, create if needed
f = io.open(logdir .. 'tmp.txt', 'w')	
if f == nil then
  os.execute('mkdir ' .. logdir)
else
  f:close()
  os.remove(logdir .. 'tmp.txt')
end

-- Check if file exists, create if needed
f = io.open(logdir .. 'powerloss.txt', 'r')
if f == nil then
  f:close()
  -- create it
  f = io.open(logdir .. 'powerloss.txt', 'w')
  f:write('Some header text \n')
  f:write('Some more header text \n')
  f:close()
else
  f:close()
end

-- append the txt file with log line
f = io.open(logdir .. 'powerloss.txt', 'a')
f:write(os.date('\n Power off %B %d %I:%M%p')  -- "Power off August 27 9:23am"
f:close()
to delete the file

Code: Select all

os.remove(logdir .. 'powerloss.txt')
Formerly Durisian (who died peacefully of digital old age)

jltsale
Posts: 29
Joined: Fri Apr 30, 2010 1:07 pm
Primary Venue / Use: Architectural
Where I Am: Denver, Colorado
Location: Denver, Colorado

Re: Text file read/write

Post by jltsale » Sun Aug 29, 2010 7:36 pm

thanks very much. I'll give it a try and let you know.

Post Reply