示例#1
0
        private static bool ConnectToPtc()
        {
            Console.Write("Starting connection...");

            try
            {
                File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " Connect to ptc start... \n");

                if (Casync == null)
                {
                    Casync          = new pfcls.CCpfcAsyncConnection();
                    AsyncConnection = Casync.GetActiveConnection();

                    if (AsyncConnection == null)
                    {
                        AsyncConnection = Casync.Connect(null, null, null, null);
                        File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " got connection \n");
                    }
                    Console.Write(" Connected!");

                    Session = (pfcls.IpfcBaseSession)AsyncConnection.Session;
                    Console.WriteLine(", Got session!");
                    File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " got session \n");
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + ex + " \n");
                Console.WriteLine("\nMake sure model is opened with Administrator rights. \n" + ex + "\n");
                return(false);
            }

            return(true);
        }
示例#2
0
        private bool ConnectToPtc()
        {
            Console.WriteLine("\nConnecting to PTC...");

            try
            {
                File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " Connect to ptc start... \n");

                if (Casync == null)
                {
                    Casync          = new pfcls.CCpfcAsyncConnection();
                    AsyncConnection = Casync.GetActiveConnection();

                    if (AsyncConnection == null)
                    {
                        AsyncConnection = Casync.Start(_exe /*+ " -g:no_graphics -i:rpc_input"*/, ".");
                        File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " got connection \n");
                    }
                    Session = (pfcls.IpfcBaseSession)AsyncConnection.Session;
                    SetModel();
                    File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + " got session \n");
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(logName, DateTime.UtcNow.ToString("yy.MM.dd HH:mm:ss ") + ex + " \n");
                Console.WriteLine("\nMake sure model is opened with Administrator rights. \n" + ex + "\n");
                return(false);
            }

            return(true);
        }