Sending a struct to embeded CPU over the Ethernet

G

Guest

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
 
B

Ben Voigt [C++ MVP]

Eitan said:
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.
 
G

Guest

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 said:
Eitan said:
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
 
B

Ben Voigt [C++ MVP]

Eitan said:
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 said:
Eitan said:
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
 
G

Guest

Thanks,

EitanB

Ben Voigt said:
Eitan said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top