Beispiel #1
0
        public void Reset(int hold)
        {
            TTransaction m_FXaction = new TTransaction();

            byte[] dta = new byte[8];

            ControlEndPt.Target  = CyConst.TGT_DEVICE;
            ControlEndPt.ReqType = CyConst.REQ_VENDOR;
            ControlEndPt.Value   = 0xE600;
            ControlEndPt.Index   = 0x0000;

            ControlEndPt.ReqCode = 0xA0;
            dta[0] = (byte)hold;
            int len = 1;

            ControlEndPt.Write(ref dta, ref len);
            len = 1;
            if (m_bRecording && (m_script_file_name != null))
            {
                m_FXaction.AltIntfc  = m_AltIntfc;
                m_FXaction.ConfigNum = m_ConfigNum;
                m_FXaction.IntfcNum  = m_IntfcNum;
                m_FXaction.EndPtAddr = ControlEndPt.Address;
                m_FXaction.Tag       = 0;

                m_FXaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                m_FXaction.CtlReqCode = ControlEndPt.ReqCode;
                m_FXaction.wValue     = ControlEndPt.Value;
                m_FXaction.wIndex     = ControlEndPt.Index;
                m_FXaction.DataLen    = (uint)len;
                m_FXaction.Timeout    = ControlEndPt.TimeOut / 1000;
                m_FXaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                //Write m_FXaction and buffer
                m_FXaction.WriteToStream(m_script_file_name);
                m_FXaction.WriteFromBuffer(m_script_file_name, ref dta, ref len);

                Thread.Sleep(0);
            }


            Thread.Sleep(500);
        }
Beispiel #2
0
        private bool LoadRamHex(string fileName)
        {
            TTransaction m_Xaction = new TTransaction();
            // A .hex file is already in the correct format for the FX2 RAM
            bool rVal = false;

            if (fileName == "VendAX")
                rVal = Util.ParseHexData(VendAX, FwImage, ref ImageLen, ref FwOffset);
            else
                rVal = Util.ParseHexFile(fileName, FwImage, ref ImageLen, ref FwOffset);

            if (rVal)
            {
                ControlEndPt.Target = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType = CyConst.REQ_VENDOR;
                ControlEndPt.ReqCode = 0xA0;
                ControlEndPt.Index = 0;

                Reset(1); // Halt

                ushort chunk = 2048;
                byte[] buffer = new byte[chunk];

                for (ushort i = FwOffset; i < ImageLen; i += chunk)
                {
                    ControlEndPt.Value = i;
                    int len = ((i + chunk) < ImageLen) ? chunk : ImageLen - i;
                    Array.Copy(FwImage, i, buffer, 0, len);

                    ControlEndPt.Write(ref buffer, ref len);

                    if (m_bRecording && (m_script_file_name != null))
                    {
                        m_Xaction.AltIntfc = m_AltIntfc;
                        m_Xaction.ConfigNum = m_ConfigNum;
                        m_Xaction.IntfcNum = m_IntfcNum;
                        m_Xaction.EndPtAddr = ControlEndPt.Address;
                        m_Xaction.Tag = 0;

                        m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                        m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                        m_Xaction.wValue = ControlEndPt.Value;
                        m_Xaction.wIndex = ControlEndPt.Index;
                        m_Xaction.DataLen = (uint)len;
                        m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                        m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                        //Write m_Xaction and buffer
                        m_Xaction.WriteToStream(m_script_file_name);
                        m_Xaction.WriteFromBuffer(m_script_file_name, ref buffer, ref len);
                    }

                }

                Reset(0); // Run

                return true;
            }

            else
                return false;
        }
Beispiel #3
0
        private bool LoadRamHex(string fname, bool blow)
        {
            TTransaction m_Xaction = new TTransaction();

            list.Clear();
            list1.Clear();

            string line, sOffset, tmp;
            int v;

            FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);
            while (!sr.EndOfStream)
            {
                list.Add(sr.ReadLine());
            }
            sr.Close();
            fs.Close();

            int Ramsize = 0x4000;

            // Delete non-data records
            for (int i = list.Count - 1; i >= 0; i--)
            {
                line = (string)list[i];
                if (line.Length > 0)
                {
                    tmp = line.Substring(7, 2);   // Get the Record Type into v
                    v = (int)Util.HexToInt(tmp);
                    if (v != 0) list.Remove(list[i]);   // Data records are type == 0
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                line = (string)list[i];

                // Remove comments
                v = line.IndexOf("//");
                if (v > -1)
                    line = line.Substring(0, v - 1);

                // Build string that just contains the offset followed by the data bytes
                if (line.Length > 0)
                {
                    // Get the offset
                    sOffset = line.Substring(3, 4);

                    // Get the string of data chars
                    tmp = line.Substring(1, 2);
                    v = (int)Util.HexToInt(tmp) * 2;
                    string s = line.Substring(9, v);

                    list1.Add(sOffset + s);
                }

            }

            if (blow) Reset(1);

            byte Reqcode = blow ? (byte)0xA0 : (byte)0xA3;
            ushort windex = 0;

            int iindex = 0;
            string Datastring = "";
            int nxtoffset = 0;
            int xferLen = 0;
            ushort wvalue = 0;

            foreach (string lines in list1)
            {
                line = lines.Substring(0, 4);
                ushort offset = (ushort)Util.HexToInt(line);

                int slen = lines.Length;

                int no_bytes = (slen - 4) / 2;
                int lastaddr = offset + no_bytes;

                //if (blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //    no_bytes = Ramsize - offset;

                //if (!blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //{
                //    no_bytes = lastaddr - (int)Ramsize;
                //    string s = "xxxx" + lines.Substring(slen - (no_bytes * 2), no_bytes * 2);

                //    list1[iindex] = s;
                //    offset = (ushort)Ramsize;
                //    line = "4000";
                //}

                //if ((blow && (offset < Ramsize)) || (!blow && (offset >= Ramsize)))
                if ((blow && (lastaddr < Ramsize)) || (!blow && (lastaddr >= Ramsize)))
                {
                    xferLen += no_bytes;

                    if ((offset == nxtoffset) && (xferLen < 0x1000))
                    {
                        Datastring += lines.Substring(4, no_bytes * 2);
                    }
                    else
                    {
                        int len = Datastring.Length;

                        if (!len.Equals(0))
                        {
                            int bufLen = len / 2;
                            byte[] buf = new byte[bufLen];
                            string d;

                            for (int j = 0; j < bufLen; j++)
                            {
                                d = Datastring.Substring(j * 2, 2);
                                buf[j] = (byte)Util.HexToInt(d);
                            }

                            ControlEndPt.Target = CyConst.TGT_DEVICE;
                            ControlEndPt.ReqType = CyConst.REQ_VENDOR;
                            ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                            ControlEndPt.ReqCode = Reqcode;
                            ControlEndPt.Value = wvalue;
                            ControlEndPt.Index = windex;

                            ControlEndPt.Write(ref buf, ref bufLen);
                            if (m_bRecording && (m_script_file_name != null))
                            {
                                m_Xaction.AltIntfc = m_AltIntfc;
                                m_Xaction.ConfigNum = m_ConfigNum;
                                m_Xaction.IntfcNum = m_IntfcNum;
                                m_Xaction.EndPtAddr = ControlEndPt.Address;
                                m_Xaction.Tag = 0;

                                m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                                m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                                m_Xaction.wValue = ControlEndPt.Value;
                                m_Xaction.wIndex = ControlEndPt.Index;
                                m_Xaction.DataLen = (uint)bufLen;
                                m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                                m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                                //Write m_Xaction and buffer
                                m_Xaction.WriteToStream(m_script_file_name);
                                m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref bufLen);
                            }

                        }

                        wvalue = (ushort)Util.HexToInt(line);
                        Datastring = lines.Substring(4, no_bytes * 2);
                        xferLen = no_bytes;
                    }

                    nxtoffset = offset + no_bytes;
                }
                iindex++;
            }

            int len1 = Datastring.Length;
            if (!len1.Equals(0))
            {
                int bufLen = len1 / 2;
                byte[] buf1 = new byte[bufLen];
                string d;

                for (int j = 0; j < bufLen; j++)
                {
                    d = Datastring.Substring(j * 2, 2);
                    buf1[j] = (byte)Util.HexToInt(d);
                }

                ControlEndPt.Target = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType = CyConst.REQ_VENDOR;
                ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                ControlEndPt.ReqCode = Reqcode;
                ControlEndPt.Value = wvalue;
                ControlEndPt.Index = windex;

                ControlEndPt.Write(ref buf1, ref bufLen);

                if (m_bRecording && (m_script_file_name != null))
                {
                    m_Xaction.AltIntfc = m_AltIntfc;
                    m_Xaction.ConfigNum = m_ConfigNum;
                    m_Xaction.IntfcNum = m_IntfcNum;
                    m_Xaction.EndPtAddr = ControlEndPt.Address;
                    m_Xaction.Tag = 0;

                    m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                    m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                    m_Xaction.wValue = ControlEndPt.Value;
                    m_Xaction.wIndex = ControlEndPt.Index;
                    m_Xaction.DataLen = (uint)bufLen;
                    m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                    m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                    //Write m_Xaction and buffer
                    m_Xaction.WriteToStream(m_script_file_name);
                    m_Xaction.WriteFromBuffer(m_script_file_name, ref buf1, ref bufLen);
                }

            }

            if (blow) Reset(0);

            return true;
        }
Beispiel #4
0
        public void Reset(int hold)
        {
            TTransaction m_Xaction = new TTransaction();
            byte[] dta = new byte[8];

            ControlEndPt.Target = CyConst.TGT_DEVICE;
            ControlEndPt.ReqType = CyConst.REQ_VENDOR;
            ControlEndPt.Value = 0xE600;
            ControlEndPt.Index = 0x0000;

            ControlEndPt.ReqCode = 0xA0;
            dta[0] = (byte)hold;
            int len = 1;
            ControlEndPt.Write(ref dta, ref len);
            if (m_bRecording && (m_script_file_name != null))
            {
                m_Xaction.AltIntfc = m_AltIntfc;
                m_Xaction.ConfigNum = m_ConfigNum;
                m_Xaction.IntfcNum = m_IntfcNum;
                m_Xaction.EndPtAddr = ControlEndPt.Address;
                m_Xaction.Tag = 0;

                m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                m_Xaction.wValue = ControlEndPt.Value;
                m_Xaction.wIndex = ControlEndPt.Index;
                m_Xaction.DataLen = (uint)len;
                m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                //Write m_Xaction and buffer
                m_Xaction.WriteToStream(m_script_file_name);
                m_Xaction.WriteFromBuffer(m_script_file_name, ref dta, ref len);

                Thread.Sleep(0);
            }

            Thread.Sleep(500);
        }
Beispiel #5
0
        private bool Ep0VendorCommand(ref byte[] buf, ref uint buflen, bool IsFromDevice, byte ReqCode, uint Value)
        {
            TTransaction m_Xaction = new TTransaction();

            ControlEndPt.TimeOut = 5000;
            ControlEndPt.Target  = CyConst.TGT_DEVICE;
            ControlEndPt.ReqType = CyConst.REQ_VENDOR;
            if (IsFromDevice)
            {
                ControlEndPt.Direction = CyConst.DIR_FROM_DEVICE;
            }
            else
            {
                ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
            }
            ControlEndPt.ReqCode = ReqCode;
            ControlEndPt.Value   = (ushort)(Value & 0x0000FFFF); // Get 16-bit LSB
            ControlEndPt.Index   = (ushort)(Value >> 16);        // Get 16-bit MSB
            int len = (int)buflen;

            // Handle the case where transfer length is 0 (used to send the Program Entry)
            if (buflen == 0)
            {
                if (m_bRecording && (m_script_file_name != null))
                {
                    m_Xaction.AltIntfc  = m_AltIntfc;
                    m_Xaction.ConfigNum = m_ConfigNum;
                    m_Xaction.IntfcNum  = m_IntfcNum;
                    m_Xaction.EndPtAddr = ControlEndPt.Address;
                    m_Xaction.Tag       = 0;

                    m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                    m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                    m_Xaction.wValue     = ControlEndPt.Value;
                    m_Xaction.wIndex     = ControlEndPt.Index;
                    m_Xaction.DataLen    = (uint)len;
                    m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                    m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                    //Write m_Xaction and buffer
                    m_Xaction.WriteToStream(m_script_file_name);
                    m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref len);
                }
                return(ControlEndPt.XferData(ref buf, ref len));
            }

            else
            {
                bool bRetCode = false;
                int  Stagelen = 0;
                int  BufIndex = 0;
                while (len > 0)
                {
                    if (len >= 65535)
                    {
                        Stagelen = 65535;
                    }
                    else
                    {
                        Stagelen = (len) % 65535;
                    }

                    // Allocate the buffer
                    byte[] StageBuf = new byte[Stagelen];
                    if (!IsFromDevice)
                    {//write operation
                        for (int i = 0; i < Stagelen; i++)
                        {
                            StageBuf[i] = buf[BufIndex + i];
                        }
                    }

                    bRetCode = ControlEndPt.XferData(ref StageBuf, ref Stagelen);
                    if (m_bRecording && (m_script_file_name != null))
                    {
                        m_Xaction.AltIntfc  = m_AltIntfc;
                        m_Xaction.ConfigNum = m_ConfigNum;
                        m_Xaction.IntfcNum  = m_IntfcNum;
                        m_Xaction.EndPtAddr = ControlEndPt.Address;
                        m_Xaction.Tag       = 0;

                        m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                        m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                        m_Xaction.wValue     = ControlEndPt.Value;
                        m_Xaction.wIndex     = ControlEndPt.Index;
                        m_Xaction.DataLen    = (uint)len;
                        m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                        m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                        //Write m_Xaction and buffer
                        m_Xaction.WriteToStream(m_script_file_name);
                        m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref len);
                    }
                    if (!bRetCode)
                    {
                        return(false);
                    }

                    if (IsFromDevice)
                    {//read operation
                        for (int i = 0; i < Stagelen; i++)
                        {
                            buf[BufIndex + i] = StageBuf[i];
                        }
                    }

                    len      -= Stagelen;
                    BufIndex += Stagelen;
                }
            }
            return(true);
        }
Beispiel #6
0
        private bool Ep0VendorCommand(ref byte[] buf, ref uint buflen, bool IsFromDevice, byte ReqCode, uint Value)
        {
            TTransaction m_Xaction = new TTransaction();
            ControlEndPt.TimeOut = 5000;
            ControlEndPt.Target = CyConst.TGT_DEVICE;
            ControlEndPt.ReqType = CyConst.REQ_VENDOR;
            if (IsFromDevice)
                ControlEndPt.Direction = CyConst.DIR_FROM_DEVICE;
            else
                ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
            ControlEndPt.ReqCode = ReqCode;
            ControlEndPt.Value = (ushort)(Value & 0x0000FFFF); // Get 16-bit LSB
            ControlEndPt.Index = (ushort)(Value >> 16);        // Get 16-bit MSB
            int len = (int)buflen;

            // Handle the case where transfer length is 0 (used to send the Program Entry)
            if (buflen == 0)
            {
                if (m_bRecording && (m_script_file_name != null))
                {
                    m_Xaction.AltIntfc = m_AltIntfc;
                    m_Xaction.ConfigNum = m_ConfigNum;
                    m_Xaction.IntfcNum = m_IntfcNum;
                    m_Xaction.EndPtAddr = ControlEndPt.Address;
                    m_Xaction.Tag = 0;

                    m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                    m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                    m_Xaction.wValue = ControlEndPt.Value;
                    m_Xaction.wIndex = ControlEndPt.Index;
                    m_Xaction.DataLen = (uint)len;
                    m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                    m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                    //Write m_Xaction and buffer
                    m_Xaction.WriteToStream(m_script_file_name);
                    m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref len);
                }
                return ControlEndPt.XferData(ref buf, ref len);
            }

            else
            {
                bool bRetCode = false;
                int Stagelen = 0;
                int BufIndex = 0;
                while (len > 0)
                {
                    if (len >= 65535)
                        Stagelen = 65535;
                    else
                        Stagelen = (len) % 65535;

                    // Allocate the buffer
                    byte[] StageBuf = new byte[Stagelen];
                    if (!IsFromDevice)
                    {//write operation
                        for (int i = 0; i < Stagelen; i++)
                            StageBuf[i] = buf[BufIndex + i];
                    }

                    bRetCode = ControlEndPt.XferData(ref  StageBuf, ref Stagelen);
                    if (m_bRecording && (m_script_file_name != null))
                    {
                        m_Xaction.AltIntfc = m_AltIntfc;
                        m_Xaction.ConfigNum = m_ConfigNum;
                        m_Xaction.IntfcNum = m_IntfcNum;
                        m_Xaction.EndPtAddr = ControlEndPt.Address;
                        m_Xaction.Tag = 0;

                        m_Xaction.bReqType = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                        m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                        m_Xaction.wValue = ControlEndPt.Value;
                        m_Xaction.wIndex = ControlEndPt.Index;
                        m_Xaction.DataLen = (uint)len;
                        m_Xaction.Timeout = ControlEndPt.TimeOut / 1000;
                        m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                        //Write m_Xaction and buffer
                        m_Xaction.WriteToStream(m_script_file_name);
                        m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref len);
                    }
                    if (!bRetCode)
                        return false;

                    if (IsFromDevice)
                    {//read operation
                        for (int i = 0; i < Stagelen; i++)
                            buf[BufIndex + i] = StageBuf[i];
                    }

                    len -= Stagelen;
                    BufIndex += Stagelen;
                }

            }
            return true;
        }
Beispiel #7
0
        private bool LoadRamHex(string fileName)
        {
            TTransaction m_Xaction = new TTransaction();
            // A .hex file is already in the correct format for the FX2 RAM
            bool rVal = false;

            if (fileName == "VendAX")
            {
                rVal = Util.ParseHexData(VendAX, FwImage, ref ImageLen, ref FwOffset);
            }
            else
            {
                rVal = Util.ParseHexFile(fileName, FwImage, ref ImageLen, ref FwOffset);
            }

            if (rVal)
            {
                ControlEndPt.Target  = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType = CyConst.REQ_VENDOR;
                ControlEndPt.ReqCode = 0xA0;
                ControlEndPt.Index   = 0;

                Reset(1); // Halt

                ushort chunk  = 2048;
                byte[] buffer = new byte[chunk];

                for (ushort i = FwOffset; i < ImageLen; i += chunk)
                {
                    ControlEndPt.Value = i;
                    int len = ((i + chunk) < ImageLen) ? chunk : ImageLen - i;
                    Array.Copy(FwImage, i, buffer, 0, len);

                    ControlEndPt.Write(ref buffer, ref len);

                    if (m_bRecording && (m_script_file_name != null))
                    {
                        m_Xaction.AltIntfc  = m_AltIntfc;
                        m_Xaction.ConfigNum = m_ConfigNum;
                        m_Xaction.IntfcNum  = m_IntfcNum;
                        m_Xaction.EndPtAddr = ControlEndPt.Address;
                        m_Xaction.Tag       = 0;

                        m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                        m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                        m_Xaction.wValue     = ControlEndPt.Value;
                        m_Xaction.wIndex     = ControlEndPt.Index;
                        m_Xaction.DataLen    = (uint)len;
                        m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                        m_Xaction.RecordSize = (uint)len + TTransaction.TotalHeaderSize;

                        //Write m_Xaction and buffer
                        m_Xaction.WriteToStream(m_script_file_name);
                        m_Xaction.WriteFromBuffer(m_script_file_name, ref buffer, ref len);
                    }
                }

                Reset(0); // Run

                return(true);
            }

            else
            {
                return(false);
            }
        }
Beispiel #8
0
        private bool LoadRamHex(string fname, bool blow)
        {
            TTransaction m_Xaction = new TTransaction();

            list.Clear();
            list1.Clear();

            string line, sOffset, tmp;
            int    v;

            FileStream   fs = new FileStream(fname, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            while (!sr.EndOfStream)
            {
                list.Add(sr.ReadLine());
            }
            sr.Close();
            fs.Close();

            int Ramsize = 0x4000;

            // Delete non-data records
            for (int i = list.Count - 1; i >= 0; i--)
            {
                line = (string)list[i];
                if (line.Length > 0)
                {
                    tmp = line.Substring(7, 2);   // Get the Record Type into v
                    v   = (int)Util.HexToInt(tmp);
                    if (v != 0)
                    {
                        list.Remove(list[i]);           // Data records are type == 0
                    }
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                line = (string)list[i];

                // Remove comments
                v = line.IndexOf("//");
                if (v > -1)
                {
                    line = line.Substring(0, v - 1);
                }

                // Build string that just contains the offset followed by the data bytes
                if (line.Length > 0)
                {
                    // Get the offset
                    sOffset = line.Substring(3, 4);

                    // Get the string of data chars
                    tmp = line.Substring(1, 2);
                    v   = (int)Util.HexToInt(tmp) * 2;
                    string s = line.Substring(9, v);

                    list1.Add(sOffset + s);
                }
            }

            if (blow)
            {
                Reset(1);
            }

            byte   Reqcode = blow ? (byte)0xA0 : (byte)0xA3;
            ushort windex  = 0;

            int    iindex     = 0;
            string Datastring = "";
            int    nxtoffset  = 0;
            int    xferLen    = 0;
            ushort wvalue     = 0;

            foreach (string lines in list1)
            {
                line = lines.Substring(0, 4);
                ushort offset = (ushort)Util.HexToInt(line);

                int slen = lines.Length;

                int no_bytes = (slen - 4) / 2;
                int lastaddr = offset + no_bytes;

                //if (blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //    no_bytes = Ramsize - offset;

                //if (!blow && (offset < Ramsize) && (lastaddr > Ramsize))
                //{
                //    no_bytes = lastaddr - (int)Ramsize;
                //    string s = "xxxx" + lines.Substring(slen - (no_bytes * 2), no_bytes * 2);

                //    list1[iindex] = s;
                //    offset = (ushort)Ramsize;
                //    line = "4000";
                //}

                //if ((blow && (offset < Ramsize)) || (!blow && (offset >= Ramsize)))
                if ((blow && (lastaddr < Ramsize)) || (!blow && (lastaddr >= Ramsize)))
                {
                    xferLen += no_bytes;

                    if ((offset == nxtoffset) && (xferLen < 0x1000))
                    {
                        Datastring += lines.Substring(4, no_bytes * 2);
                    }
                    else
                    {
                        int len = Datastring.Length;


                        if (!len.Equals(0))
                        {
                            int    bufLen = len / 2;
                            byte[] buf    = new byte[bufLen];
                            string d;

                            for (int j = 0; j < bufLen; j++)
                            {
                                d      = Datastring.Substring(j * 2, 2);
                                buf[j] = (byte)Util.HexToInt(d);
                            }

                            ControlEndPt.Target    = CyConst.TGT_DEVICE;
                            ControlEndPt.ReqType   = CyConst.REQ_VENDOR;
                            ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                            ControlEndPt.ReqCode   = Reqcode;
                            ControlEndPt.Value     = wvalue;
                            ControlEndPt.Index     = windex;

                            ControlEndPt.Write(ref buf, ref bufLen);
                            if (m_bRecording && (m_script_file_name != null))
                            {
                                m_Xaction.AltIntfc  = m_AltIntfc;
                                m_Xaction.ConfigNum = m_ConfigNum;
                                m_Xaction.IntfcNum  = m_IntfcNum;
                                m_Xaction.EndPtAddr = ControlEndPt.Address;
                                m_Xaction.Tag       = 0;

                                m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                                m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                                m_Xaction.wValue     = ControlEndPt.Value;
                                m_Xaction.wIndex     = ControlEndPt.Index;
                                m_Xaction.DataLen    = (uint)bufLen;
                                m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                                m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                                //Write m_Xaction and buffer
                                m_Xaction.WriteToStream(m_script_file_name);
                                m_Xaction.WriteFromBuffer(m_script_file_name, ref buf, ref bufLen);
                            }
                        }

                        wvalue     = (ushort)Util.HexToInt(line);
                        Datastring = lines.Substring(4, no_bytes * 2);
                        xferLen    = no_bytes;
                    }

                    nxtoffset = offset + no_bytes;
                }
                iindex++;
            }

            int len1 = Datastring.Length;

            if (!len1.Equals(0))
            {
                int    bufLen = len1 / 2;
                byte[] buf1   = new byte[bufLen];
                string d;

                for (int j = 0; j < bufLen; j++)
                {
                    d       = Datastring.Substring(j * 2, 2);
                    buf1[j] = (byte)Util.HexToInt(d);
                }


                ControlEndPt.Target    = CyConst.TGT_DEVICE;
                ControlEndPt.ReqType   = CyConst.REQ_VENDOR;
                ControlEndPt.Direction = CyConst.DIR_TO_DEVICE;
                ControlEndPt.ReqCode   = Reqcode;
                ControlEndPt.Value     = wvalue;
                ControlEndPt.Index     = windex;

                ControlEndPt.Write(ref buf1, ref bufLen);

                if (m_bRecording && (m_script_file_name != null))
                {
                    m_Xaction.AltIntfc  = m_AltIntfc;
                    m_Xaction.ConfigNum = m_ConfigNum;
                    m_Xaction.IntfcNum  = m_IntfcNum;
                    m_Xaction.EndPtAddr = ControlEndPt.Address;
                    m_Xaction.Tag       = 0;

                    m_Xaction.bReqType   = (byte)(ControlEndPt.Direction | ControlEndPt.ReqType | ControlEndPt.Target);
                    m_Xaction.CtlReqCode = ControlEndPt.ReqCode;
                    m_Xaction.wValue     = ControlEndPt.Value;
                    m_Xaction.wIndex     = ControlEndPt.Index;
                    m_Xaction.DataLen    = (uint)bufLen;
                    m_Xaction.Timeout    = ControlEndPt.TimeOut / 1000;
                    m_Xaction.RecordSize = (uint)bufLen + TTransaction.TotalHeaderSize;

                    //Write m_Xaction and buffer
                    m_Xaction.WriteToStream(m_script_file_name);
                    m_Xaction.WriteFromBuffer(m_script_file_name, ref buf1, ref bufLen);
                }
            }

            if (blow)
            {
                Reset(0);
            }

            return(true);
        }