private void btnWriteAll_Click(object sender, EventArgs e) { if (dongle.IsOpen) { Register tempReg; for (int ix = 0; ix < regAddrList.Count; ix++) { tempReg = regMap[regAddrList[ix]]; if (!dongle.writeRegBurst(tempReg.RegAddress, tempReg.ByteValue, tempReg.ByteCount)) { MessageBox.Show("Write Register Failed!", "Warning"); } } } }
private void btn_Reg04_Write_Click(object sender, EventArgs e) { byte length = 0x00; byte startAddress = 0x00; string[] tempParam; byte[] tempData; startAddress = Convert.ToByte(textBox_Reg_StartAddr.Text, 16); length = Convert.ToByte(textBox_Reg_Length.Text, 16); tempParam = this.richTextBox_Reg_Window.Text.Split(":;-".ToCharArray()); if (length > tempParam.Length) { length = Convert.ToByte(tempParam.Length); } tempData = new byte[length]; for (int i = 0; i < length; i++) { tempData[i] = Convert.ToByte(tempParam[i], 16); } if (!myDongle.writeRegBurst(startAddress, tempData, length)) { MessageBox.Show("Write Register Failed!", "Waning"); } }
private void btn_Script_Excute_Click(object sender, EventArgs e) { try { byte addr = 0x00; byte value = 0x00; byte[] data; //byte[] reg = new byte[2]; string[] AllCommands = this.richtxt_ScriptView.Text.Split('\n'); string[] parameters; SCRIPT_COMMAND cmdType; bool firstRW = true; int wrCount = 0; for (int i = 0; i < AllCommands.Length; i++) { cmdType = SCRIPT_COMMAND.None; #region TI Script parameters = AllCommands[i].TrimEnd().Split(":; ".ToCharArray()); if (parameters == null || parameters.Length <= 1) // if this line is null or comments { continue; } else if (parameters[0].Contains("~")) // if this line is comments { continue; } else { if (byte.TryParse(parameters[0].TrimStart('X'), System.Globalization.NumberStyles.HexNumber, null, out addr)) { data = new byte[parameters.Length - 1]; for (int ix_data = 1; ix_data < parameters.Length; ix_data++) { if (!byte.TryParse(parameters[ix_data], System.Globalization.NumberStyles.HexNumber, null, out data[ix_data - 1])) { MessageBox.Show(String.Format("Wrong data at line {0} : {1}", i + 1, parameters[ix_data])); return; } } cmdType = SCRIPT_COMMAND.TI_WRITE; } else { MessageBox.Show(String.Format("Wrong data at line {0} : {1}", i + 1, parameters[0])); return; } } #endregion if (cmdType == SCRIPT_COMMAND.None) { cmdType = ScriptDecodeCommand(AllCommands[i], out parameters); } if (cmdType != SCRIPT_COMMAND.None) { switch (cmdType) { case SCRIPT_COMMAND.TI_WRITE: if (wrCount++ % 10 == 0) { if (myRegOp != null) { myRegOp.RegWrite(addr, data, firstRW, false, false); firstRW = false; } else { dg.writeRegBurst(addr, data, data.Length); } } else { myRegOp.RegWrite_NoAck(addr, data); } //Thread.Sleep(200); break; #region Old Commands case SCRIPT_COMMAND.SINGLE_WRITE: //I2CWrite_Single_OneWire(parameters[0], parameters[1]); //reg[0] = Convert.ToByte(parameters[0], 16); //reg[1] = Convert.ToByte(parameters[1], 16); addr = Convert.ToByte(parameters[0], 16); value = Convert.ToByte(parameters[1], 16); dg.writeRegSingle(addr, value); Thread.Sleep(200); //dg.writeRegBlockSingle(reg, 1); break; case SCRIPT_COMMAND.SINGLE_READ: //tempU32 = oneWrie_device.I2CRead_Single(dev_addr, uint.Parse(parameters[0], NumberStyles.HexNumber)); //if (tempU32 <= 0xFF) //{ // ScriptResult(AllCommands[i], true); // DisplayOperateMes("Reg 0x" + parameters[0] + " == " + tempU32.ToString("X2")); //} //else // ScriptResult(AllCommands[i], false); break; case SCRIPT_COMMAND.BURST_WRITE: addr = Convert.ToByte(parameters[0], 16); byte length = Convert.ToByte(parameters[1], 16); data = new byte[parameters.Length - 2]; for (int j = 0; j < data.Length; j++) { data[j] = Convert.ToByte(parameters[2 + j], 16); } dg.writeRegBurst(addr, data, length); Thread.Sleep(200); break; case SCRIPT_COMMAND.BURST_READ: //data = new uint[uint.Parse(parameters[1], NumberStyles.HexNumber)]; //tempU32 = oneWrie_device.I2CRead_Burst(dev_addr, uint.Parse(parameters[0], NumberStyles.HexNumber), uint.Parse(parameters[1], NumberStyles.HexNumber), data); //if (tempU32 == 0) //{ // ScriptResult(AllCommands[i], true); // opMsg = ""; // for (int j = 0; j < data.Length; ) // { // opMsg += data[j++].ToString("X2") + " "; // if (j % 10 == 0) // opMsg += "\r\n"; // } // DisplayOperateMes(opMsg); //} break; case SCRIPT_COMMAND.SET_RSTB: value = Convert.ToByte(parameters[0], 16); if (dg.IsOpen) { if (value == 1) { dg.setUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_1); } else if (value == 0) { dg.resetUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_1); } } Thread.Sleep(200); break; case SCRIPT_COMMAND.SET_VALID: value = Convert.ToByte(parameters[0], 16); if (dg.IsOpen) { if (value == 1) { dg.setUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_0); } else if (value == 0) { dg.resetUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_0); } } Thread.Sleep(200); break; case SCRIPT_COMMAND.DELAY: UInt32 delay = Convert.ToUInt32(parameters[0]); Thread.Sleep(value); //Thread.Sleep(200); break; #endregion default: break; } } } //myRegOp.PowerOn(); } catch { MessageBox.Show("Excute script failed, please check the device address and commands!"); } }