Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:32:13+00:00 2026-06-18T06:32:13+00:00

This is the code that I’ve tried to write. I first tell the LinkSprite

  • 0

This is the code that I’ve tried to write. I first tell the “LinkSprite JPEG Camera” to take a picture and then I read the JPEG file contents.

There are no errors and the code is working, but the problem is the result comes was very slowly, I’ve seen “done” i.e. reached to FFD9 after more than 2 minutes. The message of the message box emerged after that much time.

I want get the image which is stored in the camera buffer after sending the “take picture” command and to display it in the form.

My code is:

// public static byte[] ReceivedMsg = new byte[256];
// public static int factor = 0x0000;
// public static UInt16 M = 0;
// public static byte MH = (byte)((M >> 8) & 0xff);
// public static byte ML = (byte)((M >> 0) & 0xff);

private void TakeSnap_Click(object sender, EventArgs e)
{
    // First set the size of the image //
    byte[] sendCmd = new byte[9] { 0x56, 0x00, 0x31, 0x05, 0x04, 0x01, 0x00, 0x19, 0x11 };

    try
    {
        if (!(CamPort.IsOpen)) CamPort.Open(); // If the port is closed!,Open it again //
        CamPort.Write(sendCmd, 0, 9);
        Thread.Sleep(100);// Wait for the camera //
        for (int i = 0; i < 5; i++)
        {
            ReceivedMsg[i] = (byte)(CamPort.ReadByte()); // Store the returned msg //
        }
        if (ReceivedMsg[0].ToString("x") == "76" && ReceivedMsg[1].ToString("x") ==    "0" && ReceivedMsg[2].ToString("x") == "31" && ReceivedMsg[3].ToString("x") == "0" && ReceivedMsg[4].ToString("x") == "0")
        {
            try
            {
                CamPort.DiscardOutBuffer();
                CamPort.DiscardInBuffer();
                byte[] TakePicCmd = new byte[] { 0x56, 0x00, 0x36, 0x01, 0x00 };
                CamPort.Write(TakePicCmd, 0, 5);
                Thread.Sleep(100);// Wait for the camera //
                for (int i = 0; i < 5; i++)
                {
                    ReceivedMsg[i] = (byte)(CamPort.ReadByte());
                }
                if (ReceivedMsg[0].ToString("x") == "76" && ReceivedMsg[1].ToString("x") == "0" && ReceivedMsg[2].ToString("x") == "36" && ReceivedMsg[3].ToString("x") == "0" && ReceivedMsg[4].ToString("x") == "0")
                { 
                    try
                    {
                        CamPort.DiscardOutBuffer();
                        CamPort.DiscardInBuffer();
                        byte[] ReadSizeCommand = new byte[5] { 0x56, 0x00, 0x34, 0x01, 0x00 };
                        CamPort.Write(ReadSizeCommand, 0, 5);
                        Thread.Sleep(100);// Wait for the camera //
                        for (int i = 0; i < 9; i++)
                        {
                            ReceivedMsg[i] = (byte)(CamPort.ReadByte());
                        }
                        if (ReceivedMsg[0].ToString("x") == "76" && ReceivedMsg[1].ToString("x") == "0" && ReceivedMsg[2].ToString("x") == "34" && ReceivedMsg[3].ToString("x") == "0" && ReceivedMsg[4].ToString("x") == "4" && ReceivedMsg[5].ToString("x") == "0" && ReceivedMsg[6].ToString("x") == "0")
                        {   
                            int ImageSize=(((ReceivedMsg[7] & 0x00ff) << 8) | (ReceivedMsg[8] & 0x00ff));
                            try
                            {
                                CamPort.DiscardOutBuffer();
                                CamPort.DiscardInBuffer();
                                byte[] body = new byte[32];
                                byte[] header = new byte[5];
                                bool EndFlag = false;    
                                while (!EndFlag)
                                {
                                    ReadJpegFileCommand();
                                    Thread.Sleep(25);// Wait for the camera //
                                    for (int i = 0; i < 5; i++) header[i] = (byte)CamPort.ReadByte();
                                    ////// If the first 5 bytes matching [76 00 32 00 00] then read the body and display the image //////
                                    if (((int)header[0] == 0x76) && (header[1] == 0x00) && (header[2] == 0x32) && (header[3] == 0x00) && (header[4] == 0x00))
                                    {
                                        for (int i = 0; i < 32; i++)
                                            body[i] = (byte)CamPort.ReadByte();

                                        for (int i = 1; i < body.Length; i++)// check if reached to the last two bytes(FF D9) of the body //
                                        {
                                            if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9))
                                            {
                                                EndFlag = true;
                                                MessageBox.Show("done");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Unexpted Returned value "); // the first 5 bytes does not match the header 
                                    }
                                }
                            }

                            catch (System.Exception ex) { MessageBox.Show(ex.Message); }

                        }
                        else { MessageBox.Show("Reset the camera and start again0 !!"); }
                    }
                    catch (System.Exception ex) { MessageBox.Show(ex.Message); }
                }
                else { MessageBox.Show("Reset the camera and start again1 !!"); }
              }
            catch (System.Exception ex) { MessageBox.Show(ex.Message); }
        }
        else { MessageBox.Show("Reset the camera and try again2 !!"); }
    }
    catch (System.Exception ex) { MessageBox.Show(ex.Message); }
}

//------------------------------------------------------------------------------------//

public void ReadJpegFileCommand()
{
    try
    {
        MH = (byte)(factor / 0x100);
        ML = (byte)(factor % 0x100);
        byte[] ReadImageCommand = new byte[16] { 0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00, MH, ML, 0x00, 0x00, 0x00, 0x20, 0x00, 0x0a };
        CamPort.Write(ReadImageCommand, 0, 16);
        factor += 0x20;
    }

    catch (System.Exception ex) { MessageBox.Show(ex.Message); }
}

The camera is: LinkSprite JPEG Camera

The Camera Manual

Mbed Example (Test program)

How can I reach FFD9 “Quickly” and then how can I display the bytes that are stored in the data array as an image in the picturebox1 that I’ve added to the form?

CamPort is the name of the serial port control.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:32:14+00:00Added an answer on June 18, 2026 at 6:32 am

    What baud rate is your serial port running at? Serial ports are not very fast at transmitting data, even at their highest speeds which is 115200 baud in your case. Even then, serial comms like this can be prone to drop random characters if the baud rate is set to high, or is mismatched on both ends.

    As far as getting it to display in a picture box, you will need to convert the byte array into an Image class object of some type. This isn’t difficult if your input array is correct and not missing any characters. There are a plethora of tutorials on how to do this.

    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/a20fcf5f-9d32-4d32-85d0-c8dd4d978e15

    http://forums.codeguru.com/showthread.php?496495-Manually-created-byte-array-to-picture-box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that is supposed to take an array with some words,
I have this code that creates a PDF file and then emails it. However,
In this code that uses the mongodb-native driver I'd like to increase the value
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that reads from XML file. It gets five strings (groupId,
I have this code that suppose to place the marker by the latlng public
I have this code that where I would normally use one line: if (tableView
I have this code that works in a unit test but doesn't work when
Challenge: I have this code that fails to compile. Can you figure out what's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.