/// <summary>
 /// Initializes a new instance of the <see cref="MemoryGpioConnectionDriver"/> class.
 /// </summary>
 public MemoryGpioConnectionDriver()
 {
     using (var memoryFile = UnixFile.Open("/dev/mem", UnixFileMode.ReadWrite | UnixFileMode.Synchronized)) {
         gpioAddress = MemoryMap.Create(
             IntPtr.Zero,
             Interop.BCM2835_BLOCK_SIZE,
             MemoryProtection.ReadWrite,
             MemoryFlags.Shared,
             memoryFile.Descriptor,
             GetProcessorBaseAddress(Board.Current.Processor));
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GpioConnectionDriver"/> class.
 /// </summary>
 public GpioConnectionDriver()
 {
     using (var memoryFile = UnixFile.Open("/dev/mem", UnixFileMode.ReadWrite | UnixFileMode.Synchronized)) {
         gpioAddress = MemoryMap.Create(
             IntPtr.Zero,
             Interop.BCM2835_BLOCK_SIZE,
             MemoryProtection.ReadWrite,
             MemoryFlags.Shared,
             memoryFile.Descriptor,
             Board.Current.Model == '2' ? Interop.BCM2836_GPIO_BASE : Interop.BCM2835_GPIO_BASE);
     }
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GpioConnectionDriver" /> class.
 /// </summary>
 /// <param name="threadFactory">The thread factory.</param>
 public GpioConnectionDriver(IThreadFactory threadFactory = null)
 {
     this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create();
     using (var memoryFile = UnixFile.Open("/dev/mem", UnixFileMode.ReadWrite | UnixFileMode.Synchronized))
     {
         this.gpioAddress = MemoryMap.Create(
             IntPtr.Zero,
             Interop.Bcm2835BlockSize,
             MemoryProtection.ReadWrite,
             MemoryFlags.Shared,
             memoryFile.Descriptor,
             GetProcessorBaseAddress(Board.Current.Processor));
     }
 }
Пример #4
0
        static void Main()
        {
            var sampleBigDataIn = CreateBigDataParent(10000);

            Console.WriteLine(
                $"Created '{sampleBigDataIn.Description}'");
            Console.WriteLine(
                $"with a total SomeDouble: {sampleBigDataIn.BigDataChildren.Sum(x => x.SomeDouble)}");

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var memoryMap = new MemoryMap <BigDataParent>("SomeKey");

            memoryMap.Create(sampleBigDataIn);

            Console.WriteLine(
                $"memoryMap.Create elapsed time: {stopWatch.Elapsed}");

            var sampleBigDataOut = memoryMap.Load();

            Console.WriteLine(
                $"Create and Load elapsed time: {stopWatch.Elapsed}");
            stopWatch.Stop();

            var childId = sampleBigDataIn.BigDataChildren[0].Id;

            Console.WriteLine($"BigDataParent comparison check for childId: {childId}");

            var totalSomeDoubleIn = sampleBigDataIn.BigDataChildren
                                    .Where(x => x.Id.Equals(childId)).Sum(x => x.SomeDouble);

            Console.WriteLine($"totalSomeDoubleIn : {totalSomeDoubleIn}");

            var totalSomeDoubleOut = sampleBigDataOut.BigDataChildren
                                     .Where(x => x.Id.Equals(childId)).Sum(x => x.SomeDouble);

            Console.WriteLine($"totalSomeDoubleOut: {totalSomeDoubleOut}");

            Console.ReadKey();
        }