473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Structures to byte arrays and vice versa?

ORC
Hi,
I have posted almost the same message in the compact framework group, but it
seems to got lost in a deep message structure :-) so I'll try again:

I'll receive a byte array from a serial port. The byte arrays are actually
serialized structures with alignments of 4 (pack = 4). The structures were
originally written in C++ and looks e.g. like this:
struct Parameters
{
double CreatedDate;
byte Initials[13];
double TempSensorOffset;
double TempSensorSlope;
double MathReverseCoef[3][3];
double MathForwardCoef[3][3];
double StrainsOffset[3];
double StrainsSlope[3];
};

In C++ I just had to create a Union consisting of the structure and a byte
array and then I had directly access to both withhout having to do any kind
of conversion. How should I do this in C# using (I need to both send and
receive so the I'm looking for a code that both serializes and de-serializes
the structure)? The code must be supported by the Compact Framework.

- If your advise is to use the CustomMarshaler from opennetcf then:
Does the Marshaller work in both full and compact framework? - does anyone
have a simple example on how to use it (I have read the "Creating a Custom
Marshaler for the .NET Compact Framework" article , but I'm afraid it is too
heavy for me at the state I am - please clarify.

Thank you very much for your help!
Ole
Nov 16 '05 #1
1 1444
A safe and simple approach would be to use the (strangely named)
System.BitConverter class, which converts between primitive types and byte
arrays.
You'll still have to do some work to return a single byte array for your
class/structure.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mailar | last post by:
HI, Can anyone tell me how is a multi_byte to single byte and vice versa conversion done in DB2. It would be great even if someone can tell me how Oracle does it? Oracle already has functions...
11
by: Bradford Chamberlain | last post by:
I work a lot with multidimensional arrays of dynamic size in C, implementing them using a single-dimensional C array and the appropriate multipliers and offsets to index into it appropriately. I...
3
by: simonc | last post by:
Can you define a property as type Byte array of a specific length? I am trying to pass a byte array which is 3200 bytes in length from one form (in which the bytes are read from a file) to...
1
by: Eugene Anthony | last post by:
Private Function BStr2UStr(BStr) 'Byte string to Unicode string conversion Dim lngLoop BStr2UStr = "" For lngLoop = 1 to LenB(BStr) BStr2UStr = BStr2UStr & Chr(AscB(MidB(BStr,lngLoop,1))) Next...
9
by: Roy Chastain | last post by:
I have a legacy structure that appears on a communications line that has 16 bit, 8 bit, 2 bit and 1 bit fields in it. The best I have been able to do with this was to use FieldOffset for the 8 and...
16
by: Hugh Janus | last post by:
Hi all, I am using the below functions in order to convert strings to bytes and vice versa. I totally ans shamefully stole these functions from this group btw! Anyway, they work great but as...
6
yabansu
by: yabansu | last post by:
Hi all, I think most of you probably know the two .NET framework functions, namely Encoding.GetBytes(string) and Encoding.GetString(byte), to convert string into byte array and vice versa. Now,...
4
by: cleanrabbit | last post by:
Hello! I hate having to do this, because im almost certain there is someone in the world that has come across this problem and i just havent found their solution yet, so i do appologise if this...
6
by: Ole | last post by:
I have a class that I wish to convert into a byte array for sending over a serial line and vice versa - how do I do that? Thanks and regards Ole
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.