Benoit Clouet - Viewing Profile: Topics - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Benoit Clouet

Member Since 16 Dec 2012
Offline Last Active Mar 03 2013 05:48 AM
-----

Topics I've Started

Netduino+2 Linksprite Camera Serial read problem

02 January 2013 - 07:03 PM

Hi there,

 

first of all, I wish everybody a happy new year.

 

Then here's the problem I face using a brand new Netduino+2 using this firmware version "Netduino 4.2.1.2" the problem was the same when I was using the 4.2.1.0 firmware version.

 

I'm trying to communicate with a linksprite TTL camera (see http://www.linksprit...p?id=15&lang=en). When using an arduino the camera works well, apart from the fact that it is damn slow. I was thus hoping to get a substantial speed improvement using a Netduino+2.

 

When using the library available on tinyclr here : http://www.tinyclr.c...share/entry/165 I first notice that the code has to be slightly modified so that the method ReadAllRemaining() works properly (original version throws an exception when reading bytes that are not available, which is strange considering the problem I have). Below, the modified version of this method. Apart from some debug.print added in the Read and Write methods, the rest of the LinkspriteCamera class remains unchanged:

private void ReadAllRemaining(){      int toRead = port.BytesToRead()      while (toRead > 0)      {         Read(junkBuffer, toRead);      }}

 

My problem lies during the actual reading of JPEG data in the method below:

public void GetPicture(ActionBytes bytesAction)        {            Send(SNAP_COMMAND);            if (LookFor(SNAP_OK_RESPONSE))            {                Send(SIZE_COMMAND);                if (LookFor(SIZE_OK_RESPONSE))                {                    //MSB, LSB                    var sizeBytesLength = Read(2);                    int fileSize = (InBuffer[0] << 8) | InBuffer[1];                     int startAddress = 0;                    int bytesRead = 0;                     GET_CHUNK_COMMAND[12] = MSB(IN_BUFFER_SIZE);                    GET_CHUNK_COMMAND[13] = LSB(IN_BUFFER_SIZE);                     bool endReached = false;                    while (!endReached)                    {                        GET_CHUNK_COMMAND[8] = MSB(startAddress);                        GET_CHUNK_COMMAND[9] = LSB(startAddress);                         Send(GET_CHUNK_COMMAND);              /////////////////////////////////////////////////////////////////              // Problem lies during the read operation triggered by this call to LookFor              /////////////////////////////////////////////////////////////////                        if (LookFor(GET_CHUNK_OK_RESPONSE))                        {                            int chunkLength = 0;                            do                            {                                chunkLength = Read();                                 //ditch footer                                Read(junkBuffer, GET_CHUNK_OK_RESPONSE.Length);                                 //publish byte data                                if (chunkLength > 0)                                {                                    bytesRead += chunkLength;                                    if (bytesRead >= fileSize)                                    {                                        endReached = true;                                         chunkLength = FindEnd(chunkLength);                                    }                                     bytesAction(NewArray(chunkLength));                                }                                 startAddress += chunkLength;                             } while (!endReached && chunkLength > 0);                        }                    }                }            }        }

 

The problem is that the read that occurs after the sending of the GET_CHUNK_COMMAND command bytes array during the read operation that follows seems to block forever waiting for some bytes to come from the camera.

 

Any idea why this happen ? Feel free to ask if you need the full source code to be posted.

 

Thanks in advance for your guidance.

 

Benoît


home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.