Ejemplo n.º 1
0
 protected void OnBaudRateChange(object sender, Baudrates value)
 {
     if (BaudRateChange != null)
     {
         BaudRateChange(sender, value);
     }
 }
Ejemplo n.º 2
0
 void SetBaudRate(Baudrates val)
 {
     try
     {
         m_serialPort.BaudRate = (int)val;
         m_spParams.Baudrate   = val;
         UpdateUI();
         SaveParam();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка установки скорости порта < " + m_spParams.Name + " >", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
0
        void CbxBaudRateSelectedIndexChanged(object sender, EventArgs e)
        {
            if (m_lockEvents)
            {
                return;
            }
            //
            ComboBox cbx = sender as ComboBox;

            if (cbx == null)
            {
                return;
            }
            //
            Baudrates bdr = (Baudrates)cbx.SelectedItem;

            m_spParams.Baudrate = bdr;
            OnBaudRateChange(this, bdr);
        }
Ejemplo n.º 4
0
      /// <summary>
      /// PCANLight Init function for Plug and Play Hardware.
      /// This function make the following:
      ///		- Activate a Hardware
      ///		- Make a Register Test of 82C200/SJA1000
      ///		- Allocate a Send buffer and a Hardware handle
      ///		- Programs the configuration of the transmit/receive driver
      ///		- Set the Baudrate register
      ///		- Set the Controller in RESET condition
      /// </summary>
      /// <param name="HWType">Which hardware should be initialized</param>
      /// <param name="BTR0BTR1">BTR0-BTR1 baudrate register</param>
      /// <param name="MsgType">f the frame type is standard or extended</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Init(HardwareType HWType, Baudrates BTR0BTR1, FramesType MsgType)
      {
         try
         {
            switch (HWType)
            {
               case HardwareType.PCI_1CH:
                  return (CANResult)PCAN_PCI.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCI_2CH:
                  return (CANResult)PCAN_2PCI.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCC_1CH:
                  return (CANResult)PCAN_PCC.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.PCC_2CH:
                  return (CANResult)PCAN_2PCC.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.USB_1CH:
                  return (CANResult)PCAN_USB.Init((ushort)BTR0BTR1, (int)MsgType);

               case HardwareType.USB_2CH:
                  return (CANResult)PCAN_2USB.Init((ushort)BTR0BTR1, (int)MsgType);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "Init {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Ejemplo n.º 5
0
      /// <summary>
      /// PCANLight Init function for non Plug and Play Hardware.  
      /// This function make the following:
      ///		- Activate a Hardware
      ///		- Make a Register Test of 82C200/SJA1000
      ///		- Allocate a Send buffer and a Hardware handle
      ///		- Programs the configuration of the transmit/receive driver
      ///		- Set the Baudrate register
      ///		- Set the Controller in RESET condition
      /// </summary>
      /// <param name="HWType">Which hardware should be initialized</param>
      /// <param name="BTR0BTR1">BTR0-BTR1 baudrate register</param>
      /// <param name="MsgType">If the frame type is standard or extended</param>
      /// <param name="IO_Port">Input/output Port Address of the hardware</param>
      /// <param name="Interrupt">Interrupt number</param>
      /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
      public static CANResult Init(HardwareType HWType, Baudrates BTR0BTR1, FramesType MsgType, uint IO_Port, ushort Interrupt)
      {
         try
         {
            switch (HWType)
            {
               case HardwareType.ISA_1CH:
                  return (CANResult)PCAN_ISA.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_ISA_SJA, IO_Port, Interrupt);

               case HardwareType.ISA_2CH:
                  return (CANResult)PCAN_2ISA.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_ISA_SJA, IO_Port, Interrupt);

               case HardwareType.DNG:
                  return (CANResult)PCAN_DNG.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_DONGLE_SJA, IO_Port, Interrupt);

               case HardwareType.DNP:
                  return (CANResult)PCAN_DNP.Init((ushort)BTR0BTR1, (int)MsgType, (int)Hardware.HW_DONGLE_PRO, IO_Port, Interrupt);

               // Hardware is not valid for this function
               //
               default:
                  return CANResult.ERR_ILLHW;
            }
         }
         catch (Exception Ex)
         {
            // Error: Dll does not exists or the function is not available
            //
            Tracer.WriteError(TraceGroup.CANBUS, null, "ppInit {0}", Ex.Message + "\"");
            return CANResult.ERR_NO_DLL;
         }
      }
Ejemplo n.º 6
0
    // =================== Methods ====================


    void Awake()
    {
        DontDestroyOnLoad(this);
        arduino = new ArduinoSerialPort(portName, Baudrates.GetBaudrateToInt(baudRate));
    }
Ejemplo n.º 7
0
 void SerialPortDevice_BaudRateChange(object sender, Baudrates value)
 {
     SetBaudRate(value);
 }
Ejemplo n.º 8
0
        void SetUiParams()
        {
            if (m_spParams == null)
            {
                return;
            }
            //
            int selected = -1;

            for (int i = 0; i < cbxSerialPorts.Items.Count; i++)
            {
                string port = cbxSerialPorts.Items[i].ToString();
                if (!string.Equals(port, m_spParams.Name))
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxSerialPorts.SelectedIndex = selected;
            //
            selected = -1;
            for (int i = 0; i < cbxBaudRate.Items.Count; i++)
            {
                Baudrates bdr = (Baudrates)cbxBaudRate.Items[i];
                if (bdr != m_spParams.Baudrate)
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxBaudRate.SelectedIndex = selected;
            //
            selected = -1;
            for (int i = 0; i < cbxDataBits.Items.Count; i++)
            {
                DataBits db = (DataBits)cbxDataBits.Items[i];
                if (db != m_spParams.DataBits)
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxDataBits.SelectedIndex = selected;
            //
            selected = -1;
            for (int i = 0; i < cbxParity.Items.Count; i++)
            {
                Parity pr = (Parity)cbxParity.Items[i];
                if (pr != m_spParams.Parity)
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxParity.SelectedIndex = selected;
            //
            selected = -1;
            for (int i = 0; i < cbxStopBits.Items.Count; i++)
            {
                StopBits pr = (StopBits)cbxStopBits.Items[i];
                if (pr != m_spParams.StopBits)
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxStopBits.SelectedIndex = selected;
            //
            selected = -1;
            for (int i = 0; i < cbxHandshake.Items.Count; i++)
            {
                Handshake hs = (Handshake)cbxHandshake.Items[i];
                if (hs != m_spParams.Handshake)
                {
                    continue;
                }
                //
                selected = i;
                break;
            }
            cbxHandshake.SelectedIndex = selected;
            //
        }
Ejemplo n.º 9
0
        /// <summary>
        /// PCANLight Init function for Plug and Play Hardware.
        /// This function make the following:
        ///		- Activate a Hardware
        ///		- Make a Register Test of 82C200/SJA1000
        ///		- Allocate a Send buffer and a Hardware handle
        ///		- Programs the configuration of the transmit/receive driver
        ///		- Set the Baudrate register
        ///		- Set the Controller in RESET condition
        /// </summary>
        /// <param name="HWType">Which hardware should be initialized</param>
        /// <param name="BTR0BTR1">BTR0-BTR1 baudrate register</param>
        /// <param name="MsgType">f the frame type is standard or extended</param>
        /// <returns>A CANResult value - Error/status of the hardware after execute the function</returns>
        public static CANResult Init(HardwareType HWType, Baudrates BTR0BTR1, FramesType MsgType)
        {
            try
            {
                switch (HWType)
                {
                    case HardwareType.PCI_1CH:
                        return (CANResult)PCAN_PCI.Init((ushort)BTR0BTR1, (int)MsgType);

                    case HardwareType.PCI_2CH:
                        return (CANResult)PCAN_2PCI.Init((ushort)BTR0BTR1, (int)MsgType);

                    case HardwareType.PCC_1CH:
                        return (CANResult)PCAN_PCC.Init((ushort)BTR0BTR1, (int)MsgType);

                    case HardwareType.PCC_2CH:
                        return (CANResult)PCAN_2PCC.Init((ushort)BTR0BTR1, (int)MsgType);

                    case HardwareType.USB_1CH:
                        return (CANResult)PCAN_USB.Init((ushort)BTR0BTR1, (int)MsgType);

                    case HardwareType.USB_2CH:
                        return (CANResult)PCAN_2USB.Init((ushort)BTR0BTR1, (int)MsgType);

                    // Hardware is not valid for this function
                    //
                    default:
                        return CANResult.ERR_ILLHW;
                }
            }
            catch (Exception Ex)
            {
                // Error: Dll does not exists or the function is not available
                //
                System.Windows.Forms.MessageBox.Show("Error: \"" + Ex.Message + "\"");
                return CANResult.ERR_NO_DLL;
            }
        }