Esempio n. 1
0
        /// <summary>
        /// test if it is a i2cBridgeX device by reading eeprom data
        /// </summary>
        /// <param name="comport"></param>
        /// <returns></returns>
        public static bool IsI2CBridgeX(string comport)
        {
            bool       bRtn = false;
            I2CBridgeX x    = new I2CBridgeX();

            x.PortName = comport;
            try
            {
                x.Open();
                if (x.IsOpen)
                {
                    int n = x.GetEE(246);
                    if ((n > 0) && (n & 32) > 0)
                    {
                        bRtn = true;
                    }
                }
            }
            catch
            {
                bRtn = false;
            }
            finally
            {
                x.Close();
            }

            return(bRtn);
        }
Esempio n. 2
0
 /// <summary>
 /// list all bridge x2 and x5
 /// </summary>
 /// <returns></returns>
 public static I2CBridgeX[] EnumBridge()
 {
     SerialDeviceInfo [] info = ListPorts.EnumPorts();
     ArrayList list = new ArrayList();
     try
     {
         for (int i = 0; i < info.Length; i++)
         {
             if (info[i].FriendName.Contains("USB"))
             {
                 bool isI2c = IsI2CBridgeX(info[i].PortName);
                 Debug.Print(isI2c.ToString());
                 if (isI2c)
                 {
                     I2CBridgeX b = new I2CBridgeX();
                     b.PortName = info[i].PortName;
                     list.Add(b);
                 }
             }
         }
     }
     catch
     {
     }
     return (I2CBridgeX[])list.ToArray(typeof(I2CBridgeX));
 }
Esempio n. 3
0
        /// <summary>
        /// list all bridge x2 and x5
        /// </summary>
        /// <returns></returns>
        public static I2CBridgeX[] EnumBridge()
        {
            SerialDeviceInfo [] info = ListPorts.EnumPorts();
            ArrayList           list = new ArrayList();

            try
            {
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FriendName.Contains("USB"))
                    {
                        bool isI2c = IsI2CBridgeX(info[i].PortName);
                        Debug.Print(isI2c.ToString());
                        if (isI2c)
                        {
                            I2CBridgeX b = new I2CBridgeX();
                            b.PortName = info[i].PortName;
                            list.Add(b);
                        }
                    }
                }
            }
            catch
            {
            }
            return((I2CBridgeX[])list.ToArray(typeof(I2CBridgeX)));
        }
Esempio n. 4
0
        private void frmMain_Load(object sender, EventArgs e)
        {

            //InitFtdiControls();
            EnumBridgeX();
            btnScan.Enabled = false;
            btnSend.Enabled = false;
            Configure config = new Configure();
            config.Load();
            mData = config.Data;
            if (i2cBridges != null)
            {
                for (int i = 0; i < i2cBridges.Length; i++)
                {
                    if (i2cBridges[i].LocationID == config.LocationID)
                    {
                        mBridge = i2cBridgeXs[i];
                        cmbI2CBridge.SelectedIndex = i;
                        if (config.Opened)
                        {
                            mBridge.Open();
                            btnScan.Enabled = true;
                            btnSend.Enabled = true;
                        }
                        break;
                    }
                }
            }
            if (mData == null)
            {
                mData = new I2CData();
            }
        
            ctlI2CAddress1.Addr7 = mData.Address;
            UpdateGUIFromData(mData.Content);
            chkWrite.Checked = mData.IsWrite;
            chkRead.Checked = mData.IsRead;
            numReadLength.Value = mData.ReadDataLength;
            SetFormat(mData.Format);
            LoadDevicesConfigure();
        }
Esempio n. 5
0
        private void OpenI2CAdapter()
        {
            int id = cmbI2CBridge.SelectedIndex;
            if (id != -1)
            {
                mBridge = i2cBridgeXs[id];
                mBridge.Open();
                if (mBridge.IsOpen)
                {
                    lbStatus.Text = "Selected I2C Bridge Opened.";
                    btnSend.Enabled = true;
                    btnScan.Enabled = true;
                }
                else
                {
                    btnSend.Enabled = false;
                    btnScan.Enabled = false;
                    lbStatus.Text = "Fail to open selected I2C bridge.";
                }
                Debug.Print(mBridge.IsOpen.ToString());
            }

        }
Esempio n. 6
0
 private void OpenI2CAdapter()
 {
     int id = cmbI2CBridge.SelectedIndex;
     //if (id != -1)
     {
        // mBridge = i2cBridgeXs[id];
         mBridge = new I2CBridgeX();
         mBridge.OpenSetting();
         mBridge.Open();
         //mBridge.Open();
         mBridge.OnReadData += OnReadDataHandler;
         mBridge.OnWriteData += OnSendDataHandler;
         if (mBridge.IsOpen)
         {
             lbStatus.Text = "Selected I2C Bridge Opened.";
             btnSend.Enabled = true;
             btnScan.Enabled = true;
         }
         else
         {
             btnSend.Enabled = false;
             btnScan.Enabled = false;
             lbStatus.Text = "Fail to open selected I2C bridge.";
         }
         lbConnection.Text = mBridge.GetDescription();
         Debug.Print(mBridge.IsOpen.ToString());
     }
 }
Esempio n. 7
0
        /// <summary>
        /// test if it is a i2cBridgeX device by reading eeprom data
        /// </summary>
        /// <param name="comport"></param>
        /// <returns></returns>
        public static bool IsI2CBridgeX(string comport)
        {
            bool bRtn = false;
            I2CBridgeX x = new I2CBridgeX();
            x.PortName = comport;
            try
            {
                x.Open();
                if (x.IsOpen)
                {
                    int n = x.GetEE(246);
                    if ((n > 0) && (n & 32) > 0)
                    {
                        bRtn = true;
                    }
                }
            }
            catch
            {
                bRtn = false;
            }
            finally
            {
                x.Close();
            }

            return bRtn;
        }
Esempio n. 8
0
 public frmScanI2C(I2CBridgeX bridge, byte port)
 {
     InitializeComponent();
     i2cBridge = bridge;
     mPort = port;
 }