Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing to an external file from trigger event
#1
I know this has to be pretty simple, but my reading and searching has come up empty.

What are the basic steps to open an external flat file, write something to it, then close the file from a triggered event?

For example, I am using the Elk M1G ethernet driver. I want to set up trigger events for my garage door and my front door. When the garage door is opened or closed, I want to write a record containing the door's state to garage.door.state.log. When the front door is open or closed, I want to write a record containing the door's state to front.door.state.log.

I understand the basics of triggered events, and have gotten them to do things like tell the M1G to "speak", and send email messages from CQC. But I can't find the info on how to write to an external file.

Thanks,
Ira
Reply
#2
You will probably have to write a CML macro to do that and in your triggered event do a RunMacro with the macro name. Macros will only be able to access the /CQC/CQCData/Macrofileroot directory. Something along the lines of...

Code:
Method Start() Returns Int4
Begin
    Locals=
        FileOutStream    fileLogDump;
        Time                tTime;
    EndLocals;

        fileLogDump.Open("MyLogFile", CreateActs.OpenOrCreate);
        fileLogDump.SeekToEnd();
        fileLogDump.Format(tTime);
        fileLogDump.FmtStr(" Sample Log Entry");
        fileLogDump.NewLn();
        fileLogDump.Flush();
        fileLogDump.Close();
    Return 0;
EndMethod;
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#3
wuench,

I had pretty much come to the conclusion that it would take a CML program since there aren't any commands that look like it will do what I want.

I was thinking/hoping that I could use FileSystem to create the file (if necessary), FileOutStream to open/close the file, and TextOutStream to do the writing/flushing. However, this OO stuff doesn't make much sense to an assembler language programmer like me. That's why I'm hoping for a code sample that I can modify.

Are you saying that there is no way to work on a file outside of he CQC directory structure, even with the above commands? I wanted the write to files on a network drive, external to the CQC directory.

If it's not possible with a CML program, I guess I can try a .bat file or a VB program and drive it via ExecApp.

Thanks,
Ira
Reply
#4
Yeh, for security reasons, CML can only write to the area under the MacroFileRoot directory. We might come up with some means for the system administrator to explicitly allow other access, but currently that doesn't exist.
Dean Roddey
Software Geek Extraordinaire
Reply
#5
You could look into the possibilities of using a hard link. Not sure if it is the answer, but it may work.

Mick
Reply
#6
Yeh, that could be done I assume. Map some other location to a directory in the MacroFileRoot directory. However, it may prevent the installer from working later, since it swaps the old and new directories around. I'm not sure what having a hard link pointing into the CQCData directory would do. It might prevent the directory from being renamed.
Dean Roddey
Software Geek Extraordinaire
Reply
#7
Ira Wrote:wuench,

I had pretty much come to the conclusion that it would take a CML program since there aren't any commands that look like it will do what I want.

I was thinking/hoping that I could use FileSystem to create the file (if necessary), FileOutStream to open/close the file, and TextOutStream to do the writing/flushing. However, this OO stuff doesn't make much sense to an assembler language programmer like me. That's why I'm hoping for a code sample that I can modify.

Are you saying that there is no way to work on a file outside of he CQC directory structure, even with the above commands? I wanted the write to files on a network drive, external to the CQC directory.

If it's not possible with a CML program, I guess I can try a .bat file or a VB program and drive it via ExecApp.

Thanks,
Ira

That code will open the file (MyLogFile) under Macrofileroot, create it if it doesn't exist (openorcreate), and write a line at the end of it with a timestamp then the text "Sample Log Entry". Then close it. So I think the code is all there. You don't need textoutstream or filesystem.
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#8
To write arbitrary values, just add an "[In] String ToWrite" parameter to the Start method and pass that as the value to write. You would then pass that to the macro when you invoke it from the action level.
Dean Roddey
Software Geek Extraordinaire
Reply
#9
Dean Roddey Wrote:Yeh, for security reasons, CML can only write to the area under the MacroFileRoot directory. We might come up with some means for the system administrator to explicitly allow other access, but currently that doesn't exist.

Will my idea of using ExecApp to call an "external" VB program or .bat file work, assuming I can pass it all the parameters I need? Or will that fail too if it tries to write to a file external to the CQC directory structure?

This will be a very low volume thing, so overhead isn't an issue.

Thanks,
Ira
Reply
#10
No, if you choose to run an excecutable, then it can do whatever you want it to do, as long as Windows allows it.
Dean Roddey
Software Geek Extraordinaire
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple field change trigger action Bugman 15 731 10-23-2017, 11:55 AM
Last Post: Dean Roddey
  Motion Event Running Twice? zra 2 317 07-31-2017, 08:15 PM
Last Post: zra
  Variable Driver Trigger Error zra 4 749 07-06-2017, 01:00 PM
Last Post: zra
  EVent Server Monitor znelbok 1 351 06-07-2017, 12:36 PM
Last Post: Dean Roddey
  I have an event that I want to happen 5 hours after sunset. ghurty 8 974 03-24-2017, 08:40 AM
Last Post: Dean Roddey
  HTTP-based Trigger Driver Docs znelbok 5 988 03-11-2017, 09:34 PM
Last Post: Dean Roddey
  download a file via http with CML? bbrendon 4 1,084 02-28-2017, 09:16 PM
Last Post: dlmorgan999
  Help wanted - ISY Network to CQC IP Trigger xlurkr 15 1,863 01-25-2017, 04:25 PM
Last Post: potts.mike
  Echo Config file issues rbejr 14 2,085 01-16-2017, 10:05 PM
Last Post: rbejr
  Parsing Serial Trigger data Bugman 3 592 12-01-2016, 02:09 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)