public TelesarVSharedMemory() { try { data.init(); dbuf = new byte[1432]; //FastStructure.SizeOf<shmem_T5_data>()]; buffer = new SharedMemory.BufferReadWrite("T5MA_MMF_", dbuf.Length, false); }catch (Exception e) { Debug.Log(e.ToString()); } }
// Use this for initialization void Start() { try { Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.target)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.hardware)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.shoulder)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.glove)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.joints)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.sensors)); Debug.Log(System.Runtime.InteropServices.Marshal.SizeOf(data.status)); data.init(); dbuf = new byte[1432]; //FastStructure.SizeOf<shmem_T5_data>()]; buffer = new SharedMemory.BufferReadWrite("T5MA_MMF_", dbuf.Length, false); }catch (Exception e) { Debug.Log(e.ToString()); } }
public Form1() { InitializeComponent(); const int size = 1024; const int length = 1024; int value = 1; richTextBox1.AppendText("Using Shared Memory"); while (value <= 100) { try { //using (var mmf = MemoryMappedFile.OpenExisting(args)) //{ using (var consumer = new SharedMemory.BufferReadWrite(name: "CountingBuffer")) { //MemoryMappedViewStream mmvStream = mmf.CreateViewStream(0, size); //BinaryFormatter formatter = new BinaryFormatter(); //byte[] buffer = new byte[size]; //Message msg; //richTextBox1.AppendText("found Counting file\n"); //while (mmvStream.CanRead) //{ // richTextBox1.AppendText("Reading mmvStream\n"); // mmvStream.Read(buffer, 0, size); // msg = (Message)formatter.Deserialize(new MemoryStream(buffer)); // DateTime now = DateTime.UtcNow; // long unixTime = ((DateTimeOffset)now).ToUnixTimeSeconds(); // //if (msg.timestamp != unixTime) // //{ // // msg.count++; // // richTextBox1.AppendText("Incrementing count: " + msg.count + "\n"); // //} // //value = msg.count; // richTextBox1.AppendText("Count: " + msg.count); // richTextBox1.AppendText("Timestamp: " + msg.timestamp); // formatter.Serialize(mmvStream, msg); // mmvStream.Seek(0, System.IO.SeekOrigin.Begin); //} int count; long timestamp; consumer.Read <int>(out count, 0); consumer.Read <long>(out timestamp, 500); richTextBox1.AppendText("Count: " + count.ToString() + ", timestamp: " + timestamp.ToString()); } } catch (Exception ex) { richTextBox1.AppendText(ex.ToString()); value = 101; break; } } }
public Form1() { InitializeComponent(); const int size = 1024; const int length = 1024; DateTime now = DateTime.UtcNow; long unixTime = ((DateTimeOffset)now).ToUnixTimeSeconds(); //MemoryMappedFileSecurity security = new MemoryMappedFileSecurity(); //security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); ////using (var mmf = MemoryMappedFile.CreateFromFile(@"C:\Users\Rigdon\Documents\Visual Studio 2017\Projects\FaultyOSParent\FaultyOSParent\bin\Debug\counting.txt", //// System.IO.FileMode.Open, "Counting", length)) ////{ ////using (var mmf = MemoryMappedFile.CreateFromFile(@"C:\Users\Rigdon\Documents\temp\faultyosparent\FaultyOSParent\bin\Debug\counting.txt", FileMode.Open, "CountingMapForAssignment", length)) ////{ //using (var mmf = MemoryMappedFile.CreateFromFile( // new FileStream(@"C:\Users\Rigdon\Documents\temp\faultyosparent\FaultyOSParent\bin\Debug\counting.txt", FileMode.Create), // "CountingMapFile", // 1024 * 1024, // MemoryMappedFileAccess.ReadWrite, // HandleInheritability.Inheritable, // false)) using (var producer = new SharedMemory.BufferReadWrite(name: "CountingBuffer", bufferSize: 1024)) { //using (var accessor = mmf.CreateViewAccessor(0, length * 2)) //{ // Message msg; // msg.count = "1"; // msg.timestamp = unixTime.ToString(); // for (int i = 0; i < length; i++) // { // //accessor.Read(i, out msg); // //if (msg.timestamp != unixTime) // // msg.count += 1; // accessor.Write(i, ref msg); // } //} //MemoryMappedViewAccessor fileMapView = mmf.CreateViewAccessor(); //fileMapView.Write(0, 1000); //Container MyContainer = new Container(); //fileMapView.Write<Container>(4, ref MyContainer); int count = 1; producer.Write <int>(ref count, 0); producer.Write <long>(ref unixTime, 500); //MemoryMappedViewStream mmvStream = mmf.CreateViewStream(0, length); //Message msg = new Message(); //msg.timestamp = unixTime.ToString(); //msg.count = "1"; //BinaryFormatter formatter = new BinaryFormatter(); //formatter.Serialize(mmvStream, msg); //mmvStream.Seek(0, System.IO.SeekOrigin.Begin); } //Process childProcess = new Process(); ////childProcess.StartInfo.FileName = "C:/Users/Rigdon/Documents/Visual Studio 2017/Projects/FaultyOSChild/FaultyOSChild/bin/Debug/FaultyOSChild.exe"; //childProcess.StartInfo.FileName = "FaultyOSChild.exe"; //childProcess.StartInfo.UseShellExecute = false; //childProcess.StartInfo.Arguments = "CountingMapFile"; ////childProcess.StartInfo.CreateNoWindow = false; //childProcess.Start(); //while (true) ; }