Example #1
0
        public void Open(string driver = null, string device = null)
        {
            IntPtr driverPtr = IntPtr.Zero;
            IntPtr devicePtr = IntPtr.Zero;

            if (driver != null)
            {
                driverPtr = Marshal.StringToHGlobalAnsi(driver);
            }
            if (device != null)
            {
                devicePtr = Marshal.StringToHGlobalAnsi(device);
            }

            Out123.Errors error = Out123NativeMethods.Open(handle, driverPtr, devicePtr);
            if (driverPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(driverPtr);
            }
            if (devicePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(devicePtr);
            }

            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(this);
            }
        }
Example #2
0
        public string GetParamString(Out123.Params aParam)
        {
            long   null_value  = 0; // not interested in int value because want the string value.
            double null_fvalue = 0; // not interested in double value because want the string value.
            IntPtr strPtr      = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref null_value, ref null_fvalue, strPtr);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }

            IntPtr subPtr = Marshal.ReadIntPtr(strPtr);

            if (subPtr == IntPtr.Zero)
            {
                Marshal.FreeHGlobal(strPtr);
                throw new Out123.ErrorException("unknow error");
            }
            else
            {
                string result = Marshal.PtrToStringAnsi(subPtr);
                Marshal.FreeHGlobal(strPtr);
                return(result);
            }
        }
Example #3
0
        public void TestLastErrorCodeOK()
        {
            Out123 handle = new Out123();

            Out123.Errors result = handle.LastErrorCode();
            Assert.AreEqual(Out123.Errors.OK, result);
        }
Example #4
0
        public IEnumerable <Out123.Driver> Drivers()
        {
            IntPtr namesPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr descsPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.Drivers(handle, namesPtr, descsPtr);
            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(namesPtr);
                Marshal.FreeHGlobal(descsPtr);
                throw new Out123.ErrorException(this);
            }

            IntPtr namesPtrDeref = Marshal.ReadIntPtr(namesPtr);
            IntPtr descsPtrDeref = Marshal.ReadIntPtr(descsPtr);
            int    offset        = 0;

            while (true)
            {
                IntPtr namePtr = Marshal.ReadIntPtr(namesPtrDeref, offset);
                IntPtr descPtr = Marshal.ReadIntPtr(descsPtrDeref, offset);
                if (namePtr == IntPtr.Zero)
                {
                    yield break;
                }

                String        name   = Marshal.PtrToStringAnsi(namePtr);
                String        desc   = Marshal.PtrToStringAnsi(descPtr);
                Out123.Driver driver = new Out123.Driver(name, desc);

                yield return(driver);

                offset += Marshal.SizeOf <IntPtr>();
            }
        }
Example #5
0
 public void Start(long rate, int channels, int encoding)
 {
     Out123.Errors error = Out123NativeMethods.Start(handle, new IntPtr(rate), channels, encoding);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(this);
     }
 }
Example #6
0
 public void CopyParamFrom(Out123 other)
 {
     Out123.Errors error = Out123NativeMethods.ParamFrom(handle, other.handle);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Example #7
0
 public void SetParamFloat(Out123.Params aParam, double value)
 {
     Out123.Errors error = Out123NativeMethods.Param(handle, aParam, IntPtr.Zero, value, IntPtr.Zero);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Example #8
0
 public void SetParamInt(Out123.Params aParam, long value)
 {
     Out123.Errors error = Out123NativeMethods.Param(handle, aParam, new IntPtr(value), 0, IntPtr.Zero);
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Example #9
0
 public void SetBufferSize(ulong bufferSize)
 {
     Out123.Errors error = Out123NativeMethods.SetBuffer(handle, new UIntPtr(bufferSize));
     if (error != Out123.Errors.OK)
     {
         throw new Out123.ErrorException(error);
     }
 }
Example #10
0
        public long GetParamInt(Out123.Params aParam)
        {
            long   result      = 0;
            double null_fValue = 0; // not interested in float value because want the int value.
            IntPtr null_sValue = IntPtr.Zero;

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref result, ref null_fValue, null_sValue);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }
            return(result);
        }
Example #11
0
        public double GetParamFloat(Out123.Params aParam)
        {
            long   null_value  = 0;           // not interested in int value because want the doule value.
            double result      = 0;
            IntPtr null_sValue = IntPtr.Zero; // not interested in sValue because want the doule value.

            Out123.Errors error = Out123NativeMethods.GetParam(handle, aParam, ref null_value, ref result, null_sValue);
            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(this);
            }
            return(result);
        }
Example #12
0
        public void SetParamString(Out123.Params aParam, string value)
        {
            IntPtr sValuePtr = IntPtr.Zero;

            if (sValuePtr != null)
            {
                sValuePtr = Marshal.StringToHGlobalAnsi(value);
            }
            Out123.Errors result = Out123NativeMethods.Param(handle, aParam, IntPtr.Zero, 0, sValuePtr);
            if (sValuePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(sValuePtr);
            }
        }
Example #13
0
        public void DriverInfo()
        {
            IntPtr driverPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr devicePtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.DriverInfo(handle, driverPtr, devicePtr);
            Console.WriteLine(error);
            Console.WriteLine(LastErrorCode());
            Console.WriteLine(LastErrorString());

            if (error != Out123.Errors.OK)
            {
                throw new Out123.ErrorException(error);
            }

            /*
             * IntPtr driver = Marshal.ReadIntPtr(driverPtr);
             * IntPtr device = Marshal.ReadIntPtr(devicePtr);
             *
             * Console.WriteLine(driver.ToString());
             * Console.WriteLine(device.ToString());
             */
        }
Example #14
0
        public Out123.DriverInfo GetDriverInfo()
        {
            IntPtr driverPtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr devicePtr = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.DriverInfo(handle, driverPtr, devicePtr);

            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(driverPtr);
                Marshal.FreeHGlobal(devicePtr);
                throw new Out123.ErrorException(error);
            }

            IntPtr driver = Marshal.ReadIntPtr(driverPtr);
            IntPtr device = Marshal.ReadIntPtr(devicePtr);

            Out123.DriverInfo result = new Out123.DriverInfo(Marshal.PtrToStringAnsi(driver), Marshal.PtrToStringAnsi(device));
            Marshal.FreeHGlobal(driverPtr);
            Marshal.FreeHGlobal(devicePtr);

            return(result);
        }
Example #15
0
        public Out123.Format GetFormat()
        {
            IntPtr rate      = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr channels  = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr encoding  = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            IntPtr framesize = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            Out123.Errors error = Out123NativeMethods.GetFormat(handle, rate, channels, encoding, framesize);
            if (error != Out123.Errors.OK)
            {
                Marshal.FreeHGlobal(rate);
                Marshal.FreeHGlobal(channels);
                Marshal.FreeHGlobal(encoding);
                Marshal.FreeHGlobal(framesize);
                throw new Out123.ErrorException(this);
            }

            Out123.Format result = new Out123.Format(rate.ToInt64(), channels.ToInt32(), encoding.ToInt32(), framesize.ToInt32());
            Marshal.FreeHGlobal(rate);
            Marshal.FreeHGlobal(channels);
            Marshal.FreeHGlobal(encoding);
            Marshal.FreeHGlobal(framesize);
            return(result);
        }
Example #16
0
 internal extern static IntPtr PlainStrError([MarshalAs(UnmanagedType.I4)] Out123.Errors error);