// Nov 27, 2008: Nicolette modified this function to initialize the connection to // KickBack in one function and to check the time out inside this class instead of the POS // April 15, 2010: Svetlana added system to make this class completely generic //Public Function Initialize(ByVal strHostIP As String, _ //ByVal intHostPort As Integer) As Boolean public bool Initialize(string strHostIP, short intHostPort, short System_Renamed) { bool returnValue = false; dynamic Policy_Renamed = default(dynamic); int nError = 0; float timeIN = 0; byte TimeOut = 0; HostIP = strHostIP; HostPort = intHostPort; swTCP = new SocketWrench(); swTCP.OnConnect += new EventHandler(swTCP_OnConnect); swTCP.OnDisconnect += new EventHandler(swTCP_OnDisconnect); swTCP.OnError += new SocketWrench.OnErrorEventHandler(swTCP_OnError); swTCP.OnRead += new EventHandler(swTCP_OnRead); swTCP.AutoResolve = false; swTCP.Blocking = false; swTCP.Secure = false; // TODO: Updated call of the socket wrench for the new dll. - Ipsit_33 // Refer: https://sockettools.com/webhelp/dotnet/dotnet/htmlhelp/SocketTools.SocketWrench.Initialize_overload_1.html nError = Convert.ToInt32(swTCP.Initialize(CSTOOLS4_LICENSE_KEY)); if (nError != 0) { returnValue = false; WriteToLog("Failed to initialize SocketWrench control"); return(returnValue); } // TODO: Updated call of the socket wrench for the new dll. - Ipsit_34 if (swTCP.Status == SocketWrench.SocketStatus.statusDisconnect || swTCP.Status == SocketWrench.SocketStatus.statusUnused) { nError = Convert.ToInt32(swTCP.Connect(HostIP, HostPort, SocketWrench.SocketProtocol.socketStream, TimeOut)); if (nError != 0) { returnValue = false; WriteToLog("Connect method returned an error in Comm class. Cannot connect to " + HostIP + ":" + Convert.ToString(HostPort)); return(returnValue); } // commSystem = System_Renamed; if (commSystem == 1) { TimeOut = Convert.ToByte(Policy_Renamed.FUELONLY_TMT); } else { TimeOut = (byte)5; //default timeout } timeIN = (float)DateAndTime.Timer; while (true) { System.Windows.Forms.Application.DoEvents(); // since this function is used not only by Kickback //If (Timer - timeIN > Policy.KICKBACK_TMT) Or boolIsConnected Then if ((DateAndTime.Timer - timeIN > TimeOut) || boolIsConnected) { break; } } } if (boolIsConnected) { if (commSystem == 1) { WriteToLog("Connected to FuelOnly Server " + HostIP + ":" + Convert.ToString(HostPort)); } if (commSystem == 2) { carwashSeqNum = (byte)1; WriteToLog("Connected to the Carwash Server" + HostIP + ":" + Convert.ToString(HostPort)); } } else { WriteToLog("Cannot connect to " + HostIP + ":" + Convert.ToString(HostPort)); } returnValue = boolIsConnected; return(returnValue); }