M
Martin Greul
http://www1.minpic.de/bild_anzeigen.php?id=80889&key=62441166&ende
Hello,
looks well for send the data.
But how can I receive the data and then I need the length.
How is the correct analysis?
public static void Test_Receive()
{
Byte[] bytesReceive = new Byte[1000];
bytesReceive[0] = 0;
bytesReceive[1] = 0;
bytesReceive[2] = 1;
bytesReceive[3] = 109;
int i = 0;
Byte b1 = bytesReceive[0];
Byte b2 = bytesReceive[1];
Byte b3 = bytesReceive[2];
Byte b4 = bytesReceive[3];
// How I get now the length?
}
Greeting Martin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The whole test project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace WA_ByteArray_01
{
class Endian
{
public static short Swap(short v)
{
return (short)(((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00));
}
public static int Swap(int v)
{
uint v2 = (uint)v;
return (int)(((v2 >> 24) & 0x000000FF) |
((v2 >> 8) & 0x0000FF00) |
((v2 << 8) & 0x00FF0000) |
((v2 << 24) & 0xFF000000));
}
public static void Test_Send()
{
Byte[] bytesSend = new Byte[1000];
int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;
}
public static void Test_Receive()
{
Byte[] bytesReceive = new Byte[1000];
bytesReceive[0] = 0;
bytesReceive[1] = 0;
bytesReceive[2] = 1;
bytesReceive[3] = 109;
int i = 0;
Byte b1 = bytesReceive[0];
Byte b2 = bytesReceive[1];
Byte b3 = bytesReceive[2];
Byte b4 = bytesReceive[3];
// How I get now the length?
}
public static void Test_Send_ByteArrayAsReference(ref Byte[]
bytesSend)
{
int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WA_ByteArray_01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Endian.Test_Send();
Endian.Test_Receive();
Byte[] bytesSend = new Byte[1000];
Endian.Test_Send_ByteArrayAsReference(ref bytesSend);
}
}
}
Hello,
looks well for send the data.
But how can I receive the data and then I need the length.
How is the correct analysis?
public static void Test_Receive()
{
Byte[] bytesReceive = new Byte[1000];
bytesReceive[0] = 0;
bytesReceive[1] = 0;
bytesReceive[2] = 1;
bytesReceive[3] = 109;
int i = 0;
Byte b1 = bytesReceive[0];
Byte b2 = bytesReceive[1];
Byte b3 = bytesReceive[2];
Byte b4 = bytesReceive[3];
// How I get now the length?
}
Greeting Martin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The whole test project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace WA_ByteArray_01
{
class Endian
{
public static short Swap(short v)
{
return (short)(((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00));
}
public static int Swap(int v)
{
uint v2 = (uint)v;
return (int)(((v2 >> 24) & 0x000000FF) |
((v2 >> 8) & 0x0000FF00) |
((v2 << 8) & 0x00FF0000) |
((v2 << 24) & 0xFF000000));
}
public static void Test_Send()
{
Byte[] bytesSend = new Byte[1000];
int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;
}
public static void Test_Receive()
{
Byte[] bytesReceive = new Byte[1000];
bytesReceive[0] = 0;
bytesReceive[1] = 0;
bytesReceive[2] = 1;
bytesReceive[3] = 109;
int i = 0;
Byte b1 = bytesReceive[0];
Byte b2 = bytesReceive[1];
Byte b3 = bytesReceive[2];
Byte b4 = bytesReceive[3];
// How I get now the length?
}
public static void Test_Send_ByteArrayAsReference(ref Byte[]
bytesSend)
{
int i = 365;
// write in big-endian order, regardless of host order
bytesSend[0] = (Byte)(i >> 24);
bytesSend[1] = (Byte)(i >> 16);
bytesSend[2] = (Byte)(i >> 8);
bytesSend[3] = (Byte)i;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WA_ByteArray_01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Endian.Test_Send();
Endian.Test_Receive();
Byte[] bytesSend = new Byte[1000];
Endian.Test_Send_ByteArrayAsReference(ref bytesSend);
}
}
}