7 Replies Latest reply on Jul 26, 2018 3:29 AM by SananyaM_56

    fx2lp problem

    gean_3054931

      Hello,

      I have interfaced an image sensor with fx2lp,image data recieved from the fx2lp is not displaying properly in the control center application(GUI PC),i am struggling regarding this,i dont know whether its speed problem or synchronisation problem.please help me to sort out this problem.

      thanks.

      geethanjali.

        • 1. Re: fx2lp problem
          SrinathS_16

          Hello Geethanjali,

           

          - Please let know what is the issue that you are facing.

          - Are you using the CYUSB3 driver ( vendor implementation ) or UVC based implementation.

          - Also, share the code snippet pertaining to reading image data and displaying the same.

           

          Best regards,

          Srinath S

          • 2. Re: fx2lp problem
            gean_3054931

            Hello shrinath,

            I had discussion with you reagrding this fx2lp with hardware setup,its working fine with cc application but frame rate is below 10fps,because of file read and write functions,so this is not our requirement.

            so we go through direct display method in cc application,frame rate is now more than 25 fps,but image shifting (like in the previous case) is happening even cpu is at 12MHz,can you please help me.

             

            regards,

            geetha.

            • 3. Re: fx2lp problem
              SrinathS_16

              Hello Geetha,

               

              Kindly, post the code snippet of the GUI where the data is being read and how the image data is being displayed.

               

              Best regards,

              Srinath S

              • 4. Re: fx2lp problem
                gean_3054931

                Hello shrinath,

                this is the code snippet.

                thank you.

                 

                DataXferBtn.BackColor = Color.LimeGreen;

                            ON = false;

                            DataXferBtn.Text = "STOP";

                            DeviceTreeView.ExpandAll();

                 

                 

                            NumBytesBox.Text = "721920";

                            DeviceTreeView.SelectedNode = DeviceTreeView.Nodes[0].Nodes[0].Nodes[1].Nodes[0].Nodes[0];

                 

                 

                            if (curEndpt == null)

                            {

                                MessageBox.Show("Select <bulk> <iso> <int> endpoint enabled in the device tree.", "No endpoint selected");

                                return;

                            }

                 

                 

                            int bytes = 0;

                 

                 

                            try

                            {

                 

                 

                                if (!NumBytesBox.Text.Contains("-"))

                                {

                                    if (NumBytesBox.Text.Contains("0X") || NumBytesBox.Text.Contains("0x"))

                                        bytes = Convert.ToInt32(NumBytesBox.Text, 16);

                                    else

                                        bytes = Convert.ToInt32(NumBytesBox.Text);

                                }

                                else

                                {

                                    MessageBox.Show("Enter a valid number of bytes to transfer.", "Invalid Bytes to tranfer");

                                    return;

                                }

                            }

                            catch (Exception exc)

                            {

                                if (bytes < 1)

                                {

                                    //Just to remove warning

                                    exc.ToString();

                 

                 

                                    MessageBox.Show("Enter a valid number of bytes to transfer.", "Invalid Bytes to Transfer");

                                    return;

                                }

                            }

                 

                 

                            int length = 721920;// Convert.ToInt32(Console.ReadLine());

                            byte[] buffer = new byte[length];

                            bool bXferCompleted = false;

                 

                 

                            // Setting control endpt direction needs to occur before BuildDataCaption call

                            CyControlEndPoint ctrlEpt = curEndpt as CyControlEndPoint;

                            if (ctrlEpt != null)

                                ctrlEpt.Direction = DirectionBox.Text.Equals("In") ? CyConst.DIR_FROM_DEVICE : CyConst.DIR_TO_DEVICE;

                 

                 

                            // Stuff the output buffer

                            if (!curEndpt.bIn)

                            {

                                string[] hexTokens = XferDataBox.Text.Split(' ');

                                int i = 0;

                 

                 

                                //foreach (string tok in hexTokens)

                                for (int j = 0; j < hexTokens.Length; j++)

                                {

                                    string tok;

                 

                 

                                    try

                                    {

                                        tok = hexTokens[j];

                                    }

                                    catch

                                    {

                                        tok = "";

                                    }

                 

                 

                                    if ((tok.Length > 0) && (bytes > j))

                                    {

                                        try

                                        {

                                            buffer[i++] = (byte)Convert.ToInt32(tok, 16);

                                        }

                                        catch (Exception exc)

                                        {

                                            MessageBox.Show(exc.Message, "Input Error");

                                            return;

                                        }

                                    }

                                }

                            }

                 

                 

                 

                 

                            OutputBox.Text += dataCaption;

                            OutputBox.SelectionStart = OutputBox.Text.Length;

                            OutputBox.ScrollToCaret();

                 

                 

                            curEndpt.TimeOut = 2000;

                 

                 

                            if (ctrlEpt != null)

                            {

                                if (TargetBox.Text.Equals("Device")) ctrlEpt.Target = CyConst.TGT_DEVICE;

                                else if (TargetBox.Text.Equals("Interface")) ctrlEpt.Target = CyConst.TGT_INTFC;

                                else if (TargetBox.Text.Equals("Endpoint")) ctrlEpt.Target = CyConst.TGT_ENDPT;

                                else if (TargetBox.Text.Equals("Other")) ctrlEpt.Target = CyConst.TGT_OTHER;

                 

                 

                                if (ReqTypeBox.Text.Equals("Standard")) ctrlEpt.ReqType = CyConst.REQ_STD;

                                else if (ReqTypeBox.Text.Equals("Class")) ctrlEpt.ReqType = CyConst.REQ_CLASS;

                                else if (ReqTypeBox.Text.Equals("Vendor")) ctrlEpt.ReqType = CyConst.REQ_VENDOR;

                 

                 

                                ctrlEpt.Direction = DirectionBox.Text.Equals("In") ? CyConst.DIR_FROM_DEVICE : CyConst.DIR_TO_DEVICE;

                 

                 

                                try

                                {

                                    ctrlEpt.ReqCode = (byte)Convert.ToInt16(ReqCodeBox.Text, 16); //(byte)Util.HexToInt(ReqCodeBox.Text);

                                    ctrlEpt.Value = (ushort)Convert.ToInt16(wValueBox.Text, 16); //(ushort)Util.HexToInt(wValueBox.Text);

                                    ctrlEpt.Index = (ushort)Convert.ToInt16(wIndexBox.Text, 16); //(ushort)Util.HexToInt(wIndexBox.Text);

                                }

                                catch (Exception exc)

                                {

                                    MessageBox.Show(exc.Message, "Input Error");

                                    return;

                                }

                 

                 

                                bXferCompleted = ctrlEpt.XferData(ref buffer, ref bytes);

                 

                 

                 

                 

                                if (bRecording && (script_stream != null))

                                {

                                    Xaction.ConfigNum = FxDev.Config;

                                    Xaction.IntfcNum = 0;

                                    Xaction.AltIntfc = FxDev.AltIntfc;

                                    Xaction.EndPtAddr = ctrlEpt.Address;

                                    Xaction.Tag = 0;

                 

                 

                                    Xaction.bReqType = (byte)(ctrlEpt.Direction | ctrlEpt.ReqType | ctrlEpt.Target);

                                    Xaction.CtlReqCode = ctrlEpt.ReqCode;

                                    Xaction.wValue = ctrlEpt.Value;

                                    Xaction.wIndex = ctrlEpt.Index;

                                    Xaction.DataLen = (uint)bytes;

                                    Xaction.Timeout = ctrlEpt.TimeOut / 1000;

                                    Xaction.RecordSize = (uint)bytes + TTransaction.TotalHeaderSize;

                 

                 

                                    //Write xaction and buffer

                                    Xaction.WriteToStream(script_stream);

                                    Xaction.WriteFromBuffer(script_stream, ref buffer, ref bytes);

                                }

                            }

                 

                 

                            bool IsPkt = IsPacket.Checked ? true : false;

                 

                 

                            CyBulkEndPoint bulkEpt = curEndpt as CyBulkEndPoint;

                            if (bulkEpt != null)

                            {

                                bXferCompleted = bulkEpt.XferData(ref buffer, ref bytes, IsPkt);

                                CheckForScripting(ref buffer, ref bytes);

                            }

                 

                 

                            CyIsocEndPoint isocEpt = curEndpt as CyIsocEndPoint;

                            if (isocEpt != null)

                            {

                                isocEpt.XferSize = Convert.ToInt32(NumBytesBox.Text);

                                //

                                if (isocEpt.MaxPktSize == 0)

                                {

                                    MessageBox.Show("Please correct MaxPacketSize in Descriptor", "Invalid MaxPacketSize");

                                    return;

                                }

                                int pkts = bytes / isocEpt.MaxPktSize;

                                if ((bytes % isocEpt.MaxPktSize) > 0) pkts++;

                                ISO_PKT_INFO[] Iskpt = new ISO_PKT_INFO[pkts];

                                bXferCompleted = isocEpt.XferData(ref buffer, ref bytes, ref Iskpt);

                                if (bXferCompleted)

                                {

                                    int MainBufOffset = 0;

                                    int tmpBufOffset = 0;

                                    byte[] tmpbuf = new byte[bytes];

                                    // Check all packets and  if Iso in/out packet is not succeeded then don't update the buffer.

                                    for (int i = 0; i < pkts; i++)

                                    {

                                        if (Iskpt[i].Status != 0)

                                        {

                 

                 

                                        }

                                        else if (bytes <= MainBufOffset)

                                        {

                                            // We have already read all the received data.                           

                                        }

                                        else

                                        {

                                            int j = 0;

                                            try

                                            {

                 

                 

                                                for (j = 0; j < Iskpt[i].Length; j++)

                                                {

                                                    tmpbuf[tmpBufOffset] = buffer[MainBufOffset + j]; // get the received/transfered data in the temparary buffer

                                                    tmpBufOffset++;

                                                }

                                            }

                                            catch (Exception pExp)

                                            {

                                                MessageBox.Show(pExp.Message, "Exception Caught");

                                            }

                                        }

                                        MainBufOffset += isocEpt.MaxPktSize;

                                    }

                                    // Now copy the temparary buffer to main buffer to display

                                    for (int x = 0; x < tmpBufOffset; x++)

                                    {

                                        buffer[x] = tmpbuf[x]; // Updated the main buffer with the whatever data has been received / transfered.

                                    }

                                }

                                //bXferCompleted = isocEpt.XferData(ref buffer, ref bytes);               

                                CheckForScripting(ref buffer, ref bytes);

                            }

                 

                 

                            CyInterruptEndPoint intEpt = curEndpt as CyInterruptEndPoint;

                            if (intEpt != null)

                            {

                                bXferCompleted = intEpt.XferData(ref buffer, ref bytes, IsPkt);

                                CheckForScripting(ref buffer, ref bytes);

                            }

                 

                 

                            byte[] lbuffer = new byte[361480];

                            try

                            {

                                for (int i = 0; i < 721920; i++)

                                {

                                    if ((buffer[i] == 0X4D) && (buffer[i + 1] == 0X49) && (buffer[i + 2] == 0X4E) && (buffer[i + 3] == 0X44) && (buffer[i + 4] == 0X46) && (buffer[i + 5] == 0X4C) && (buffer[i + 6] == 0X4F) && (buffer[i + 7] == 0X57))

                                    {

                                        for (int j = i + 8; j < 721920; j++)

                                        {

                                            if ((buffer[j] == 0X4D) && (buffer[j + 1] == 0X49) && (buffer[j + 2] == 0X4E) && (buffer[j + 3] == 0X44) && (buffer[j + 4] == 0X46) && (buffer[j + 5] == 0X4C) && (buffer[j + 6] == 0X4F) && (buffer[j + 7] == 0X57))

                                            {

                                                int Length = (j + 8) - i;

                                            

                                                Buffer.BlockCopy(buffer, i, lbuffer, 0, Length);

                                                if (Length < 361480)

                                                {

                                                    string path = "D:\\jpeg_picture1123.raw";

                                                    File.WriteAllBytes(path, lbuffer);

                                                }

                                                // Desstination = lbuffer;

                                                Random r = new Random();

                                                int width = 752;

                                                int height = 480;

                                                byte[] source = new byte[361480];

                                                byte[] dest = new byte[361480 * 3];

                                                byte[] pixelValues = new byte[width * height * 3];

                                                //Buffer.BlockCopy(buffer,0 ,source,0,1);

                                                pixelValues = dest;

                                                //

                                                source = lbuffer;

                                                bayer2rgb24(dest, source, width, height);

                                                //for (int i = 0; i < pixelValues.Length; ++i)

                                                //{

                                                //    // Just creating random pixel values for test

                                                //    pixelValues[i] = (byte)r.Next(0, 256);

                                                //}

                                                //

                                                //string path1 = "D:\\jpeg_picture.jpg";

                                                //File.WriteAllBytes(path1, pixelValues);

                 

                 

                                                var bmp = CreateBitmapFromBytes(pixelValues, width, height);

                                                if (length >360960)

                                                {

                                                    pictureBox1.Image = bmp;

                                                }

                                                string path1 = "D:";

                                                pictureBox1.Image.Save(path1);

                                                timer1.Start();

                                            }

                                        }

                                    }

                                }

                            }

                            catch (Exception ex)

                            {

                                Console.WriteLine(ex.Message);

                            }

                        }

                • 5. Re: fx2lp problem
                  gean_3054931

                  Hi,

                  what is the issue of this code?

                   

                  regards,

                  geetha.

                  • 6. Re: fx2lp problem
                    gean_3054931

                    Hello,

                    will you suggest any other options?why image shifting/overwrite is happening?

                     

                    regards,

                    geethanjali.

                    • 7. Re: fx2lp problem
                      SananyaM_56

                      Hello Geetha,

                       

                      As per discussion, we need to check on the data received with the default Control center. Please follow up on-

                      Re: fx2lp slavefifo

                       

                      Best Regards,

                      Sananya