hey man
thanks for the input...
so to explain better, and to keep in mind one goal is to keep this as a single distributable exe, here is what really happens, from the user perspective
the exe can be run normally, giving multiple gui interfaces allowing manual machine status change via context menu. this exe polls an ini file for changes, and when updated, reads the appropriate machine's log file reading current status, and history of previous logs [wherein lies the problem when they are out of order] Manually changing the status via gui doesn't really change the internal status of that machine, but rather logs the change and updates said ini file, the same as the following use...
the exe can also be run with command line parameters, which updates the ini, logs to the machine's daily log, and logs to the general scripts monthly log (designed to be called by another program, a DNC server for serial comm. to the cnc machines). I realize it would have been simpler to make a separate script to handle the direct logging calls, but its been a fun challenge getting it working as well as it is... so when the command line parameters are used, that instance logs and then exits... when none are used it just detects and kills the other running instances (since singleinstance couldnt be used for the above functionality req) and then restarts (acts like singleinstance force when an icon is run from windows, but acts like single instance off when called with command line parameters)
to make it slightly more complicated (and to explain why its functioning the way it does by updating files and polling those files, instead of just storing the pertinant info in memory... but the reason is this. besides the 1 persistant instance running all the time, and the other superquick instances running from command line calls, and other superquick instances running from hotkeys (wired to machine's relays).......
there are a few pcs on the network, doing the same thing (except to that remote ini and log file on the server)... mostly reading but with the ability to update statuses...
i shuold be using the tcp/ip functionality well documented on these forums at some point but i havent tackled that one yet... and it will cause other problems with functionality...
got long winded again, i'll end there, i'm gonna tidy up some code tonight and see if i feel like posting it all on here... if anyone is interested (otherwise i'll wait til its better and post a new thread to scripts instead...)
here's the code that's doing whats pertinant to this convo:
Code:
#SingleInstance Off ;Force
#Persistent
#NoTrayIcon
#NoEnv
SetWorkingDir, %A_ScriptDir%
DetectHiddenWindows, On
OnExit, ExitMyScript
If %1%
GoSub, SMServer
WinGet, InstanceID, List, %A_ScriptFullPath%
Loop %InstanceID%
If A_Index <> 1
SendMessage, 0x1111, 1, 65134, , % "ahk_id " InstanceID%A_Index%
OnMessage(0x1111, "AnotherInstance")
GoSub, Initialize
Return
CheckForUpdate:
FileGetTime, UpdateTime, %RemoteIni%
If LastUpdateTime <> % UpdateTime
GoSub, UpdatedRemoteIni
Else
GoSub, RefreshGUIs
Return
UpdatedRemoteIni:
Loop %Machine0%
IniRead, MachineStatus%A_Index%, %RemoteIni%, MachineStatus, % Machine%A_Index%, % MachineStatus%A_Index%
Loop %Machine0%
If MachineStatus%A_Index% <> % MachineLastStatus%A_Index%
GoSub, UpdateFound
If Details
Loop %Machine0%
If MachineStatusChanged%A_Index%
{
MachineStatusChanged%A_Index% := False
RefreshDetails(A_Index)
}
If UpdateHTML
SetTimer, UpdateWWW, -5000
If LastUpdateTime <> % UpdateTime
SetTimer, UpdatedRemoteIni, % - RefreshTime * 2000
LastUpdateTime := UpdateTime
Return
Code:
SMServer:
SetWorkingDir, %A_ScriptDir%
RemoteIni = %A_ScriptDir%\MyScript.ini
LogPath = %A_ScriptDir%
CommandLine = %1% %2% %3% %4% %5%
StringUpper, CommandLine, CommandLine, T
StringSplit, CL, CommandLine, %A_Space%
StatusList = Start,End,Off,Warm,Alert,Hold,On,Job
If CL2 in %StatusList%
GoSub, Update
Else
If CL1
GoSub, FileList
ExitApp
Update:
SplitPath, RemoteIni, , LogPath
IfNotExist, %LogPath%\Log\
{
FileCreateDir, %LogPath%\Log
FileCreateDir, %LogPath%\Log\Archive
}
FormatTime, NowDate, %A_Now%, yyMMdd
FileAppend, %A_Now%%A_Tab%%CL1%%A_Tab%%CL2%%A_Tab%%CL3%%A_Tab%%CL4%`n, %LogPath%\Log\%CL1% - %NowDate%.log
IniWrite, %CL2%, %RemoteIni%, MachineStatus, %CL1%
FormatTime, NowMonth, %A_Now%, MMMM yyy
FileAppend, %A_Now%%A_Tab%%CL1%%A_Tab%%CL2%%A_Tab%%CL3%%A_Tab%%CL4%`n, %LogPath%\Log\MyScript - %NowMonth%.log
If % CL2 = "Job"
IniWrite, %CL3%, MyScript.ini, MachineJob, %CL1%
Else
If % CL3 = "Email"
GoSub, SendEmail
Return
and also, i'm not sure how multiple log files would solve it, as the timestamp is only by second (A_Now) and the problem really only appears when the two instances are run immediately one after the other, usually under the 1 second resolution of the log data... now because these times are so short, you would think what difference does it make?... but if the machine sends:
START [n seconds] HOLD [n seconds] START [n seconds] END
the log sequence follows START HOLD START END
but if the machine sends:
START [m seconds] HOLD [0 seconds] START [n seconds] END
(notice the 0 seconds) then the log sequence could end up like this:
START (computes to m seconds)
START ( " 0 seconds)
HOLD ( " n seconds)
END
when it might be important to know that the HOLD status was 0 seconds long and that the START status (ie when the machines are running) was N seconds long... when the computation is taken one status to the next in sequence from the log file
thanks
- joel