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

High Speed Ethernet


  • Please log in to reply
12 replies to this topic

#1 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 17 February 2012 - 01:40 PM

Hey all, I hope someone could help me a little bit. My Netduino has diffrent operating states like: - reading out a sensing device via I2C - reading an analog input - wait for order - reboot and set initial states - .... When i am reading out the meassured data from I2C or an analog port I build data packages to send then via UDP to a local Pc. The Netduino is just a listener in the network. It reacts to special orders which are sent by the Pc via Labview. Everything works fine I really have no problems to set up a communication or something else... BUT.... And here the Problem starts.... it is just to slow! I am watching at the network traffic with wireshark. As you can see in the picture there are some DHCP packages.. Where do they come from?? And how to shut them down? and if you calculate the frequenc of the measured data... there are just 350 values per second... how is it possible to use the full 10Mbps of the Ethernet?? The Netduino has the IP 192.168.5.100 and LabView 192.168.5.10 The Netduino is listening to the Ethernet if there are some new orders from LabView to execute. but there are no differences in the transition speed if i check for a new order after every measured value or after 1000. I hope someone could help me cause working with the Netduino is really interesting. Thanks in advance Runner

Attached Files



#2 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 17 February 2012 - 01:55 PM

and here is some of the code I am using:

For sending the Data:
public static void sendMessage(string message, Socket send, IPEndPoint Endpoint)
{
    byte[] bytes = Encoding.UTF8.GetBytes(message);
    send.Send(bytes);                            
}

For setting up the connection:
// Checking if there is allready a socket 
public static Socket socketUDP(Socket SOCK)
{
    if (SOCK==null)
    {
        Socket send = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);  // build socket
        return send;                                                                                // take new one
    }
    else return SOCK;     // use old socket
}


public static IPEndPoint Point(Socket send, IPEndPoint IPEND)
{
      if (IPEND==null)
      {
          IPEndPoint Endpoint = new IPEndPoint(IPAddress.Parse("192.168.5.10"), 49000);
          send.Connect(Endpoint);   

          return Endpoint;
      }
      else return IPEND;
}

and at last the measurement..
while(true)
{
    Counter++;

    double PINDATA= GPIO_PIN_A0.Read();
    double value = (PINDATA* maxVoltage) / maxADCValue;
    string Measured= value.ToString("f6");

    DATAOUT= DATAOUT+ "+" + Measured;          // packing data seperated by "+"

    string Order= NDPConnect.getMessage(uCSocket);                    //checking for new orders

    if (Order.Length != 0)
    {
        NDPConnect.sendMessage(DATAOUT, LVSocket, LVEndpoint);  // send data immdiately
        DATAOUT= "";

        return Order;    // go to recieved case
    }


    if (Counter >= 20)
    {
      Counter= 0;
      NDPConnect.sendMessage(DATAOUT, LVSocket, LVEndpoint);  // send data
      DATAOUT= "";

      return "WAIT@ALL#";     // go to wait case
    };
}



#3 seuabb

seuabb

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 February 2012 - 02:59 PM

Hi,Runner, Glad to find a post on the subject of LabVIEW communicating with Netduino. And I'm a new Netduinoer here. Looking forward to finding a solution for your question. Because I'm going to deal with a project similar with yours. I want to use Netuino as a Data Acquisition device for multiple channels of analog signals and also a TCP listener for another device (which will send data to Netuino too). Finally, I need to response to a remote PC for the command of logging data to SD cards. I'm not quite sure whether this project could be implemented by a Netduino plus. However, I think my problem is in some degree part as you described. Maybe I need a router for the TCP/IP communication. Pls give me your advice. Good luck to you.

#4 tunachicken27

tunachicken27

    Member

  • Members
  • PipPip
  • 17 posts

Posted 20 February 2012 - 12:23 AM

and here is some of the code I am using:

For sending the Data:

public static void sendMessage(string message, Socket send, IPEndPoint Endpoint)
{
    byte[] bytes = Encoding.UTF8.GetBytes(message);
    send.Send(bytes);                            
}

For setting up the connection:
// Checking if there is allready a socket 
public static Socket socketUDP(Socket SOCK)
{
    if (SOCK==null)
    {
        Socket send = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);  // build socket
        return send;                                                                                // take new one
    }
    else return SOCK;     // use old socket
}


public static IPEndPoint Point(Socket send, IPEndPoint IPEND)
{
      if (IPEND==null)
      {
          IPEndPoint Endpoint = new IPEndPoint(IPAddress.Parse("192.168.5.10"), 49000);
          send.Connect(Endpoint);   

          return Endpoint;
      }
      else return IPEND;
}

and at last the measurement..
while(true)
{
    Counter++;

    double PINDATA= GPIO_PIN_A0.Read();
    double value = (PINDATA* maxVoltage) / maxADCValue;
    string Measured= value.ToString("f6");

    DATAOUT= DATAOUT+ "+" + Measured;          // packing data seperated by "+"

    string Order= NDPConnect.getMessage(uCSocket);                    //checking for new orders

    if (Order.Length != 0)
    {
        NDPConnect.sendMessage(DATAOUT, LVSocket, LVEndpoint);  // send data immdiately
        DATAOUT= "";

        return Order;    // go to recieved case
    }


    if (Counter >= 20)
    {
      Counter= 0;
      NDPConnect.sendMessage(DATAOUT, LVSocket, LVEndpoint);  // send data
      DATAOUT= "";

      return "WAIT@ALL#";     // go to wait case
    };
}


The general rule with high-performance managed code is to keep memory allocations to a min. I see that you're creating string at the beginning of the loop (memory allocation), then during encoding you're converting string to byte array (memory allocation). I wouldn't be surprised if the garbage collector kicks in every few packets to free up resources, and thats whats slowing down the throughput, not to mention all the memory allocations to begin with.

I would move some of this code, especially encoding and string to native/interop. That way there is minimal overhead processing the message. It will be a harder to write than the current code but you'll get performance boost.

#5 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 20 February 2012 - 06:32 AM

Good day everyone! @tunachicken27: i will try this in the next days and rewrite the code. I am not really good at programming. (what everyone could see in my code) but im trying to get better... @seuabb: i have tried a communication viw TCP befor but due to the "handshake" protocol of the TCP i thought that UDP would be better. also the handshake failed some times with LabView. But it was really great when the Netduino and LabView "talked" the first time with each other... In your application we don´t want to save data on the SD Card... For the project at the University we want to setup a host PC and several Netduinos. The Netduinos are used as local sensing devices and the PC with LabView running as Master in the network.... But at the moment we are just building up an prototype to check the performance. Thanks to all!

#6 seuabb

seuabb

    Member

  • Members
  • PipPip
  • 10 posts

Posted 23 February 2012 - 04:07 AM

Good day everyone!

@tunachicken27: i will try this in the next days and rewrite the code. I am not really good at programming. (what everyone could see in my code) but im trying to get better...

@seuabb: i have tried a communication viw TCP befor but due to the "handshake" protocol of the TCP i thought that UDP would be better. also the handshake failed some times with LabView. But it was really great when the Netduino and LabView "talked" the first time with each other...

In your application we don´t want to save data on the SD Card... For the project at the University we want to setup a host PC and several Netduinos. The Netduinos are used as local sensing devices and the PC with LabView running as Master in the network....
But at the moment we are just building up an prototype to check the performance.

Thanks to all!


Hi, Runner,
Tks for your quick reply.
Look forward to your test results.
Have you ever considered of building up a WSN(wireless sensor network) with Netduino+ and other module?

#7 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 23 February 2012 - 06:46 AM

Hi seuabb, at the moment we want to build a "wired Netduino measuring network"... Further projects are planed but we have a lack of manpower.. :-) my lecturer is searching for students cause he want to build up a wireless network for sensing devices and he wants to create sensing devices which are sending data via GPRS... btw: really big thanks to tunachicken27!!! i have rewritten the code (still working on it) but at the moment i have increased the value output from 350 values / second to approximately 2500... also found some more places to optimize... :-) Runner.... P.S.: for everyone who wants to use the code from above... DON´T DO IT!!! :-)

#8 tunachicken27

tunachicken27

    Member

  • Members
  • PipPip
  • 17 posts

Posted 23 February 2012 - 08:49 AM

btw:
really big thanks to tunachicken27!!!
i have rewritten the code (still working on it)
but at the moment i have increased the value output from 350 values / second to approximately 2500...


Glad I could be of help! So did you use interop or just optimized the managed/C# code?

#9 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 23 February 2012 - 09:10 AM

Glad I could be of help! So did you use interop or just optimized the managed/C# code?


Unfortunately i have to admit that this was the easiest way:

took my brain out of the desk and used it for programming.. :-)

my code was full of converting functions...
e.g.:
i recieved a byte array converted it to a string...
then i separated the string to a string array and converted it again to byte or int or something else...
same procedure for sending data...
i don´t know why i have done things like that...

after all i have to laugh about the mess of code i´ve created.. :-)

therefore the warning: Do not use my code!

#10 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 23 February 2012 - 03:13 PM

Short question... we are sampling data via I2C with a bus frequence of 400kHz it works really good and we get the right data out of the sensing device. But when i take a look at the communication there is a pause between each "bus package" one package consists of the order from the netduino ( 1 byte) and the response from the sensor (2 byte) after these 3 packages there is a pause of 500 micro seconds. Is there any chance to reduce this pause? kind regards Runner

#11 Runner

Runner

    Member

  • Members
  • PipPip
  • 21 posts

Posted 24 February 2012 - 05:51 AM

forgot to add some code... sorry

// setup for I2C

ushort Address = 0x80 >> 1;
int ICSpeed = 400;
           
var Duino = new Microsoft.SPOT.Hardware.I2CDevice(new Microsoft.SPOT.Hardware.I2CDevice.Configuration(Address, ICSpeed));

var commands = new Microsoft.SPOT.Hardware.I2CDevice.I2CTransaction[]
{
   Microsoft.SPOT.Hardware.I2CDevice.CreateWriteTransaction(Register),      //Order to read out the INA226
   Microsoft.SPOT.Hardware.I2CDevice.CreateReadTransaction(buffer),            // Recieve answer from INA226
};


// routine for reading out the I2C sensing device

    while (Shunt < ClusterSize)
    {
        Duino.Execute(commands, 1);   // I2C transmittion

        DATAOUT[Shunt++] = buffer[0];
        DATAOUT[Shunt++] = buffer[1];
    }
after the .Execute command there is the pause....
or takes the netduino so much time to write the two byte from buffer to dataout?

#12 tunachicken27

tunachicken27

    Member

  • Members
  • PipPip
  • 17 posts

Posted 24 February 2012 - 06:03 AM

I think someone else should reply here...as I have No experience with I2C.

#13 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 24 February 2012 - 07:46 AM

after these 3 packages there is a pause of 500 micro seconds.

IMHO that is the execution of the managed code between two consecutive I2C calls in you loop: accessing the buffers and evaluating the loop condition. Provided that one CIL instruction takes roughly 50 µs to execute, 500 µs translates into ~10 instructions which seems to be reasonable. You might be able to reduce this a little bit by optimizing the managed code (decrease the number of CIL instructions needed to be executed - e.g. unroll the loop, use larger data types for 'bulk' transfers or copy the buffers at once using Array.Copy(), Utility.CombineArrays() etc.). Also, make sure to inspect the Release code and measure first - in some cases, the time it takes to execute a particular sequence of instructions differs from what is expected (e.g. by comparison with similar code in C/C++ or assembly).




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.