Exemplo n.º 1
0
        public static void SendAWave(IntPtr ptr)
        {
            try
            {
                FAMOSDataObject fdo = FAMOSDataObject.FromDLL_WavePointer(ptr);

                String msgStr = "The DLL received the following:" + Environment.NewLine;
                msgStr += String.Format("  Name:    {0}", fdo.Name) + Environment.NewLine;
                msgStr += String.Format("  xUnit:   {0}", fdo.xUnit) + Environment.NewLine;
                msgStr += String.Format("  yUnit:   {0}", fdo.yUnit) + Environment.NewLine;
                msgStr += String.Format("  dX:      {0}", fdo.dX) + Environment.NewLine;
                msgStr += String.Format("  X0:      {0}", fdo.X0) + Environment.NewLine;
                msgStr += String.Format("  Flags:   {0}", fdo.Flags) + Environment.NewLine;
                msgStr += String.Format("  Samples: {0}", fdo.Samples) + Environment.NewLine;
                msgStr += String.Format("  Time:    {0}", fdo.Time) + Environment.NewLine;
                int numToShow = Math.Min(10, (int)fdo.Samples);
                msgStr += String.Format("  Data (first {0}):", numToShow) + Environment.NewLine;
                for (int i = 0; i < numToShow; i++)
                {
                    msgStr += String.Format("    {0}", fdo.y[i]) + Environment.NewLine;
                }

                MessageBox.Show(msgStr);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Houston..." + Environment.NewLine + ex.ToString());
            }
        }
Exemplo n.º 2
0
        public static IntPtr GetAWave(string fileName)
        {
            FAMOSDataObject tempFDO = new FAMOSDataObject();

            tempFDO.Name    = "Testing...";
            tempFDO.xUnit   = "Seconds";
            tempFDO.yUnit   = "Volts";
            tempFDO.X0      = 0;
            tempFDO.dX      = 0.01F;
            tempFDO.Flags   = 0;
            tempFDO.Time    = 0;
            tempFDO.Samples = 100;
            tempFDO.y       = new float[100];
            for (int i = 0; i < 100; i++)
            {
                tempFDO.y[i] = i;
            }

            try
            {
                IntPtr result = tempFDO.ToDLL_WavePointer();
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Houston..." + Environment.NewLine + ex.ToString());
                return(default(IntPtr));
            }
        }
Exemplo n.º 3
0
        public static FAMOSDataObject FromDLL_WavePointer(IntPtr ptr)
        {
            DLL_Wave        dllWave = (DLL_Wave)Marshal.PtrToStructure(ptr, typeof(DLL_Wave));
            FAMOSDataObject result  = new FAMOSDataObject();

            result.xUnit   = TrimNullTerminatedString(dllWave.xUnit);
            result.yUnit   = TrimNullTerminatedString(dllWave.yUnit);
            result.Name    = TrimNullTerminatedString(dllWave.Name);
            result.dX      = dllWave.dX;
            result.X0      = dllWave.X0;
            result.Flags   = dllWave.Flags;
            result.Samples = dllWave.Samples;
            result.Time    = dllWave.Time;

            var newPtr = new IntPtr(ptr.ToInt32() + 56); // move to first

            result.y = new Single[dllWave.Samples];
            Marshal.Copy(newPtr, result.y, 0, result.y.Length);

            return(result);
        }