コード例 #1
0
 public UInt16 Write(byte[] buffer, int offset = 0, UInt16 length = 0)
 {
     lock (Daq) {
         int byteCount = buffer.Length;
         if (length != 0 && length < buffer.Length)
         {
             byteCount = length;
         }
         if (byteCount > offset)
         {
             byteCount -= offset;
         }
         UInt16 bytesWritten      = 0;
         UInt16 totalBytesWritten = 0;
         while (byteCount != 0)
         {
             UInt16 byteChunk = (UInt16)Math.Min(MaxByteChunk, byteCount);
             BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.Usart);
             BasicTypeSerializer.Put(SendContext, (byte)Command.Write);
             BasicTypeSerializer.Put(SendContext, byteChunk);
             SendContext.Store(buffer, offset, byteChunk);
             Daq.Execute();
             Daq.Receive();
             CheckResult();
             bytesWritten       = BasicTypeDeSerializer.Get(ReceiveContext, bytesWritten);
             totalBytesWritten += bytesWritten;
             offset            += bytesWritten;
             byteCount         -= bytesWritten;
         }
         return(totalBytesWritten);
     }
 }
コード例 #2
0
 public void Write(Speed speed, UInt16 address, byte[] buffer, int offset = 0, UInt16 length = 0)
 {
     lock (Daq) {
         int byteCount = buffer.Length;
         if (length != 0 && length < buffer.Length)
         {
             byteCount = length;
         }
         if (byteCount > offset)
         {
             byteCount -= offset;
         }
         while (byteCount != 0)
         {
             UInt16 byteChunk = (UInt16)Math.Min(MaxByteChunk, byteCount);
             BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.I2c);
             BasicTypeSerializer.Put(SendContext, (byte)Command.Write);
             BasicTypeSerializer.Put(SendContext, (byte)speed);
             BasicTypeSerializer.Put(SendContext, (UInt16)address);
             BasicTypeSerializer.Put(SendContext, byteChunk);
             SendContext.Store(buffer, offset, byteChunk);
             Daq.Execute();
             Daq.Receive();
             CheckResult();
             offset    += byteChunk;
             byteCount -= byteChunk;
         }
     }
 }
コード例 #3
0
ファイル: FileSystem.cs プロジェクト: fabienroyer/NetduinoGo
 public UInt16 WriteFile(UInt16 fileId, byte[] buffer, int bytesToWrite)
 {
     lock (Daq) {
         int    byteCount         = bytesToWrite;
         UInt16 bytesWritten      = 0;
         UInt16 totalBytesWritten = 0;
         int    offset            = 0;
         while (byteCount != 0)
         {
             UInt16 byteChunk = (UInt16)Math.Min(MaxByteChunk, byteCount);
             BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem);
             BasicTypeSerializer.Put(SendContext, (byte)Command.WriteFile);
             BasicTypeSerializer.Put(SendContext, fileId);
             BasicTypeSerializer.Put(SendContext, byteChunk);
             SendContext.Store(buffer, offset, byteChunk);
             Daq.Execute();
             Daq.Receive();
             CheckResult();
             bytesWritten       = BasicTypeDeSerializer.Get(ReceiveContext, bytesWritten);
             totalBytesWritten += bytesWritten;
             offset            += bytesWritten;
             byteCount         -= bytesWritten;
         }
         return(totalBytesWritten);
     }
 }