示例#1
0
        public virtual IFrostedSerialPort CreateAndOpen(string serialPortName, int baudRate, bool DtrEnableOnConnect)
        {
#if __ANDROID__
            //Create an instance of a FrostedSerialPort and open it
            IFrostedSerialPort newPort = Create(serialPortName);

            newPort.BaudRate = baudRate;
            if (DtrEnableOnConnect)
            {
                newPort.DtrEnable = true;
            }

            // Set the read/write timeouts
            newPort.ReadTimeout  = 500;
            newPort.WriteTimeout = 500;
            newPort.Open();

            return(newPort);
#else
            IFrostedSerialPort newPort = Create(serialPortName);

            bool isLinux = !(newPort is FrostedSerialPort) && !IsWindows;
            bool customBaudAssignment = isLinux && baudRate > 115200;

            // Only set serial port .BaudRate when not using Linux workaround
            if (!customBaudAssignment)
            {
                newPort.BaudRate = baudRate;
            }

            if (DtrEnableOnConnect)
            {
                newPort.DtrEnable = true;
            }

            // Set the read/write timeouts
            newPort.ReadTimeout  = 500;
            newPort.WriteTimeout = 500;

            newPort.Open();

            if (customBaudAssignment)
            {
                // Once mono has enforced its ANSI baud rate policy(in SerialPort.Open), reset the baud rate to the user specified
                // value by calling set_baud in libSetSerial.so
                set_baud(serialPortName, baudRate);
            }

            return(newPort);
#endif // ANDROID
        }
        public virtual IFrostedSerialPort CreateAndOpen(string serialPortName, int baudRate, bool DtrEnableOnConnect)
        {
#if __ANDROID__
            //Create an instance of a FrostedSerialPort and open it
            IFrostedSerialPort newPort = Create(serialPortName);

            newPort.BaudRate = baudRate;
            if (DtrEnableOnConnect)
            {
                newPort.DtrEnable = true;
            }

            // Set the read/write timeouts
            newPort.ReadTimeout  = 500;
            newPort.WriteTimeout = 500;
            newPort.Open();

            return(newPort);
#else
            IFrostedSerialPort newPort = Create(serialPortName);

            bool isLinux = !(newPort is FrostedSerialPort) && !IsWindows;

            // Skip BaudRate assignment on Linux to avoid Invalid Baud exception - defaults to 9600
            if (!isLinux)
            {
                newPort.BaudRate = baudRate;
            }

            if (DtrEnableOnConnect)
            {
                newPort.DtrEnable = true;
            }

            // Set the read/write timeouts
            newPort.ReadTimeout  = 500;
            newPort.WriteTimeout = 500;

            newPort.Open();

            if (isLinux)
            {
                // Once mono has enforced its ANSI baud rate policy(in SerialPort.Open), reset the baud rate to the user specified
                // value by calling set_baud in libSetSerial.so
                set_baud(serialPortName, baudRate);
            }

            return(newPort);
#endif // ANDROID
        }
 public void Open()
 {
     port.Open();
 }
		public void PulseRtsLow()
		{
			if (serialPort == null && this.ActivePrinter != null)
			{
				serialPort = FrostedSerialPortFactory.GetAppropriateFactory(ActivePrinterProfile.Instance.ActivePrinter.DriverType).Create(this.ActivePrinter.ComPort);
				serialPort.BaudRate = this.BaudRate;

				// Set the read/write timeouts
				serialPort.ReadTimeout = 500;
				serialPort.WriteTimeout = 500;
				serialPort.Open();

				serialPort.RtsEnable = true;
				serialPort.RtsEnable = false;
				try
				{
					Thread.Sleep(100);
				}
				catch(Exception e)
				{
					// Let's track this issue if possible.
					MatterControlApplication.Instance.ReportException(e, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
				}
				serialPort.RtsEnable = true;
				serialPort.Close();
			}
		}
        public void PulseRtsLow()
        {
            if (serialPort == null && this.ActivePrinter != null)
            {   
                serialPort = FrostedSerialPort.Create(this.ActivePrinter.ComPort);
                serialPort.BaudRate = this.BaudRate;
                if (PrinterConnectionAndCommunication.Instance.DtrEnableOnConnect)
                {
                    serialPort.DtrEnable = true;
                }

                // Set the read/write timeouts
                serialPort.ReadTimeout = 500;
                serialPort.WriteTimeout = 500;
                serialPort.Open();
                
                serialPort.RtsEnable = true;
                serialPort.RtsEnable = false;
                try
                {
                    Thread.Sleep(1);
                }
                catch
                {
                }
                serialPort.RtsEnable = true;
                serialPort.Close();
            }
        }