473,609 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 TempSensorOffse t;
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 1456
A safe and simple approach would be to use the (strangely named)
System.BitConve rter 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
8448
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 called to_single_byte and to_multi_byte which convert a given multi byte character to single byte and vice versa respectively. thanks in advance mailar
11
3462
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 tend to iterate over subsets of these arrays by walking a pointer and an offset per dimension across their dimensions. I've found that this tends to result in more performance in a portable manner than doing explicit indexing calculations and...
3
11457
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 another form (where the content can be edited). I have defined a property for the editing form using the following Dim m_edicin(3199) As Byte Public Property ebcdicin() As Byte Get
1
2504
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 End Function Private Function UStr2Bstr(UStr)
9
2539
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 bit fields. I then defined enums with the FlagAttribute to generate the 1 and 2 bit fields. Any suggestions or comments on the preceding are welcome. Now, things get better. As I said this structure comes on a communications line so if a...
16
2140
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 sooooo slow. Anyone know how I can speed this functions up? I basically need to convert a byte to string, perform a function on each 'section' of the string, then reconvert it to a byte. The slow part is the conversion to and from byte, not the...
6
39264
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, I want to do the same thing in pure(unmanaged) C++. I searched the Internet but could not find any satisfactory solutions. I am really in need of help! Is there anyone to explain how I can implement these functions by not using .NET library? ...
4
4714
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 has already been covered. I have been trying to learn c# as fast as possible in the last month and in doing so i have been re-visiting old C/C++ problems and trying to overcome them in C#. What i have is a very complex serise of structures. Id...
6
2251
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
8035
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8509
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8374
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6034
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5502
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4002
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4059
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2502
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 we have to send another system

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.