Example #1
0
 public void SetDelay(string noteDelay, double delayDefinition)
 {
     DelayStr = noteDelay.StartsWith("/") ? $@"1{noteDelay}" : noteDelay;
     RefDelay = 120.0 * (120.0 / delayDefinition);
     if (DelayStr.Contains("/"))
     {
         string[] zt = DelayStr.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
         int      z  = StaticFunctionsClass.ToIntDef(zt[0], 0);
         int      t  = StaticFunctionsClass.ToIntDef(zt[1], 1);
         Delay = RefDelay * (((double)z) / ((double)t));
     }
     else if (!string.IsNullOrEmpty(DelayStr))
     {
         int z = StaticFunctionsClass.ToIntDef(DelayStr, 1);
         Delay = RefDelay * z;
     }
     else
     {
         Delay = RefDelay;
     }
 }
Example #2
0
        public void SetDelay(string delay)
        {
            DelayStr = delay.StartsWith("/") ? $@"1{delay}" : delay;

            if (DelayStr.Contains("/"))
            {
                string[] zt = DelayStr.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                int      z  = StaticFunctionsClass.ToIntDef(zt[0], 0);
                int      t  = StaticFunctionsClass.ToIntDef(zt[1], 1);
                Delay = RefDelay * (((double)z) / ((double)t));
            }
            else if (!string.IsNullOrEmpty(DelayStr))
            {
                double dl = StaticFunctionsClass.ToDoubleDef(DelayStr, 1);
                Delay = RefDelay * dl;
            }
            else
            {
                Delay = 1;
            }
            Delay *= Statics.NoteDelayFactor;
        }
Example #3
0
        //Load script file
        private void ButtonLoadScript_Click(object sender, EventArgs e)
        {
            string ScriptFileLine, DelayStr, CommandDes;

            string[] DelayStrArray;
            int      ScriptFileLine1 = 0, Result, CheckInteger;
            bool     Error = false;
            ushort   usCRC = 0, usCrcLen;

            byte[] CommandBuf    = new byte[16];
            byte[] ScriptCommand = new byte[14];

            CommandCount = 0;
            TextBoxCommandScriptDes.Text = "";
            TextBoxCommandScript.Text    = "";
            TextBoxScriptResponse.Text   = "";
            LabelCommandCount.Text       = "0";
            ButtonExecute.Enabled        = false;
            DelayTimeError = false;
            CommandError   = false;
            CommandIDError = false;
            CommandList.Clear();

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "C:\\";
            openFileDialog1.Filter           = "Text Files (.txt)|*.txt";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                System.IO.StreamReader ScriptFile = new System.IO.StreamReader(openFileDialog1.FileName);
                while ((ScriptFileLine = ScriptFile.ReadLine()) != null)
                {
                    ScriptFileLine1++;
                    if (ScriptFileLine1 == 1)
                    {
                        //Check the RFID script file.
                        Result = String.Compare(ScriptFileLine, "#MTI RFID Command Script", true);
                        if (Result != 0)
                        {
                            MessageBox.Show("This is not command script fileļ¼");
                            Error = true;
                            break;
                        }
                    }
                    else
                    {
                        if (ScriptFileLine.Replace(" ", "").Trim().Length != 0)
                        {
                            //Example of script content

                            //#This is a command script sample.
                            //#This is a test file.
                            //43 49 54 4D FF 11 00 00 00 00 00 00 00 00 # comment 1
                            //delay(500)
                            //43 49 54 4D FF 11 01 00 00 00 00 00 00 00 # comment 2

                            //Filter the command script description
                            if (String.Compare(ScriptFileLine[0].ToString(), "#", true) == 0)
                            {
                                TextBoxCommandScriptDes_Refresh(ScriptFileLine.Trim('#'));
                            }
                            else
                            {
                                //Filter the command script "delay" function
                                if (ScriptFileLine.Replace(" ", "").Contains("delay("))
                                {
                                    DelayStr = ScriptFileLine.Trim();
                                    TextBoxCommandScript_Refresh(DelayStr);

                                    //Check first char
                                    if (DelayStr[0] != 'd')
                                    {
                                        DelayTimeError = true;
                                        ErrorMes(ScriptFileLine);
                                        Error = true;
                                        break;
                                    }

                                    //Check delay(delaytime) format
                                    DelayStrArray = DelayStr.Replace("delay(", "*").Replace(")", "*").Split('*');
                                    if (DelayStrArray.Length > 3)
                                    {
                                        DelayTimeError = true;
                                        ErrorMes(ScriptFileLine);
                                        Error = true;
                                        break;
                                    }
                                    if (DelayStrArray[0].Length > 0 || DelayStrArray[2].Length > 0)
                                    {
                                        DelayTimeError = true;
                                        ErrorMes(ScriptFileLine);
                                        Error = true;
                                        break;
                                    }

                                    //Check delaytime format
                                    CheckInteger = 0;
                                    if (int.TryParse(DelayStrArray[1], out CheckInteger) == false)
                                    {
                                        DelayTimeError = true;
                                        ErrorMes(ScriptFileLine);
                                        Error = true;
                                        break;
                                    }

                                    CommandList.Add("d" + DelayStrArray[1].ToString());
                                }
                                //Filter the command script "COMMAND" function
                                else if (ScriptFileLine.Replace(" ", "").Contains("4349544D"))
                                {
                                    if (CheckCommandFormat(ScriptFileLine))
                                    {
                                        //Compute the command CRC
                                        usCRC         = 0;
                                        CommandDes    = "";
                                        CommandBuf    = new byte[16];
                                        ScriptCommand = new byte[14];
                                        Array.Clear(CommandBuf, 0, CommandBuf.Length);
                                        usCrcLen = (ushort)(ENMU_PKT_INDEX.PKT_CRC - ENMU_PKT_INDEX.PKT_HEADER);

                                        ScriptCommand = StringToByteArray(ScriptFileLine.Substring(0, 28).Replace(" ", ""));
                                        Array.Copy(ScriptCommand, 0, CommandBuf, 0, ScriptCommand.Length);

                                        usCRC          = rfid.Linkage.CrcCul(CommandBuf, 0, (ushort)(usCrcLen * 8));
                                        CommandBuf[14] = (byte)(~usCRC & 0xFF);
                                        CommandBuf[15] = (byte)(~usCRC >> 8 & 0xFF);

                                        CommandList.Add(BitConverter.ToString(CommandBuf, 0, CommandBuf.Length).Replace("-", ""));

                                        if (ScriptFileLine.Contains("#"))
                                        {
                                            CommandDes = ScriptFileLine.Substring(42, ScriptFileLine.Length - 42);
                                        }

                                        TextBoxCommandScript_Refresh(BitConverter.ToString(CommandBuf, 0, CommandBuf.Length).Replace("-", " ") + " " + CommandDes);
                                        ResponseCommand.Add(BitConverter.ToString(CommandBuf, 0, CommandBuf.Length).Replace("-", " ") + " " + CommandDes);
                                        CommandCount++;
                                    }
                                    else
                                    {
                                        TextBoxCommandScript_Refresh(ScriptFileLine);
                                        ErrorMes(ScriptFileLine);
                                        Error = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    TextBoxCommandScript_Refresh(ScriptFileLine);
                                    ErrorMes(ScriptFileLine);
                                    Error = true;
                                    break;
                                }
                            }
                        }
                        if (Error == true)
                        {
                            break;
                        }
                    }
                }
                ScriptFile.Close();
                if (Error == false)
                {
                    ButtonExecute.Enabled  = true;
                    LabelCommandCount.Text = CommandCount.ToString();
                }
            }
        }