/// <summary> /// This class writes to the PLC for Tesla /// Tags have default values, but they can be overriden by accessing the public variables of each of the tags /// </summary> /// <param name="PLCIPAddress"></param> /// <param name="_ResultsTags"></param> /// <param name="_VehicleInfoTags"></param> public PLCComm(string PLCIPAddress) { ResultsTags = new TPM_Results_Tags(); HeartbeatTime = 500; //ms. This value can also be set through a public variable. mPLC = new Esys.IO.PLC.AB.ControlLogix(); mIPAddress = PLCIPAddress; }
/// <summary> /// Stop the threads. Start a timer to make sure the threads are stopped before closing the form. /// </summary> public void Dispose() { try { OnNewMessage("Closing connection to PLC...Please wait..."); //ReadResultsThread_Running = false; ConnectionThread_Running = false; ReadResultsThread_Running = false; mPLC.StatusChanged -= new Esys.IO.DeviceStatusEventHandler(mPLC_StatusChanged); while (threadConnection.IsAlive) { Thread.Sleep(10); } while (threadReadResultsThread.IsAlive) { Thread.Sleep(10); } } catch { } //ignore exceptions try { mPLC.RemoveAllTags(); } catch { }//ignore exceptions try { mPLC.Disconnect(); } catch { }//ignore exceptions mPLC = null; OnNewMessage("PLC Disconnection Complete"); }