1
0

2 Commits e0d4a04631 ... 92b4255370

Autor SHA1 Nachricht Datum
  luo 92b4255370 合并冲突 vor 4 Wochen
  luo 7f7b3b7d2b fpga读写改为单线程模式 vor 4 Wochen

BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-105-Heavy.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-115-Black.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-35-Thin.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-45-Light.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-55-Regular.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-55-RegularL3.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-65-Medium.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-75-SemiBold.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-85-Bold.ttf


BIN
Avalonia/ShakerApp/Fonts/AlibabaPuHuiTi-3-95-ExtraBold.ttf


+ 0 - 14
Avalonia/ShakerApp/ShakerApp.csproj

@@ -16,20 +16,6 @@
     <AvaloniaResource Include="Assets\**" />
   </ItemGroup>
 
-
-  <ItemGroup>
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-105-Heavy.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-115-Black.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-35-Thin.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-45-Light.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-55-Regular.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-55-RegularL3.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-65-Medium.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-75-SemiBold.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-85-Bold.ttf" />
-    <AvaloniaResource Include="Fonts\AlibabaPuHuiTi-3-95-ExtraBold.ttf" />
-  </ItemGroup>
-
   <ItemGroup>
     <AvaloniaXaml Include="Styles\ResourceDictionary.axaml">
       <SubType>Designer</SubType>

+ 1 - 1
Avalonia/ShakerApp/ViewModels/CommunicationViewModel.cs

@@ -71,7 +71,7 @@ namespace ShakerApp.ViewModels
                     bool success = false;
                     for (int i = 0; i < 3; i++)
                     {
-                        var result = LocalCommunication.GetEvent<string>(Topic.SERVICERESULT).Publish(this, null);
+                        var result = LocalCommunication.GetEvent<string>(Topic.SERVICERESULT)?.Publish(this, null);
                         if (!string.IsNullOrEmpty(result))
                         {
                             success = true;

+ 12 - 1
Avalonia/ShakerApp/ViewModels/Setting/ShakerSettingViewModel.cs

@@ -143,7 +143,18 @@ namespace ShakerApp.ViewModels
         [PropertyAssociation(nameof(ShakerSettingModel.Language))]
         public string Language { get => Model.Language; set => SetProperty(ref Model.Language, value); }
         [PropertyAssociation(nameof(ShakerSettingModel.DataDirectory))]
-        public string DataDirectory { get => Model.DataDirectory; set => SetProperty(ref Model.DataDirectory, value); }
+        public string DataDirectory 
+        {
+            get
+            {
+                if(!System.IO.Directory.Exists(Model.DataDirectory))
+                {
+                    Directory.CreateDirectory(Model.DataDirectory);
+                }
+                return Model.DataDirectory;
+            }
+            set => SetProperty(ref Model.DataDirectory, value);
+        }
         private ShakerSettingViewModel()
         {
             Content = typeof(Views.ShakerSettingView);

+ 2 - 2
Avalonia/ShakerApp/ViewModels/ShakerDataViewModel.cs

@@ -18,7 +18,7 @@ namespace ShakerApp.ViewModels
         {
             GetEvent<AllConfig>().Subscrip((sender, args) =>
             {
-                CommunicationViewModel.Instance.LocalCommunication.GetEvent(Topic.DATA).Subscrip((sender, args) =>
+                CommunicationViewModel.Instance.LocalCommunication.GetEvent(Topic.DATA)?.Subscrip((sender, args) =>
                 {
                     if(args.Data.Length>0 && args.Data[0] is float[,] v)
                     {
@@ -29,7 +29,7 @@ namespace ShakerApp.ViewModels
                                 {
                                     if(file ==null)
                                     {
-                                        file = new NationalInstruments.Tdms.File(System.IO.Path.Combine(ViewModels.ShakerSettingViewModel.Instance.DataDirectory, $"{DateTime.Now:yyyy-MM-dd HH-mm-ss}.sdat")).Open();
+                                        file = new NationalInstruments.Tdms.File(System.IO.Path.Combine(ViewModels.ShakerSettingViewModel.Instance.DataDirectory, $"{DateTime.Now:yyyy-MM-dd HH-mm-ss}.sdat"), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite).Open();
                                     }
                                     //file.
                                 }

+ 35 - 15
Communication/TcpEventBus/NettyServer.cs

@@ -23,30 +23,41 @@ namespace TcpEventBus
 {
     public class NettyServerManger: ISocket
     {
-        IEventLoopGroup bossGroup;
-        IEventLoopGroup workerGroup;
-        IChannel boundChannel;
+        [AllowNull]
+        private IEventLoopGroup bossGroup;
+        [AllowNull]
+        private IEventLoopGroup workerGroup;
+        [AllowNull]
+        private IChannel boundChannel;
+        [AllowNull]
+        private ServerBootstrap bootstrap;
         public string IP { get; }
+        public int MaxFrameLength { get; }
         public int Port { get; }
         public bool IsService => true;
         public bool IsConnect => handler == null ? false:handler.IsConnect;
 
         public int ReceiveTimeout { get; }
+        [AllowNull]
 
         public Action OnConnected { get; set; }
+        [AllowNull]
         public Action<ArraySegment<byte>> OnData { get; set; }
+        [AllowNull]
         public Action OnDisconnected { get; set; }
         private NettyHandler handler = new NettyHandler();
 
-        public NettyServerManger(string ip,int port,int timeout=1000)
+        public NettyServerManger(string ip,int port,int timeout=1000,int maxFrameLength=512000)
         {
+            if (maxFrameLength <= 0) throw new ArgumentOutOfRangeException($"{nameof(maxFrameLength)} must be greater than 0");
+            MaxFrameLength = maxFrameLength;
             this.IP = ip;
             this.Port = port;
             ReceiveTimeout = timeout;
-            RunServerAsync().Wait();
+            RunServer();
         }
-        ServerBootstrap bootstrap;
-       private async Task RunServerAsync()
+
+       private void RunServer()
         {
 #if DEBUG
             InternalLoggerFactory.DefaultFactory = LoggerFactory.Create(builder => builder.AddConsole());
@@ -90,11 +101,10 @@ namespace TcpEventBus
                         IChannelPipeline pipeline = channel.Pipeline;
                         pipeline.AddLast(new LoggingHandler("SRV-CONN"));
                         pipeline.AddLast("framing-enc", new LengthFieldPrepender(3));
-                        pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(512000 + 3, 0, 3, 0, 3));
+                        pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(MaxFrameLength + 3, 0, 3, 0, 3));
 
                         pipeline.AddLast("echo", handler);
                     }));
-
             }
             finally
             {
@@ -130,7 +140,8 @@ namespace TcpEventBus
         [AllowNull]
         public Action OnDisconnected { get; set; }
         public bool IsConnect { get; private set; }
-        IChannelHandlerContext _Context;
+        [AllowNull]
+        private IChannelHandlerContext _Context;
         public NettyHandler()
         {
             IsConnect = false;
@@ -175,28 +186,37 @@ namespace TcpEventBus
 
     public class NettyClientManger :  ISocket
     {
-        IChannel clientChannel;
+        [AllowNull]
+        private Bootstrap bootstrap;
+        [AllowNull]
+        private MultithreadEventLoopGroup group;
+        [AllowNull]
+        private IChannel clientChannel;
         public string IP { get; }
         public int Port { get; }
         public bool IsService => true;
         public bool IsConnect => handler == null ? false : handler.IsConnect;
 
         public int ReceiveTimeout { get; }
+        [AllowNull]
 
         public Action OnConnected { get; set; }
+        public int MaxFrameLength { get; }
+        [AllowNull]
         public Action<ArraySegment<byte>> OnData { get; set; }
+        [AllowNull]
         public Action OnDisconnected { get; set; }
         private NettyHandler handler = new NettyHandler();
 
-        public NettyClientManger(string ip, int port,int timeout = 1000)
+        public NettyClientManger(string ip, int port,int timeout = 1000,int maxFrameLength=512000)
         {
+            if(maxFrameLength<=0) throw new ArgumentOutOfRangeException($"{nameof(maxFrameLength)} must be greater than 0");
             this.IP = ip;
             this.Port = port;
             ReceiveTimeout = timeout;
+            MaxFrameLength = maxFrameLength;
             RunClientAsync();
         }
-        Bootstrap bootstrap;
-        MultithreadEventLoopGroup group;
         private void RunClientAsync()
         {
 #if DEBUG
@@ -221,7 +241,7 @@ namespace TcpEventBus
 
                         pipeline.AddLast(new LoggingHandler());
                         pipeline.AddLast("framing-enc", new LengthFieldPrepender(3));
-                        pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(512000 + 3, 0, 3, 0, 3));
+                        pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(MaxFrameLength + 3, 0, 3, 0, 3));
 
                         pipeline.AddLast("echo", handler);
                     }));

+ 2 - 2
DBHelper/SQLite.cs

@@ -4618,8 +4618,8 @@ namespace SQLite
 			Serialized = 3
 		}
 
-        //const string LibraryPath = "libsqlite3.so.0";
-        const string LibraryPath = "e_sqlite3.dll";
+        const string LibraryPath = "libsqlite3.so.0";
+        //const string LibraryPath = "e_sqlite3.dll";
 #if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE && !USE_SQLITEPCL_RAW
         [DllImport(LibraryPath, EntryPoint = "sqlite3_threadsafe", CallingConvention=CallingConvention.Cdecl)]
 		public static extern int Threadsafe ();

+ 3 - 2
NIFPGA/FPGAArrayFXPReadProperty.cs

@@ -42,8 +42,9 @@ namespace NIFPGA
                 }
             }
 
-            _Convert.FxpConvertToDouble(ref tempvalue[0], _TypeInfo, ref doubles[0], Count);
-            return doubles;
+                _Convert.FxpConvertToDouble(ref tempvalue[0], _TypeInfo, ref doubles[0], Count);
+                return doubles;
+            }
         }
         public uint Count { get; }
         public double[] Value { get => GetData(); }

+ 11 - 17
NIFPGA/FPGAArrayFXPWriteProperty.cs

@@ -44,30 +44,24 @@ namespace NIFPGA
                 }
             }
 
-            _Convert.FxpConvertToDouble(ref tempvalue[0], _TypeInfo, ref doubles[0], Count);
-            return doubles;
+                _Convert.FxpConvertToDouble(ref tempvalue[0], _TypeInfo, ref doubles[0], Count);
+                return doubles;
+            }
         }
         private void SetData(double[] values)
         {
             if (values.Length != Count) return;
             _Convert.DoubleConvertToDxp(ref values[0], _TypeInfo, ref tempvalue[0], Count);
-            int tempdatalen = Unsafe.SizeOf<ulong>() * 8;
-            for (int i = 0; i < Count; i++)
+            string s = string.Empty;
+            for(int i=0;i<tempvalue.Length;i++)
             {
-                int index = i * _TypeInfo.wordLength / tempdatalen;
-                int bitindex = tempdatalen - (i * _TypeInfo.wordLength % tempdatalen);
-                var b =(tempvalue[i] & ((1ul << _TypeInfo.wordLength) - 1));
-                if (bitindex >= _TypeInfo.wordLength)
-                {
-                    tempbuffer[index] |= (b << (bitindex - _TypeInfo.wordLength));
-                }
-                else
-                {
-                    tempbuffer[index] |= (b >> (_TypeInfo.wordLength - bitindex));
-                    tempbuffer[index + 1] |= ((b & ((1ul << (_TypeInfo.wordLength - bitindex)) - 1)) << (tempdatalen - (_TypeInfo.wordLength - bitindex)));
-                }
+                s += tempvalue[i].ToString("b").PadLeft(64, '0').Substring(64 - _TypeInfo.wordLength, _TypeInfo.wordLength);
+            }
+            for(int i=0;i< tempbuffer.Length;i++)
+            {
+                tempbuffer[i] = System.Convert.ToByte(s.Substring(i * 8, Math.Min(8, s.Length - i * 8)),2);
             }
-            _Session.CheckResult(Write(_Session.Session,Indicator, ref Unsafe.As<ulong,byte>(ref tempbuffer[0]), (uint)tempbuffer.Length*8));
+            _Session.CheckResult(Write(_Session.Session,Indicator, ref tempbuffer[0], (uint)tempbuffer.Length));
         }
         public uint Count { get; }
         public double[] Value { get => GetData(); set => SetData(value); }

+ 40 - 36
NIFPGA/FPGAArrayReadProperty.cs

@@ -6,6 +6,7 @@ namespace NIFPGA
     where T : unmanaged
     {
         private T[] tempvalue = new T[0];
+        private object lockObject = new object();
         internal FPGAArrayReadProperty(FPGASession session, uint indicator, uint count) : base(session, indicator, true)
         {
             Count = count;
@@ -13,44 +14,47 @@ namespace NIFPGA
         }
         private T[] GetValues()
         {
-            if (Count == 0) return tempvalue;
-            switch (tempvalue[0])
+            lock (lockObject)
             {
-                case (bool):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
-                    break;
-                case (byte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
-                    break;
-                case (sbyte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref tempvalue[0]), Count));
-                    break;
-                case short:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref tempvalue[0]), Count));
-                    break;
-                case (ushort):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref tempvalue[0]), Count));
-                    break;
-                case (int):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref tempvalue[0]), Count));
-                    break;
-                case (uint):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref tempvalue[0]), Count));
-                    break;
-                case (long):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref tempvalue[0]), Count));
-                    break;
-                case (ulong):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref tempvalue[0]), Count));
-                    break;
-                case (float):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref tempvalue[0]), Count));
-                    break;
-                case (double):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref tempvalue[0]), Count));
-                    break;
+                if (Count == 0) return tempvalue;
+                switch (tempvalue[0])
+                {
+                    case (bool):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
+                        break;
+                    case (byte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
+                        break;
+                    case (sbyte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref tempvalue[0]), Count));
+                        break;
+                    case short:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref tempvalue[0]), Count));
+                        break;
+                    case (ushort):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref tempvalue[0]), Count));
+                        break;
+                    case (int):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref tempvalue[0]), Count));
+                        break;
+                    case (uint):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref tempvalue[0]), Count));
+                        break;
+                    case (long):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref tempvalue[0]), Count));
+                        break;
+                    case (ulong):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref tempvalue[0]), Count));
+                        break;
+                    case (float):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref tempvalue[0]), Count));
+                        break;
+                    case (double):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref tempvalue[0]), Count));
+                        break;
+                }
+                return tempvalue;
             }
-            return tempvalue;
         }
         public uint Count { get; }
         public T[] Values  => GetValues(); 

+ 78 - 71
NIFPGA/FPGAArrayWriteProperty.cs

@@ -6,6 +6,7 @@ namespace NIFPGA
     where T : unmanaged
     {
         private T[] tempvalue = new T[0];
+        private object lockObject = new object();
         internal FPGAArrayWriteProperty(FPGASession session, uint indicator, uint count) : base(session, indicator, false)
         {
             Count = count;
@@ -13,84 +14,90 @@ namespace NIFPGA
         }
         private void SetValue(T[] values)
         {
-            if (values.Length != Count) return;
-            switch (values[0])
+            lock (lockObject)
             {
-                case (bool):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref values[0]), Count));
-                    break;
-                case (byte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref values[0]), Count));
-                    break;
-                case (sbyte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref values[0]), Count));
-                    break;
-                case (short):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref values[0]), Count));
-                    break;
-                case (ushort):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref values[0]), Count));
-                    break;
-                case (int):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref values[0]), Count));
-                    break;
-                case (uint):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref values[0]), Count));
-                    break;
-                case (long):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref values[0]), Count));
-                    break;
-                case (ulong):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref values[0]), Count));
-                    break;
-                case (float):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref values[0]), Count));
-                    break;
-                case (double):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref values[0]), Count));
-                    break;
+                if (values.Length != Count) return;
+                switch (values[0])
+                {
+                    case (bool):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref values[0]), Count));
+                        break;
+                    case (byte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref values[0]), Count));
+                        break;
+                    case (sbyte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref values[0]), Count));
+                        break;
+                    case (short):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref values[0]), Count));
+                        break;
+                    case (ushort):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref values[0]), Count));
+                        break;
+                    case (int):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref values[0]), Count));
+                        break;
+                    case (uint):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref values[0]), Count));
+                        break;
+                    case (long):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref values[0]), Count));
+                        break;
+                    case (ulong):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref values[0]), Count));
+                        break;
+                    case (float):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref values[0]), Count));
+                        break;
+                    case (double):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref values[0]), Count));
+                        break;
+                }
             }
         }
         private T[] GetValues()
         {
-            if (Count == 0) return tempvalue;
-            switch (tempvalue[0])
+            lock (lockObject)
             {
-                case (bool):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
-                    break;
-                case (byte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
-                    break;
-                case (sbyte):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref tempvalue[0]), Count));
-                    break;
-                case short:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref tempvalue[0]), Count));
-                    break;
-                case (ushort):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref tempvalue[0]), Count));
-                    break;
-                case (int):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref tempvalue[0]), Count));
-                    break;
-                case (uint):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref tempvalue[0]), Count));
-                    break;
-                case (long):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref tempvalue[0]), Count));
-                    break;
-                case (ulong):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref tempvalue[0]), Count));
-                    break;
-                case (float):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref tempvalue[0]), Count));
-                    break;
-                case (double):
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref tempvalue[0]), Count));
-                    break;
+                if (Count == 0) return tempvalue;
+                switch (tempvalue[0])
+                {
+                    case (bool):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
+                        break;
+                    case (byte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref tempvalue[0]), Count));
+                        break;
+                    case (sbyte):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref tempvalue[0]), Count));
+                        break;
+                    case short:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref tempvalue[0]), Count));
+                        break;
+                    case (ushort):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref tempvalue[0]), Count));
+                        break;
+                    case (int):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref tempvalue[0]), Count));
+                        break;
+                    case (uint):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref tempvalue[0]), Count));
+                        break;
+                    case (long):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref tempvalue[0]), Count));
+                        break;
+                    case (ulong):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref tempvalue[0]), Count));
+                        break;
+                    case (float):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArraySgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref tempvalue[0]), Count));
+                        break;
+                    case (double):
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadArrayDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref tempvalue[0]), Count));
+                        break;
+                }
+                return tempvalue;
             }
-            return tempvalue;
         }
         public uint Count { get; }
         public T[] Values { get => GetValues(); set => SetValue(value); }

+ 8 - 5
NIFPGA/FPGAFXPReadProperty.cs

@@ -15,11 +15,14 @@ namespace NIFPGA
         }
         private double GetValue()
         {
-            ulong value = 0;
-            double temp = 0;
-            _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
-            _Convert.FxpConvertToDouble(ref value, _TypeInfo, ref temp, 1);
-            return temp;
+            lock (Read)
+            {
+                ulong value = 0;
+                double temp = 0;
+                _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
+                _Convert.FxpConvertToDouble(ref value, _TypeInfo, ref temp, 1);
+                return temp;
+            }
         }
         public double Value => GetValue();
     }

+ 14 - 8
NIFPGA/FPGAFXPWriteProperty.cs

@@ -17,17 +17,23 @@ namespace NIFPGA
         }
         private double GetValue()
         {
-            ulong value = 0;
-            double temp = 0;
-            _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
-            _Convert.FxpConvertToDouble (ref value, _TypeInfo, ref temp, 1);
-            return temp;
+            lock (Read)
+            {
+                ulong value = 0;
+                double temp = 0;
+                _Session.CheckResult(Read(_Session.Session, Indicator, ref value));
+                _Convert.FxpConvertToDouble(ref value, _TypeInfo, ref temp, 1);
+                return temp;
+            }
         }
         private void SetValue(double value)
         {
-            ulong temp = 0;
-            _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp, 1);
-            _Session.CheckResult(Write(_Session.Session, Indicator, temp));
+            lock (Read)
+            {
+                ulong temp = 0;
+                _Convert.DoubleConvertToDxp(ref value, _TypeInfo, ref temp, 1);
+                _Session.CheckResult(Write(_Session.Session, Indicator, temp));
+            }
         }
         public double Value { get => GetValue(); set => SetValue(value); }
     }

+ 40 - 36
NIFPGA/FPGAReadProperty.cs

@@ -5,49 +5,53 @@ namespace NIFPGA
     public sealed class FPGAReadProperty<T> : FPGABaseProperty
         where T : unmanaged
     {
+        private object lockObject = new object();
         internal FPGAReadProperty(FPGASession session, uint indicator) : base(session, indicator, true)
         {
         }
         private T GetValue()
         {
-            T value = default;
-            switch (value)
+            lock (lockObject)
             {
-                case Boolean:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
-                    break;
-                case Byte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
-                    break;
-                case SByte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref value)));
-                    break;
-                case Int16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref value)));
-                    break;
-                case UInt16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref value)));
-                    break;
-                case Int32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref value)));
-                    break;
-                case UInt32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref value)));
-                    break;
-                case Int64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref value)));
-                    break;
-                case UInt64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref value)));
-                    break;
-                case Single:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref value)));
-                    break;
-                case double:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref value)));
-                    break;
+                T value = default;
+                switch (value)
+                {
+                    case Boolean:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
+                        break;
+                    case Byte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
+                        break;
+                    case SByte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref value)));
+                        break;
+                    case Int16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref value)));
+                        break;
+                    case UInt16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref value)));
+                        break;
+                    case Int32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref value)));
+                        break;
+                    case UInt32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref value)));
+                        break;
+                    case Int64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref value)));
+                        break;
+                    case UInt64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref value)));
+                        break;
+                    case Single:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref value)));
+                        break;
+                    case double:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref value)));
+                        break;
+                }
+                return value;
             }
-            return value;
         }
         public T Value => GetValue();
     }

+ 77 - 70
NIFPGA/FPGAWriteProperty.cs

@@ -11,88 +11,95 @@ namespace NIFPGA
     public sealed class FPGAWriteProperty<T> : FPGABaseProperty
         where T : unmanaged
     {
+        private object lockObject = new object();
         internal FPGAWriteProperty(FPGASession session, uint indicator) : base(session, indicator, false)
         {
         }
         private void SetValue(T value)
         {
-            switch (value)
+            lock (lockObject)
             {
-                case Boolean boolvalue:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteBool>()(_Session.Session, Indicator, Convert.ToByte(boolvalue)));
-                    break;
-                case Byte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU8>()(_Session.Session, Indicator, Unsafe.As<T, byte>(ref value)));
-                    break;
-                case SByte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI8>()(_Session.Session, Indicator, Unsafe.As<T, sbyte>(ref value)));
-                    break;
-                case Int16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI16>()(_Session.Session, Indicator, Unsafe.As<T, short>(ref value)));
-                    break;
-                case UInt16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU16>()(_Session.Session, Indicator, Unsafe.As<T, ushort>(ref value)));
-                    break;
-                case Int32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI32>()(_Session.Session, Indicator, Unsafe.As<T, int>(ref value)));
-                    break;
-                case UInt32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU32>()(_Session.Session, Indicator, Unsafe.As<T, uint>(ref value)));
-                    break;
-                case Int64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI64>()(_Session.Session, Indicator, Unsafe.As<T, long>(ref value)));
-                    break;
-                case UInt64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU64>()(_Session.Session, Indicator, Unsafe.As<T, ulong>(ref value)));
-                    break;
-                case Single:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteSgl>()(_Session.Session, Indicator, Unsafe.As<T, float>(ref value)));
-                    break;
-                case double:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteDbl>()(_Session.Session, Indicator, Unsafe.As<T, double>(ref value)));
-                    break;
+                switch (value)
+                {
+                    case Boolean boolvalue:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteBool>()(_Session.Session, Indicator, Convert.ToByte(boolvalue)));
+                        break;
+                    case Byte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU8>()(_Session.Session, Indicator, Unsafe.As<T, byte>(ref value)));
+                        break;
+                    case SByte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI8>()(_Session.Session, Indicator, Unsafe.As<T, sbyte>(ref value)));
+                        break;
+                    case Int16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI16>()(_Session.Session, Indicator, Unsafe.As<T, short>(ref value)));
+                        break;
+                    case UInt16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU16>()(_Session.Session, Indicator, Unsafe.As<T, ushort>(ref value)));
+                        break;
+                    case Int32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI32>()(_Session.Session, Indicator, Unsafe.As<T, int>(ref value)));
+                        break;
+                    case UInt32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU32>()(_Session.Session, Indicator, Unsafe.As<T, uint>(ref value)));
+                        break;
+                    case Int64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteI64>()(_Session.Session, Indicator, Unsafe.As<T, long>(ref value)));
+                        break;
+                    case UInt64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteU64>()(_Session.Session, Indicator, Unsafe.As<T, ulong>(ref value)));
+                        break;
+                    case Single:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteSgl>()(_Session.Session, Indicator, Unsafe.As<T, float>(ref value)));
+                        break;
+                    case double:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteDbl>()(_Session.Session, Indicator, Unsafe.As<T, double>(ref value)));
+                        break;
+                }
             }
         }
         private T GetValue()
         {
-            T value = default;
-            switch (value)
+            lock (lockObject)
             {
-                case Boolean:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
-                    break;
-                case Byte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
-                    break;
-                case SByte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref value)));
-                    break;
-                case Int16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref value)));
-                    break;
-                case UInt16:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref value)));
-                    break;
-                case Int32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref value)));
-                    break;
-                case UInt32:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref value)));
-                    break;
-                case Int64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref value)));
-                    break;
-                case UInt64:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref value)));
-                    break;
-                case Single:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref value)));
-                    break;
-                case double:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref value)));
-                    break;
+                T value = default;
+                switch (value)
+                {
+                    case Boolean:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadBool>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
+                        break;
+                    case Byte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU8>()(_Session.Session, Indicator, ref Unsafe.As<T, byte>(ref value)));
+                        break;
+                    case SByte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI8>()(_Session.Session, Indicator, ref Unsafe.As<T, sbyte>(ref value)));
+                        break;
+                    case Int16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI16>()(_Session.Session, Indicator, ref Unsafe.As<T, short>(ref value)));
+                        break;
+                    case UInt16:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU16>()(_Session.Session, Indicator, ref Unsafe.As<T, ushort>(ref value)));
+                        break;
+                    case Int32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI32>()(_Session.Session, Indicator, ref Unsafe.As<T, int>(ref value)));
+                        break;
+                    case UInt32:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU32>()(_Session.Session, Indicator, ref Unsafe.As<T, uint>(ref value)));
+                        break;
+                    case Int64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadI64>()(_Session.Session, Indicator, ref Unsafe.As<T, long>(ref value)));
+                        break;
+                    case UInt64:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadU64>()(_Session.Session, Indicator, ref Unsafe.As<T, ulong>(ref value)));
+                        break;
+                    case Single:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadSgl>()(_Session.Session, Indicator, ref Unsafe.As<T, float>(ref value)));
+                        break;
+                    case double:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadDbl>()(_Session.Session, Indicator, ref Unsafe.As<T, double>(ref value)));
+                        break;
+                }
+                return value;
             }
-            return value;
         }
         public T Value { get => GetValue(); set => SetValue(value); }
     }

+ 38 - 34
NIFPGA/ReadFifo.cs

@@ -13,46 +13,50 @@ namespace NIFPGA
     public class ReadFifo<T>:Fifo
         where T : unmanaged
     {
+        private object _Lock = new object();
         internal ReadFifo(FPGASession session, uint fifosession) : base(session, fifosession)
         {
         }
         public void Read(ref T value,uint count, uint timeout, ref uint elementsRemaining)
         {
-            switch(value)
+            lock (_Lock)
             {
-                case bool:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoBool>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case byte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case sbyte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case ushort:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case short:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case int:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case uint:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case long:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case ulong:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case float:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoSgl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
-                case double:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoDbl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
-                    break;
+                switch (value)
+                {
+                    case bool:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoBool>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case byte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case sbyte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case ushort:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case short:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case int:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case uint:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case long:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoI64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case ulong:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoU64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case float:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoSgl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                    case double:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_ReadFifoDbl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value), count, timeout, ref elementsRemaining));
+                        break;
+                }
             }
         }
         public uint ElementsRemaining

+ 39 - 35
NIFPGA/WriteFifo.cs

@@ -12,47 +12,51 @@ namespace NIFPGA
     public class WriteFifo<T>:Fifo
         where T : unmanaged
     {
+        private object _Locker = new object();
         internal WriteFifo(FPGASession session, uint fifosession) : base(session, fifosession)
         {
         }
         public void Write(T[] value,uint timeout,ref uint emptyElementsRemaining)
         {
-            if (value.Length == 0) return;
-            switch(value[0])
+            lock (_Locker)
             {
-                case bool:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoBool>()(_Session.Session, FifoSession,ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case byte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case sbyte:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case short:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case ushort:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case int:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case uint:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case long:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case ulong:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case float:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoSgl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
-                case double:
-                    _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoDbl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
-                    break;
+                if (value.Length == 0) return;
+                switch (value[0])
+                {
+                    case bool:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoBool>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case byte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case sbyte:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI8>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case short:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case ushort:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU16>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case int:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case uint:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU32>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case long:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoI64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case ulong:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoU64>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case float:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoSgl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                    case double:
+                        _Session.CheckResult(_Session.GetDelegate<Interop.NiFpgaDll_WriteFifoDbl>()(_Session.Session, FifoSession, ref Unsafe.As<T, byte>(ref value[0]), (uint)value.Length, timeout, ref emptyElementsRemaining));
+                        break;
+                }
             }
         }
     }

+ 2 - 2
TdmsFile/File.cs

@@ -22,9 +22,9 @@ namespace NationalInstruments.Tdms
             _stream = new Lazy<Stream>(() => stream);
         }
 
-        public File(string path) : this()
+        public File(string path,FileMode mode, FileAccess access) : this()
         {
-            _stream = new Lazy<Stream>(() => new FileStream(path, FileMode.Open, FileAccess.Read));
+            _stream = new Lazy<Stream>(() => new FileStream(path, mode,access));
         }
 
         public IDictionary<string, object> Properties { get; private set; }