aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-09-30 12:00:53 +0300
committerAvi Levkovich <avi@twine-s.com>2020-09-30 12:00:53 +0300
commitb2420e1b64c155020bd8b9355ea1135f6e4a9b36 (patch)
tree05938bf0bb21aa4aec17ef30132caddb8132e474 /Software/Stubs Collection
parentb0d3ccdbb8cd825c32a1f616223c9c391e0d1e14 (diff)
downloadTango-b2420e1b64c155020bd8b9355ea1135f6e4a9b36.tar.gz
Tango-b2420e1b64c155020bd8b9355ea1135f6e4a9b36.zip
Update VOC_Sensor Diagnostics
Diffstat (limited to 'Software/Stubs Collection')
-rw-r--r--Software/Stubs Collection/stubs/ConvertFloat2Bytes.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Software/Stubs Collection/stubs/ConvertFloat2Bytes.cs b/Software/Stubs Collection/stubs/ConvertFloat2Bytes.cs
new file mode 100644
index 000000000..dc980e438
--- /dev/null
+++ b/Software/Stubs Collection/stubs/ConvertFloat2Bytes.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Text;
+using System.Linq;
+using System.Drawing;
+using System.Diagnostics;
+using System.Windows.Forms;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using Tango.PMR.Stubs;
+using Tango.Stubs;
+
+
+
+public void OnExecute(StubManager stubManager)
+{
+ //see online Floating Point to Hex Converter (with Swap endianness) :https://gregstoll.com/~gregstoll/floattohex/
+ // ----------------- option 1 -------------------------------
+ stubManager.WriteLine("--- option 1 ---");
+ float value = 5.2F;
+ var byteArray1 = new byte[4];// a single float is 4 bytes/32 bits
+ byteArray1 = BitConverter.GetBytes(value);
+
+ //print
+ for(int i =0;i<4;i++)
+ {
+ stubManager.WriteHex(byteArray1[i],2);
+ stubManager.Write(" ");
+ }
+ stubManager.WriteLine("");
+ stubManager.WriteLine("");
+
+ // ----------------- option 2 for buffer -------------------------------
+ stubManager.WriteLine("--- option 2 ---");
+ var floatArray1 = new float[] {5.2f, 1.2f, 3.7f};
+
+
+ // create a byte array and copy the floats into it...
+ var byteArray = new byte[floatArray1.Length * 4];// a single float is 4 bytes/32 bits
+ Buffer.BlockCopy(floatArray1, 0, byteArray, 0, byteArray.Length);
+
+ //print
+ for(int j =0;j<floatArray1.Length;j++)
+ {
+ for(int i =0;i<4;i++)
+ {
+ stubManager.WriteHex(byteArray[j+i],2);
+ stubManager.Write(" ");
+ }
+ stubManager.WriteLine("");
+ }
+
+
+} \ No newline at end of file