Exemple #1
0
 private void rbt_Valid_on_CheckedChanged(object sender, EventArgs e)
 {
     if (rbt_Valid_on.Checked)
     {
         //GPIO on interface
         if (myDongle.IsOpen)
         {
             myDongle.setUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_0);
         }
     }
     else
     {
         //GPIO on interface
         if (myDongle.IsOpen)
         {
             myDongle.resetUserIO(DMDongle.USERIOGROUP.GROUP_A, DMDongle.USERIOPIN.USR_IO_0);
         }
     }
 }
Exemple #2
0
        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!");
            }
        }