private void IICWriteBtn_Click(object sender, EventArgs e) { if ((IICSlaveAddressTextBox.Text == "") || (IICWriteNumTextBox.Text == "")) { MessageBox.Show("Invalid Value !!!"); return; } if ((Convert.ToInt16(IICSlaveAddressTextBox.Text, 16) < 0) || (Convert.ToInt16(IICWriteNumTextBox.Text) < 0)) { MessageBox.Show("Invalid Value !!!"); return; } byte SlaveAddr = Convert.ToByte(IICSlaveAddressTextBox.Text, 16); UInt32 WriteNum = Convert.ToUInt32(IICWriteNumTextBox.Text); UInt16 LastErrCode; IIC_API.IMC_IIC_WRITE Parm_IICW = new IIC_API.IMC_IIC_WRITE(); unsafe { if (IICPrimaryRdBtn.Checked == true) { Parm_IICW.IICType = (uint)IIC_API.BusType.Primary; } else if (IICSmbusIICRdBtn.Checked == true) { Parm_IICW.IICType = (uint)IIC_API.BusType.SmbusIIC; } else { MessageBox.Show("IIC not support all type!"); return; } Parm_IICW.SlaveAddress = SlaveAddr; Parm_IICW.WriteLen = WriteNum; byte[] ResultIIC = new byte[WriteNum]; HexStringToByteArray(IICInputTextBox.Text, ref ResultIIC); fixed(byte *pResultIIC = ResultIIC) { Parm_IICW.WriteBuf = pResultIIC; LastErrCode = IIC_API.IIC_Write(ref Parm_IICW); } if (LastErrCode != IMC_ERR_NO_ERROR) { MessageBox.Show("IMC_IIC_READ fail!"); } } }
private void IICWRCombineBtn_Click(object sender, EventArgs e) { if ((IICReadNumTextBox.Text == "") || (IICWriteNumTextBox.Text == "") || (IICSlaveAddressTextBox.Text == "")) { MessageBox.Show("Invalid Value !!!"); return; } if ((Convert.ToInt16(IICSlaveAddressTextBox.Text, 16) < 0) || (Convert.ToInt16(IICReadNumTextBox.Text) < 0) || (Convert.ToInt16(IICWriteNumTextBox.Text) < 0)) { MessageBox.Show("Invalid Value !!!"); return; } byte SlaveAddr = Convert.ToByte(IICSlaveAddressTextBox.Text, 16); byte ReadNum = Convert.ToByte(IICReadNumTextBox.Text, 16); UInt32 WriteNum = Convert.ToUInt32(IICWriteNumTextBox.Text); UInt16 LastErrCode; IIC_API.IMC_IIC_WRITE_READ_COMBINE Parm_IICRW = new IIC_API.IMC_IIC_WRITE_READ_COMBINE(); unsafe { if (IICPrimaryRdBtn.Checked == true) { Parm_IICRW.IICType = (uint)IIC_API.BusType.Primary; } else if (IICSmbusIICRdBtn.Checked == true) { Parm_IICRW.IICType = (uint)IIC_API.BusType.SmbusIIC; } else { MessageBox.Show("IIC not support all type!"); return; } Parm_IICRW.SlaveAddress = SlaveAddr; Parm_IICRW.ReadLen = ReadNum; Parm_IICRW.WriteLen = WriteNum; byte[] ResultIICR = new byte[ReadNum]; byte[] ResultIICW = new byte[WriteNum]; HexStringToByteArray(IICInputTextBox.Text, ref ResultIICW); fixed(byte *pResultIICR = ResultIICR) fixed(byte *pResultIICW = ResultIICW) { Parm_IICRW.WriteBuf = pResultIICW; Parm_IICRW.ReadBuf = pResultIICR; LastErrCode = IIC_API.IIC_WriteReadCombine(ref Parm_IICRW); } if (LastErrCode != IMC_ERR_NO_ERROR) { MessageBox.Show("IMC_IIC_WriteReadCombine fail!", LastErrCode.ToString()); return; } else { IICResultTextBox.Text = ""; string tempString = ""; for (int i = 0; i < ReadNum; i++) { tempString += Convert.ToString(ResultIICR[i], 16) + " "; } IICResultTextBox.Text = tempString; } } }
private void IICReadBtn_Click(object sender, EventArgs e) { if ((IICSlaveAddressTextBox.Text == "") || (IICReadNumTextBox.Text == "")) { MessageBox.Show("Invalid Value !!!"); return; } if ((Convert.ToInt16(IICSlaveAddressTextBox.Text, 16) < 0) || (Convert.ToInt16(IICReadNumTextBox.Text) < 0)) { MessageBox.Show("Invalid Value !!!"); return; } byte SlaveAddr = Convert.ToByte(IICSlaveAddressTextBox.Text, 16); byte ReadNum = Convert.ToByte(IICReadNumTextBox.Text, 16); UInt16 LastErrCode; if (IICReadNumTextBox.Text == "") { MessageBox.Show("Please input Read number!"); return; } IIC_API.IMC_IIC_READ Parm_IICR = new IIC_API.IMC_IIC_READ(); unsafe { if (IICPrimaryRdBtn.Checked == true) { Parm_IICR.IICType = (uint)IIC_API.BusType.Primary; } else if (IICSmbusIICRdBtn.Checked == true) { Parm_IICR.IICType = (uint)IIC_API.BusType.SmbusIIC; } else { MessageBox.Show("IIC not support all type!"); return; } Parm_IICR.SlaveAddress = SlaveAddr; Parm_IICR.ReadLen = ReadNum; byte[] ResultIIC = new byte[ReadNum]; fixed(byte *pResultIIC = ResultIIC) { Parm_IICR.ReadBuf = pResultIIC; LastErrCode = IIC_API.IIC_Read(ref Parm_IICR); } if (LastErrCode != IMC_ERR_NO_ERROR) { MessageBox.Show("IMC_IIC_READ fail!"); } else { IICResultTextBox.Text = ""; string tempString = ""; for (int i = 0; i < ReadNum; i++) { tempString += Convert.ToString(ResultIIC[i], 16) + " "; } IICResultTextBox.Text = tempString; } } }
private void IIC_Load(object sender, EventArgs e) { UInt16 LastErrCode = IIC_API.IIC_Available(); if (LastErrCode == IMC_ERR_IIC_STATUS_OK_PLATFORM_SUPPORT) { IICPrimaryRdBtn.Enabled = true; IICSmbusIICRdBtn.Enabled = true; MessageBox.Show("IIC support all type!"); } else if (LastErrCode == IMC_ERR_IIC_STATUS_OK_PLATFORM_ONLY_SUPPORT_PRIMARY) { IICPrimaryRdBtn.Enabled = true; IICSmbusIICRdBtn.Enabled = false; IICPrimaryRdBtn.Checked = true; MessageBox.Show("IIC only support primary mode!"); } else if (LastErrCode == IMC_ERR_IIC_STATUS_OK_PLATFORM_ONLY_SUPPORT_SMBUS) { IICPrimaryRdBtn.Enabled = false; IICSmbusIICRdBtn.Enabled = true; IICSmbusIICRdBtn.Checked = true; MessageBox.Show("IIC only support SMBus mode!"); } else if (LastErrCode == IMC_ERR_IIC_STATUS_OK_PLATFORM_NOT_SUPPORT_ALL) { IICPrimaryRdBtn.Enabled = false; IICSmbusIICRdBtn.Enabled = false; IICPrimaryRdBtn.Checked = false; IICSmbusIICRdBtn.Checked = false; MessageBox.Show("IIC not support any type!"); } else { IICPrimaryRdBtn.Enabled = false; IICSmbusIICRdBtn.Enabled = false; IICPrimaryRdBtn.Checked = false; IICSmbusIICRdBtn.Checked = false; MessageBox.Show("Fails to init IIC!"); } byte[] byIICLibVersion = new byte[IIC_API.IMC_LIB_VERSION_SIZE]; LastErrCode = IIC_API.IIC_GetLibVersion(byIICLibVersion); if (LastErrCode != IMC_ERR_NO_ERROR) { MessageBox.Show("Fails to get library version"); return; } int nIICRealSize; IICStaticLibVersionValue.Text = ConvertByte2String(byIICLibVersion, byIICLibVersion.Length, out nIICRealSize); }