Netduino+2 Linksprite Camera Serial read problem - Netduino Plus 2 (and Netduino Plus 1) - 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.
Photo

Netduino+2 Linksprite Camera Serial read problem

Serial Linksprite Netduino+2 4.2.1.2 camera TTL

  • Please log in to reply
8 replies to this topic

#1 Benoit Clouet

Benoit Clouet

    New Member

  • Members
  • Pip
  • 4 posts

Posted 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



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 02 January 2013 - 07:55 PM

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

 

toread will never b e 0, cos you only read it once before the loop



#3 Benoit Clouet

Benoit Clouet

    New Member

  • Members
  • Pip
  • 4 posts

Posted 02 January 2013 - 11:56 PM

Yes you're right, this is an error I did when I copy/pasted the code.

 

Anyway, this seems not to be the problem.



#4 Benoit Clouet

Benoit Clouet

    New Member

  • Members
  • Pip
  • 4 posts

Posted 03 January 2013 - 06:58 AM

Shall you need the full source, please see here : http://pastebin.com/qS5jqd0L

 

What is really strange is the fact that the camera works well with an arduino...



#5 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 22 January 2013 - 10:11 AM

this code does not work with np2. I'm using a different lib and im having issues too. I had to go back to the NP1

 

my post

http://forums.netdui...-on-the-plus-2/

 

Is there is an issue here somewhere! the NP2 does not like this camera when trying to get the data out of the camera after its been setup :(



#6 Benoit Clouet

Benoit Clouet

    New Member

  • Members
  • Pip
  • 4 posts

Posted 22 January 2013 - 11:31 PM

Actually I managed to get some random results changing the size of the image chunks I fetch down to 128.

 

const int IN_BUFFER_SIZE = 512;

change into

const int IN_BUFFER_SIZE = 128;

 

However, it is not reliable at this stage.

 

Now I'm going to use a logic level converter since the N+2 is said to be 3.3v and the camera is said to be 5v. I will hopefully get some more reliable communication.



#7 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 23 January 2013 - 10:12 AM

let us know how you get on

 

i just find it strange that the command that fails is when im trying to get the image data out of the camera. Functions that work are.

 

reset

set image size

set baud rate

set compression

take a pic

get image size

stop pic



#8 ash

ash

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts

Posted 25 January 2013 - 09:28 AM

I think secret labs should get a camera to try in order to see whats going on :P



#9 pcamargo

pcamargo

    New Member

  • Members
  • Pip
  • 4 posts

Posted 22 April 2013 - 09:49 PM

We got the ttl camera working on netduino plus 2, however once we connect the ethernet the uart stops working correctly.

 

When the ethernet port is connected the uarts works for small data transfers but fails for big data transfers like the frames of the ttl cameras.

 

This is a bug on the netduino plus 2.







Also tagged with one or more of these keywords: Serial, Linksprite, Netduino+2, 4.2.1.2, camera, TTL

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.