I'm noob to C#, I've looked at the answers to previous problems similar to this but am still stuck. I need to collect and process 3 arrays of structs that contain arrays of ushort. I made a class to hold my struct:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
struct Wvsamps
{
ushort[] wav1 = new ushort[3];
ushort[] wav2 = new ushort[3];
ushort[] wav3 = new ushort[3];
ushort[] wav4 = new ushort[3];
ushort modes;
uint time;
ushort chkSum;
}
namespace ConsoleApplication1
{
public class LoadSamps
{
Wvsamps[] ldSamps = new Wvsamps[0x800000];
}
}
Compiler gives error:
Error 1 'Wvsamps.wav1': cannot have instance field initializers in structs C:\Users\Hewitt\Desktop\C# Projects\MarshalBytesToStruct\LoadSamps.cs 8 11 MarshalBytesToStruct
I would then like to access and put values in my arrays of structs from my Main program class. I'm doing this up as a console app to try and get a handle for doing this in a Windows Form app.
To expand upon my problem, I will be receiving 32 byte packets 1/sec over a network connection. The actual data in a 32 byte packet will look like this:
0x94, 0xa5, 0xca, 0x62, 0x41, 0x28, 0x4c, 0x93, 0x09, 0x42, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x04, 0x01, 0x40, 0x10, 0x00, 0x00, 0x70, 0x0d, 0x58, 0x3e, 0xc6, 0xd1, 0x07,
As I receive these 32 byte packets I need to put them in an array of Wvsamps struct as shown in my original post. Ideally the Wvsamps struct is 32bytes long. In an old C/C++ embedded solution of this I was able to memcpy the 32byte network packet to a Wvsamps struct in the ldSamps array then increment a ldSamps array index to point to the next available Wvsamps struct in the ldSamps array for the next received packet. I need to accumulate 0x40000 worth of the Wvsamps structs in the ldSamps array so the array needs to be 0x40000 Wvsamps structs long.
I will be accessing the Wvsamps structs from the ldSamps array to plot waveforms in a WinForm, scroll through the waveforms (I've at least go that working with hard coded simulation data) and make measurements. There will also be the added issue that the data I'm receiving comes in Big Endian format and needs to be converted and stored in Little Endian in the Wvsamps structs.
Wvsampsa class and the problem goes away. Any particular reason you thought you needed a struct?