public override BaseData Copy() { I2CData data = new I2CData(); data.IsWrite = IsWrite; data.ReadDataLength = ReadDataLength; data.Name = Name; data.Format = Format; data.IsRead = IsRead; data.Address = Address; if (Content != null) { data.Content = (byte[])Content.Clone(); } else { data.Content = null; } data.Comments = Comments; if (WaitInfo != null) { data.WaitInfo = new WaitInfo(WaitInfo); } return(data); }
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(); }
public override BaseData Copy() { I2CData data = new I2CData(); data .IsWrite = IsWrite; data .ReadDataLength = ReadDataLength; data.Name = Name; data.Format = Format; data.IsRead = IsRead; data.Address = Address; if (Content != null) { data.Content = (byte[])Content.Clone(); } else { data.Content = null; } data.Comments = Comments; if (WaitInfo != null) { data.WaitInfo = new WaitInfo(WaitInfo); } return data; }
public frmI2CDataEdit(I2CData data) { InitializeComponent(); mData = data; }
public I2CData Data; // current i2c data //load the configure file public void Load() { try { XmlReader reader = XmlReader.Create("Config.xml"); XmlSerializer serializer = new XmlSerializer(typeof(Configure)); Configure temp = (Configure)serializer.Deserialize(reader); Data = temp.Data; LocationID = temp.LocationID; Opened = temp.Opened; PortName = temp.PortName; reader.Close(); } catch (Exception e) { Debug.Print("Fail to load configure file."); } }
/// <summary> /// Send i2c data /// </summary> /// <param name="data"></param> /// <param name="readLength"></param> /// <returns></returns> public byte[] SendI2C(byte[] writedata, byte readLength) { try { I2CData data = new I2CData(); byte[] data2 = new byte[writedata.Length - 1]; for (int i = 1; i < writedata.Length; i++) { data2[i - 1] = writedata[i]; } data.Content = data2; data.ReadDataLength = readLength; data.IsRead = readLength > 0; data.Address = (byte)(writedata[0] >> 1); mData = data; UpdateGUIFromData(mData.Content); ctlI2CAddress1.Addr7 = mData.Address; chkRead.Checked = mData.IsRead; chkWrite.Checked = mData.IsWrite; numReadLength.Value = mData.ReadDataLength; UpdateData(); if (chkWrite.Checked) { StringBuilder sb = new StringBuilder(); sb.Append("W:"); string format = GetFormat() == emViewFormat.Hex ? "{0:X2} " : "{0:d} "; sb.AppendFormat(format, ctlI2CAddress1.Addr7 * 2); for (int i = 0; i < mData.Content.Length; i++) { sb.AppendFormat(format, mData.Content[i]); } LogText(sb.ToString()); } if (!mBridge.Write((byte)numPort.Value, mData.Address, mData.Content)) { //OnWriteDataError(); throw new Exception("On Write Data Error"); } else { if (chkRead.Checked) { try { byte[] readData = mBridge.ReadData((byte)numPort.Value, ctlI2CAddress1.Addr7, (byte)numReadLength.Value); if (IsFail(readData)) { LogText("Read Data Fail"); } else if (readData != null) { StringBuilder sb = new StringBuilder(); string format = GetFormat() == emViewFormat.Hex ? "{0:X2} " : "{0:d} "; sb.Append("W:"); sb.AppendFormat(format, ctlI2CAddress1.Addr7 * 2 + 1); sb.AppendLine(); sb.Append("R:"); for (int i = 0; i < readData.Length; i++) { sb.AppendFormat(format, readData[i]); } LogText(sb.ToString()); return readData; } } catch (Exception ex) { //OnReadDataError(); throw new Exception("On Read Data Error"); } } } } catch(Exception ex) { LogText(ex.Message); } return null; }
private void btnEdit_Click(object sender, EventArgs e) { UpdateData(); mData.Address = ctlI2CAddress1.Addr7; Controls.frmI2CDataEdit frm = new Controls.frmI2CDataEdit(mData); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { mData = frm.Data; UpdateGUIFromData(mData.Content); ctlI2CAddress1.Addr7 = mData.Address; chkRead.Checked = mData.IsRead; chkWrite.Checked = mData.IsWrite; numReadLength.Value = mData.ReadDataLength; } }
public void Send(I2CData data) { mData = data; UpdateGUIFromData(mData.Content); ctlI2CAddress1.Addr7 = mData.Address; chkRead.Checked = mData.IsRead; chkWrite.Checked = mData.IsWrite; numReadLength.Value = mData.ReadDataLength; Send(); }
public frmI2CDataEdit(I2CData data, frmMain parent) { InitializeComponent(); mData = data; mParent = parent; }