Well, I couldn't find a way to make RSLogix 500 open in the "Compare" mode through the command line, so I made an ugly hack instead. It's made even more complicated for me because I keep my git tools on my host and my PLC Programming in a VMWare image and use unity mode which makes things even more worse.
So, that being said, here's what I did.
I made a .bat that opens my VM, enters unity mode and opens a custom RSLogix 500 Launcher with arguments as the source/compare project:
Code:
REM Compare500RSS.bat
REM @echo off
C:
cd C:\Program Files (x86)\VMware\VMware Workstation
REM Start VM
vmrun -T ws start "C:\Users\xxxx\Virtual Machines\RSLogix 500\RSLogix 500.vmx" nogui
REM Now run application
vmware-unity-helper.exe -r -G:6 -V:1
vmrun -T ws -gu xxxx -gp xxxx runProgramInGuest "C:\Users\xxxx\Virtual Machines\RSLogix 500\RSLogix 500.vmx" -activeWindow -interactive -nowait "C:\Utilities\RSlogix 500 Compare.exe " %1 %2
exit
I then used this Compare500RSS.bat as my external "git difftool" in my git config
Code:
[diff]
[difftool "Compare500File"]
cmd = "\"C:/Compare500RSS.bat\" \"$LOCAL\" \"$REMOTE\""
[diff]
tool = Compare500File
The "RSLogix 500 Compare.exe" I made in c# - the launcher translates the path to what the VM sees in the shared folder to my host hard drive, loads up RSLogix, then (
disgusting hack alert!!!) uses a series of keystokes to call up the compare utility and enter in all the info (base project path, compare project path etc), maximize and rearrange windows etc. Again, this was whipped up on the fly and is not pretty or perfect but it does work.
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RSlogix_500_Compare
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
//Start RSLogix
ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
si.CreateNoWindow = true;
si.FileName = "C:\\Program Files (x86)\\Rockwell Software\\RSLogix 500 English\\rs500.exe";
si.UseShellExecute = false;
System.Diagnostics.Process.Start(si);
//Wait for it to boot
System.Threading.Thread.Sleep(3000);
//Get the handle of the RSLogix window
System.IntPtr iHandle = FindWindow(null, "RSLogix 500");
if (iHandle != IntPtr.Zero)
{
//Maximize the window
ShowWindow(iHandle, 3);
//Alt-t then c for compare
SendKeys.SendWait("%t");
SendKeys.SendWait("c");
//Send the paths
SendKeys.SendWait(convertFilePath(args[0]));
SendKeys.SendWait("{TAB}{TAB}{TAB}");
SendKeys.SendWait(convertFilePath(args[1]));
SendKeys.SendWait("{ENTER}");
//Wait for window and say OK
System.Threading.Thread.Sleep(500);
SendKeys.SendWait("{ENTER}");
//Scroll down to first ladder file and open it
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}");
SendKeys.SendWait("{ENTER}");
//enter the passcode
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("passcodehere{ENTER}");
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("passcodehere{ENTER}");
//Arrange the windows to default project
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("%w");
SendKeys.SendWait("a");
SendKeys.SendWait("{ENTER}");
Application.Exit();
}
}
private static string convertFilePath(string path)
{
//Convert file path for VMware image from C:\ to Z:\C\
StringBuilder newPathSourceProject = new StringBuilder(path);
newPathSourceProject.Replace("C:\\", "Z:\\C\\");
return newPathSourceProject.ToString();
}
}
}
I hope someone can use this in the future because I sure was frustrated looking for the easy way with a command line switch. If you don't have a VM you can use the launcher program directly as your git difftool or maybe an AutoHotKey script to do the same thing.