High Speed Ethernet
#1
Posted 17 February 2012 - 01:40 PM
#2
Posted 17 February 2012 - 01:55 PM
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
Posted 19 February 2012 - 02:59 PM
#4
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
Posted 20 February 2012 - 06:32 AM
#6
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
Posted 23 February 2012 - 06:46 AM
#8
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
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
Posted 23 February 2012 - 03:13 PM
#11
Posted 24 February 2012 - 05:51 AM
// 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
Posted 24 February 2012 - 06:03 AM
#13
Posted 24 February 2012 - 07:46 AM
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).after these 3 packages there is a pause of 500 micro seconds.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users