467,912 Members | 1,665 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,912 developers. It's quick & easy.

Sending a struct to embeded CPU over the Ethernet

Hello,

I need to send a "struct" to an embeded CPU over the Ethernet.

The struct is defined like this:

[Serializable]
public struct MyStruct
{
public double dVar1;
public bool bVar2;
public int nVar3;
}

What would we the best way to pack it into an "array" and send it? Would
that be through Marshal.Copy!? or any other more effiecient way?

Thanks
EitanB
Sep 24 '07 #1
  • viewed: 1306
Share:
4 Replies

"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
Hello,

I need to send a "struct" to an embeded CPU over the Ethernet.

The struct is defined like this:

[Serializable]
public struct MyStruct
{
public double dVar1;
public bool bVar2;
public int nVar3;
}

What would we the best way to pack it into an "array" and send it? Would
that be through Marshal.Copy!? or any other more effiecient way?
BitConverter and a byte[] the most straightforward.
>
Thanks
EitanB

Sep 24 '07 #2
Hello Ben,

Looking at the online help for BitConverter, I understand that it works for
data types such as int, double, etc. Is there a conversion method for the
whole struct at once or should I do one element at a time?

Thanks
EitanB

"Ben Voigt [C++ MVP]" wrote:
>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
Hello,

I need to send a "struct" to an embeded CPU over the Ethernet.

The struct is defined like this:

[Serializable]
public struct MyStruct
{
public double dVar1;
public bool bVar2;
public int nVar3;
}

What would we the best way to pack it into an "array" and send it? Would
that be through Marshal.Copy!? or any other more effiecient way?

BitConverter and a byte[] the most straightforward.

Thanks
EitanB


Sep 25 '07 #3

"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:96**********************************@microsof t.com...
Hello Ben,

Looking at the online help for BitConverter, I understand that it works
for
data types such as int, double, etc. Is there a conversion method for the
whole struct at once or should I do one element at a time?
You'd have to do it one element at a time. If you have just a few small
structs without too many members, this is the easiest and most
straightforward way.
>
Thanks
EitanB

"Ben Voigt [C++ MVP]" wrote:
>>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:27**********************************@microso ft.com...
Hello,

I need to send a "struct" to an embeded CPU over the Ethernet.

The struct is defined like this:

[Serializable]
public struct MyStruct
{
public double dVar1;
public bool bVar2;
public int nVar3;
}

What would we the best way to pack it into an "array" and send it?
Would
that be through Marshal.Copy!? or any other more effiecient way?

BitConverter and a byte[] the most straightforward.
>
Thanks
EitanB



Sep 25 '07 #4
Thanks,

EitanB

"Ben Voigt [C++ MVP]" wrote:
>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:96**********************************@microsof t.com...
Hello Ben,

Looking at the online help for BitConverter, I understand that it works
for
data types such as int, double, etc. Is there a conversion method for the
whole struct at once or should I do one element at a time?

You'd have to do it one element at a time. If you have just a few small
structs without too many members, this is the easiest and most
straightforward way.

Thanks
EitanB

"Ben Voigt [C++ MVP]" wrote:
>
"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
Hello,

I need to send a "struct" to an embeded CPU over the Ethernet.

The struct is defined like this:

[Serializable]
public struct MyStruct
{
public double dVar1;
public bool bVar2;
public int nVar3;
}

What would we the best way to pack it into an "array" and send it?
Would
that be through Marshal.Copy!? or any other more effiecient way?

BitConverter and a byte[] the most straightforward.


Thanks
EitanB


Sep 25 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by johnny.karlsson | last post: by
7 posts views Thread by ANaiveProgrammer | last post: by
5 posts views Thread by Daniel Brown | last post: by
3 posts views Thread by GeLLcheN | last post: by
10 posts views Thread by Martin BŁrkle | last post: by
1 post views Thread by =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.