public FakeSerialPortL7S(SerialPortConfig portConfig)
        {
            if (portConfig == null) throw new ArgumentNullException("portConfig");

            //this.Log = LogManager.GetLogger(this.GetType());

            // http://zachsaw.blogspot.com/2010/07/net-serialport-woes.html
            //ObjectClasses.SerialPortFixer.Execute(portConfig.Name);

            var port = new RJCP.IO.Ports.SerialPortStream(portConfig.Name, portConfig.BaudRate, portConfig.DataBits, RJCP.IO.Ports.Parity.None, RJCP.IO.Ports.StopBits.One);

            //var port = new RJCP.IO.Ports.SerialPortStream(
            //    portConfig.Name,
            //    portConfig.BaudRate,
            //    portConfig.DataBits,
            //    RJCP.IO.Ports.Parity.None,
            //    RJCP.IO.Ports.StopBits.One)
            //{
            //    RtsEnable = portConfig.RtsEnable,
            //    DtrEnable = portConfig.DtrEnable,
            //    ReadTimeout = -1,
            //    WriteTimeout = -1,
            //    ReceivedBytesThreshold = 40
            //};

            //this._internalSerialStream = port.BaseStream;
            this._port = port;
            //this._port..Disposed += new EventHandler(_port_Disposed);

            byte[] mockByteBuffer = new byte[73];
        }
Exemplo n.º 2
0
        static void Main()
        {
            System.Diagnostics.Process MyProcess = System.Diagnostics.Process.GetCurrentProcess();
            MyProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.AboveNormal;

            ObjectClasses.SerialPortConfig serialPortConfig = new ObjectClasses.SerialPortConfig("COM9", 57600, 8, System.IO.Ports.StopBits.One, System.IO.Ports.Parity.None, false, false);
            ObjectClasses.SerialPortIo serialPort = new ObjectClasses.SerialPortIo(serialPortConfig);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);

            if (CalibrationSettings.Default.Debug == false)
            {
                if (!IsRunAsAdministrator())
                {
                    // It is not possible to launch a ClickOnce app as administrator directly, so instead we launch the
                    // app as administrator in a new process.
                    var processInfo = new System.Diagnostics.ProcessStartInfo(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

                    // The following properties run the new process as administrator
                    processInfo.UseShellExecute = true;
                    processInfo.Verb = "runas";

                    // Start the new process
                    try
                    {
                        System.Diagnostics.Process.Start(processInfo);
                    }
                    catch (Exception)
                    {
                        // The user did not allow the application to run as administrator
                        MessageBox.Show("Sorry, this application must be run as Administrator.");
                    }

                    // Shut down the current process
                    Application.Exit();
                }
                else
                {
                    // We are running as administrator
                    // Do normal startup stuff...
                    Application.Run(new frmProgramMDI());

                }
            }
            else
            { 
                //Run Application in Non-Administrator mode to allow debugging
                Application.Run(new frmProgramMDI());
            }
        }
        /// <summary>
        /// Sets up some required Program Settings and Loads the splash screen
        /// </summary>
        private void InitializeProgramSettings()
        {
            //Change Windows Shell to current Application - Registry Setup and Batch File Creation
            //ConfigWindowsShell();

            //Initialize Logger Settings
            XmlConfigurator.Configure();

            //Setup the Display Timeout Settings
            PowerManager.PowerRequest displayPowerRequest = new PowerManager.PowerRequest("SessionActive");
            displayPowerRequest.GetSystemPowerPolicy();
            if (displayPowerRequest != null)
                displayPowerRequest.Dispose();

            //Create a new fixed serial port
            ObjectClasses.SerialPortConfig serialPortConfig = new ObjectClasses.SerialPortConfig(CalibrationSettings.Default.LeftSerialPortName, 57600, 8, System.IO.Ports.StopBits.One, System.IO.Ports.Parity.None, false, false);
            GlobalVariables.leftSerialPort = new ObjectClasses.SerialPortL7S(serialPortConfig);
            GlobalVariables.leftSerialPort.PortName = CalibrationSettings.Default.LeftSerialPortName;
            GlobalVariables.ServoController = new objServoController();

            ObjectClasses.SerialPortConfig serialPortSeatConfig = new ObjectClasses.SerialPortConfig(CalibrationSettings.Default.RightSerialPortName, 57600, 8, System.IO.Ports.StopBits.One, System.IO.Ports.Parity.None, false, false);
            GlobalVariables.rightSerialPort = new ObjectClasses.SerialPortL7S(serialPortSeatConfig);
            GlobalVariables.rightSerialPort.PortName = CalibrationSettings.Default.RightSerialPortName;

            GlobalVariables.serialPortLeftLeg = new ObjectClasses.SerialPortIo(serialPortSeatConfig);
            GlobalVariables.serialPortLeftLeg.PortName = CalibrationSettings.Default.LeftSerialPortName;

            GlobalVariables.serialPortRightLeg = new ObjectClasses.SerialPortIo(serialPortSeatConfig);
            GlobalVariables.serialPortRightLeg.PortName = CalibrationSettings.Default.RightSerialPortName;

            //Sets the Path to the DataDirectory
            //AppDomain.CurrentDomain.SetData("DataDirectory", "C:\\Grucox Data");

            //Load the Startup Splash Screen
            Thread splashThread = new Thread(new ThreadStart(StartSplash));        // Create a new thread from which to start the splash screen form
            splashThread.Start();

            //Twitter Feed - Diagnostics
            DataComms.CreateThreadInstance("Program Startup!");
        }
        public FakeSerialPort(SerialPortConfig portConfig)
        {
            if (portConfig == null) throw new ArgumentNullException("portConfig");

            //this.Log = LogManager.GetLogger(this.GetType());

            // http://zachsaw.blogspot.com/2010/07/net-serialport-woes.html
            //ObjectClasses.SerialPortFixer.Execute(portConfig.Name);

            var port = new SerialPort(
                portConfig.Name,
                portConfig.BaudRate,
                portConfig.Parity,
                portConfig.DataBits,
                portConfig.StopBits)
            {
                RtsEnable = portConfig.RtsEnable,
                DtrEnable = portConfig.DtrEnable,
                ReadTimeout = -1,
                WriteTimeout = -1,
                Handshake = Handshake.XOnXOff,
                ReceivedBytesThreshold = 40
            };

            //this._internalSerialStream = port.BaseStream;
            this._port = port;
            this._port.Disposed += new EventHandler(_port_Disposed);

            byte[] mockByteBuffer = new byte[73];        
        }