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); } }
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); } }
public UInt16 ReadFile(UInt16 fileId, byte[] buffer, int bytesToRead) { lock (Daq) { int byteCount = bytesToRead; UInt16 bytesRead = 0; UInt16 totalBytesRead = 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.ReadFile); BasicTypeSerializer.Put(SendContext, fileId); BasicTypeSerializer.Put(SendContext, byteChunk); Daq.Execute(); Daq.Receive(); CheckResult(); bytesRead = BasicTypeDeSerializer.Get(ReceiveContext, bytesRead); ReceiveContext.CopyBytesFromInternalBuffer(buffer, offset, bytesRead); totalBytesRead += bytesRead; offset += bytesRead; byteCount -= bytesRead; if (bytesRead < byteChunk) { break; } } return(totalBytesRead); } }
public void TouchscreenWaitForEvent() { BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenWaitForEvent); Execute(); Receive(); TouchScreenDataType eventType = (TouchScreenDataType)BasicTypeDeSerializer.Get(ReceiveContext); if (eventType != TouchScreenDataType.TouchEvent) { throw new ApplicationException("eventType"); } var touchEvent = new TouchEvent(); touchEvent.X = BasicTypeDeSerializer.Get(ReceiveContext, touchEvent.X); touchEvent.Y = BasicTypeDeSerializer.Get(ReceiveContext, touchEvent.Y); touchEvent.Pressure = BasicTypeDeSerializer.Get(ReceiveContext, touchEvent.Pressure); touchEvent.IsValid = BasicTypeDeSerializer.Get(ReceiveContext); OnTouch(touchEvent); if (WidgetClicked != null) { foreach (Widget widget in RegisteredWidgets) { widget.OnClickEvent(touchEvent); if (widget.Clicked) { WidgetClicked(this, widget, touchEvent); } } } }
protected void CheckResult() { byte result = BasicTypeDeSerializer.Get(ReceiveContext); if (result != 0) { throw new I2cException((int)result, ResultStrings[result]); } }
public ClockState GetClockState() { lock (this) { BasicTypeSerializer.Put(SendContext, (byte)Command.GetClockState); Execute(); Receive(); ClockState state = (ClockState)BasicTypeDeSerializer.Get(ReceiveContext); return(state); } }
public void Get(BasicTypeDeSerializerContext context) { An = BasicTypeDeSerializer.Get(context, An); Bn = BasicTypeDeSerializer.Get(context, Bn); Cn = BasicTypeDeSerializer.Get(context, Cn); Dn = BasicTypeDeSerializer.Get(context, Dn); En = BasicTypeDeSerializer.Get(context, En); Fn = BasicTypeDeSerializer.Get(context, Fn); Divider = BasicTypeDeSerializer.Get(context, Divider); }
public void SetConfig(UsartConfig config) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.Usart); BasicTypeSerializer.Put(SendContext, (byte)Command.SetConfig); config.Put(SendContext); Daq.Execute(); Daq.Receive(); config.CheckResult(BasicTypeDeSerializer.Get(ReceiveContext)); } }
public string TouchscreenShowDialog(DialogType dialogType) { BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenShowDialog); BasicTypeSerializer.Put(SendContext, (ushort)dialogType); Execute(); Receive(); TouchScreenDataType eventType = (TouchScreenDataType) BasicTypeDeSerializer.Get(ReceiveContext); if (eventType != TouchScreenDataType.String) { throw new ApplicationException("eventType"); } return BasicTypeDeSerializer.Get(ReceiveContext, ""); }
public CalibrationMatrix GetTouchscreenCalibrationMatrix() { BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenGetCalibrationMatrix); Execute(); Receive(); TouchScreenDataType eventType = (TouchScreenDataType)BasicTypeDeSerializer.Get(ReceiveContext); if (eventType != TouchScreenDataType.CalibrationMatrix) { throw new ApplicationException("eventType"); } var matrix = new CalibrationMatrix(); matrix.Get(ReceiveContext); return matrix; }
public DiskStatus GetDiskStatus() { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.GetDiskStatus); Daq.Execute(); Daq.Receive(); CheckResult(); DiskStatus diskResult = (DiskStatus)BasicTypeDeSerializer.Get(ReceiveContext); return(diskResult); } }
public bool IsBusBusy() { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.I2c); BasicTypeSerializer.Put(SendContext, (byte)Command.IsBusBusy); Daq.Execute(); Daq.Receive(); CheckResult(); byte busBusy = BasicTypeDeSerializer.Get(ReceiveContext); return((busBusy == 0) ? false : true); } }
public string GetCurrentDir() { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.GetCurrentDir); Daq.Execute(); Daq.Receive(); CheckResult(); string dir = ""; dir = BasicTypeDeSerializer.Get(ReceiveContext, dir); return(dir); } }
public bool GetFileError(UInt16 fileId) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.GetFileError); BasicTypeSerializer.Put(SendContext, fileId); Daq.Execute(); Daq.Receive(); CheckResult(); byte error = BasicTypeDeSerializer.Get(ReceiveContext); return((error == 1) ? true : false); } }
public string ReadString(UInt16 fileId) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.ReadString); BasicTypeSerializer.Put(SendContext, fileId); Daq.Execute(); Daq.Receive(); CheckResult(); string str = ""; str = BasicTypeDeSerializer.Get(ReceiveContext, str); return(str); } }
public UInt32 GetFileSize(UInt16 fileId) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.GetFileSize); BasicTypeSerializer.Put(SendContext, fileId); Daq.Execute(); Daq.Receive(); CheckResult(); UInt32 size = 0; size = BasicTypeDeSerializer.Get(ReceiveContext, size); return(size); } }
// // Directory functions // public UInt16 OpenDir(string directoryName) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.OpenDir); BasicTypeSerializer.Put(SendContext, directoryName, true); Daq.Execute(); Daq.Receive(); CheckResult(); UInt16 dirId = 0; dirId = BasicTypeDeSerializer.Get(ReceiveContext, dirId); return(dirId); } }
public bool Read(GpioInput gpio) { lock (this) { BasicTypeSerializer.Put(SendContext, (byte)Command.GetDigitalInputState); BasicTypeSerializer.Put(SendContext, (byte)gpio.Identifier); Execute(); Receive(); byte state = BasicTypeDeSerializer.Get(ReceiveContext); if (state == 255) { throw new ApplicationException("Invalid Gpio type or Identifier"); } return((state == 1) ? true : false); } }
// // File functions // public UInt16 OpenFile(string filename, FileMode mode) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.OpenFile); BasicTypeSerializer.Put(SendContext, filename, true); BasicTypeSerializer.Put(SendContext, (byte)mode); Daq.Execute(); Daq.Receive(); CheckResult(); UInt16 fileId = 0; fileId = BasicTypeDeSerializer.Get(ReceiveContext, fileId); return(fileId); } }
public Int32 WriteString(UInt16 fileId, string str) { lock (Daq) { BasicTypeSerializer.Put(SendContext, (byte)NwazetDAQ.Command.FileSystem); BasicTypeSerializer.Put(SendContext, (byte)Command.WriteString); BasicTypeSerializer.Put(SendContext, fileId); BasicTypeSerializer.Put(SendContext, str, true); Daq.Execute(); Daq.Receive(); CheckResult(); Int32 charactersWritten = 0; charactersWritten = BasicTypeDeSerializer.Get(ReceiveContext, charactersWritten); return(charactersWritten); } }
public void Get(BasicTypeDeSerializerContext context) { byte count = BasicTypeDeSerializer.Get(context); if ((GpioId)count != GpioId.GpioCount) { throw new IndexOutOfRangeException("count"); } for (var i = 0; i < count; i++) { Counts[i] = BasicTypeDeSerializer.Get(context, Counts[i]); RollOverCounts[i] = BasicTypeDeSerializer.Get(context, RollOverCounts[i]); Updated[i] = BasicTypeDeSerializer.Get(context, Updated[i]); } }
public UsartReadResult Read(byte[] buffer, int offset = 0, int length = 0, UInt32 totalTimeoutMs = 0, bool useTerminator = false, byte terminator = 0) { lock (Daq) { var result = new UsartReadResult(); 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.Usart); BasicTypeSerializer.Put(SendContext, (byte)Command.Read); BasicTypeSerializer.Put(SendContext, byteChunk); BasicTypeSerializer.Put(SendContext, totalTimeoutMs); BasicTypeSerializer.Put(SendContext, (byte)((useTerminator) ? 1 : 0)); BasicTypeSerializer.Put(SendContext, (byte)terminator); Daq.Execute(); Daq.Receive(); byte returnCode = BasicTypeDeSerializer.Get(ReceiveContext); UInt16 bytesRead = 0; bytesRead = BasicTypeDeSerializer.Get(ReceiveContext, bytesRead); ReceiveContext.CopyBytesFromInternalBuffer(buffer, offset, bytesRead); result.TotalBytesRead += bytesRead; offset += bytesRead; byteCount -= bytesRead; switch ((Result)returnCode) { case Result.InvalidParameter: throw new UsartException((int)returnCode, ResultStrings[returnCode]); case Result.TerminatorReceived: result.TerminatorReceived = true; return(result); case Result.Timeout: result.TimedOut = true; return(result); } } return(result); } }
public UInt32[] GetSystemRegisters() { lock (this) { var registers = new UInt32[MaxRtcBackupRegisters]; BasicTypeSerializer.Put(SendContext, (byte)Command.GetBackupRegisters); Execute(); Receive(); UInt32 register = 0; registers[(int)Register.System] = BasicTypeDeSerializer.Get(ReceiveContext, register); registers[(int)Register.User1] = BasicTypeDeSerializer.Get(ReceiveContext, register); registers[(int)Register.User2] = BasicTypeDeSerializer.Get(ReceiveContext, register); registers[(int)Register.User3] = BasicTypeDeSerializer.Get(ReceiveContext, register); registers[(int)Register.User4] = BasicTypeDeSerializer.Get(ReceiveContext, register); return(registers); } }
public void Read() { lock (this) { BasicTypeSerializer.Put(SendContext, (byte)Command.GetDigitalInputState); BasicTypeSerializer.Put(SendContext, (byte)GpioId.GpioCount); Execute(); Receive(); GpioId id = GpioId.GpioCount; while (true) { id = (GpioId)BasicTypeDeSerializer.Get(ReceiveContext); if (id == GpioId.GpioCount) { break; } byte state = BasicTypeDeSerializer.Get(ReceiveContext); Gpios[(int)id].State = (state == 0) ? false : true; } } }
public string Name; // Short file name (8.3 format) public void Get(BasicTypeDeSerializerContext context) { UInt16 date = 0; UInt16 time = 0; Size = BasicTypeDeSerializer.Get(context, Size); date = BasicTypeDeSerializer.Get(context, date); time = BasicTypeDeSerializer.Get(context, time); Attribute = BasicTypeDeSerializer.Get(context); Name = BasicTypeDeSerializer.Get(context, Name); /* * FAT filestamp format: * [31:25] - year - 1980 * [24:21] - month 1..12 * [20:16] - day 1..31 * [15:11] - hour 0..23 * [10:5] - minute 0..59 * [4:0] - second/2 0..29 * so... midnight 2009 is 0x3a000000 */ }
public static DateTime Get(BasicTypeDeSerializerContext context) { byte year; byte month; byte day; byte weekDay; byte hour; byte minute; byte second; int subSecond = 0; year = BasicTypeDeSerializer.Get(context); month = BasicTypeDeSerializer.Get(context); day = BasicTypeDeSerializer.Get(context); weekDay = BasicTypeDeSerializer.Get(context); hour = BasicTypeDeSerializer.Get(context); minute = BasicTypeDeSerializer.Get(context); second = BasicTypeDeSerializer.Get(context); subSecond = BasicTypeDeSerializer.Get(context, subSecond); return(new DateTime((int)2000 + year, (int)month, (int)day, (int)hour, (int)minute, (int)second, (int)subSecond)); }
public void Get(BasicTypeDeSerializerContext context) { X = BasicTypeDeSerializer.Get(context, X); Y = BasicTypeDeSerializer.Get(context, Y); }
public void Get(BasicTypeDeSerializerContext context) { DiskCapacityKB = BasicTypeDeSerializer.Get(context, DiskCapacityKB); FreeDiskSpaceKB = BasicTypeDeSerializer.Get(context, FreeDiskSpaceKB); }
public static void Main() { var contextSerializer = new BasicTypeSerializerContext(); BasicTypeSerializer.Put(contextSerializer, (byte)byte.MaxValue); BasicTypeSerializer.Put(contextSerializer, (UInt16)UInt16.MaxValue); BasicTypeSerializer.Put(contextSerializer, (Int16)Int16.MinValue); BasicTypeSerializer.Put(contextSerializer, (UInt32)UInt32.MaxValue); BasicTypeSerializer.Put(contextSerializer, (Int32)Int32.MinValue); BasicTypeSerializer.Put(contextSerializer, (UInt64)UInt64.MaxValue); BasicTypeSerializer.Put(contextSerializer, (Int64)Int64.MinValue); BasicTypeSerializer.Put(contextSerializer, (float)float.MaxValue); BasicTypeSerializer.Put(contextSerializer, (float)float.MinValue); BasicTypeSerializer.Put(contextSerializer, "Unicode String"); BasicTypeSerializer.Put(contextSerializer, "ASCII String", true); BasicTypeSerializer.Put(contextSerializer, new byte[] { byte.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, byte.MaxValue }); BasicTypeSerializer.Put(contextSerializer, new ushort[] { ushort.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt16.MaxValue }); BasicTypeSerializer.Put(contextSerializer, new UInt32[] { UInt32.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt32.MaxValue }); BasicTypeSerializer.Put(contextSerializer, new UInt64[] { UInt64.MinValue, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, UInt64.MaxValue }); byte byteValue = 0; UInt16 UInt16Value = 0; Int16 Int16Value = 0; UInt32 UInt32Value = 0; Int32 Int32Value = 0; UInt64 UInt64Value = 0; Int64 Int64Value = 0; float floatValue = 0.0F; string UnicodeString = null; string AsciiString = null; byte[] byteArray = null; ushort[] ushortArray = null; UInt32[] UInt32Array = null; UInt64[] UInt64Array = null; Debug.Print("sizeof(byte)=" + sizeof(byte)); Debug.Print("sizeof(UInt16)=" + sizeof(UInt16)); Debug.Print("sizeof(Int16)=" + sizeof(Int16)); Debug.Print("sizeof(UInt32)=" + sizeof(UInt32)); Debug.Print("sizeof(Int32)=" + sizeof(Int32)); Debug.Print("sizeof(UInt64)=" + sizeof(UInt64)); Debug.Print("sizeof(Int64)=" + sizeof(Int64)); Debug.Print("sizeof(float)=" + sizeof(float)); Debug.Print("sizeof(double)=" + sizeof(double)); var contextDeserializer = new BasicTypeDeSerializerContext(contextSerializer.GetBuffer()); byteValue = BasicTypeDeSerializer.Get(contextDeserializer); if (byteValue != byte.MaxValue) { throw new ApplicationException("byteValue"); } UInt16Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt16Value); if (UInt16Value != UInt16.MaxValue) { throw new ApplicationException("UInt16Value"); } Int16Value = BasicTypeDeSerializer.Get(contextDeserializer, Int16Value); if (Int16Value != Int16.MinValue) { throw new ApplicationException("Int16Value"); } UInt32Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt32Value); if (UInt32Value != UInt32.MaxValue) { throw new ApplicationException("UInt32Value"); } Int32Value = BasicTypeDeSerializer.Get(contextDeserializer, Int32Value); if (Int32Value != Int32.MinValue) { throw new ApplicationException("Int32Value"); } UInt64Value = BasicTypeDeSerializer.Get(contextDeserializer, UInt64Value); if (UInt64Value != UInt64.MaxValue) { throw new ApplicationException("UInt64Value"); } Int64Value = BasicTypeDeSerializer.Get(contextDeserializer, Int64Value); if (Int64Value != Int64.MinValue) { throw new ApplicationException("Int64Value"); } floatValue = BasicTypeDeSerializer.Get(contextDeserializer, floatValue); if (floatValue != float.MaxValue) { throw new ApplicationException("floatValue"); } floatValue = BasicTypeDeSerializer.Get(contextDeserializer, floatValue); if (floatValue != float.MinValue) { throw new ApplicationException("floatValue"); } UnicodeString = BasicTypeDeSerializer.Get(contextDeserializer, ""); if (UnicodeString != "Unicode String") { throw new ApplicationException("UnicodeString"); } AsciiString = BasicTypeDeSerializer.Get(contextDeserializer, ""); if (AsciiString != "ASCII String") { throw new ApplicationException("AsciiString"); } byteArray = BasicTypeDeSerializer.Get(contextDeserializer, byteArray); if (byteArray[0] != byte.MinValue || byteArray[15] != byte.MaxValue) { throw new ApplicationException("byteArray"); } ushortArray = BasicTypeDeSerializer.Get(contextDeserializer, ushortArray); if (ushortArray[0] != ushort.MinValue || ushortArray[15] != ushort.MaxValue) { throw new ApplicationException("ushortArray"); } UInt32Array = BasicTypeDeSerializer.Get(contextDeserializer, UInt32Array); if (UInt32Array[0] != UInt32.MinValue || UInt32Array[15] != UInt32.MaxValue) { throw new ApplicationException("UInt32Array"); } UInt64Array = BasicTypeDeSerializer.Get(contextDeserializer, UInt64Array); if (UInt64Array[0] != UInt64.MinValue || UInt64Array[15] != UInt64.MaxValue) { throw new ApplicationException("UInt64Array"); } }
public void Get(BasicTypeDeSerializerContext context) { Time = TimeStamp.Get(context); Values = BasicTypeDeSerializer.Get(context, Values); }