473,473 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
4 1481

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: johnny.karlsson | last post by:
Hi, I'm working on a project were a need to be able to upload firmware to a microcontroller based Ethernet device. But because of the memory constraints the controller can only handle packages of...
7
by: ANaiveProgrammer | last post by:
Hi all I have made the following two structs and size is not according to what is supposed to be, so please ponder over following and identify if im wrong... please also mention what would be...
5
by: Daniel Brown | last post by:
I am coding a managed C# wrapper for an unmanaged C DLL and I am unable to marshal a structure that contains an array of structures. When executed, the following code throws an ArgumentException...
3
by: Karl M | last post by:
Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public:
4
by: Abubakar | last post by:
Hi, I am writing a server in C# and client in C++ (pure, not managed). The communication goes on through sockets. In C# I am using NetworkStream to send text data (by converting it to byte array)...
3
by: GeLLcheN | last post by:
Hello everybody, I've got a little (endian) problem. I'm programming a network-based application, in which I'll use structs, interpreting ethernet packets. My intention is to read the stream...
10
by: Martin Bürkle | last post by:
Hi NG, I have writen a programm using TCP sockets. After i get the connection to another socket I cut the Ethernet cable. Then I send a message. The program doesnt raise any exception. Can...
1
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Can somone tell me why one senario works but not the other? namespace mynamespaceA { public unsafe struct structA { public int a1; } public unsafe class classA
4
by: MTsoul | last post by:
I noticed some quirks with C++ (not sure if this is the same for C). I have: struct A { char a; }; struct B { char b;
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.