static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(FormProvider.getMain()); Application.Run(FormProvider.getMain()); }
// Non-static method public void sensorEventThread() { try { OpenZen.ZenInit(device_Handle); ZenEvent zenEvent = new ZenEvent(); Boolean connected = false; ZenSensorInitError sensorInitError = ZenSensorInitError.ZenSensorInitError_Max; // try three connection attempts for (int i = 0; i < 1; i++) { sensorInitError = OpenZen.ZenObtainSensor(device_Handle, mSensor, device_Sensor); if (sensorInitError == ZenSensorInitError.ZenSensorInitError_None) { connected = true; // Enable Disconnect Button MainForm mainForm = FormProvider.getMain(); switch (device_No) { case 1: if (mainForm.InvokeRequired) { mainForm.BeginInvoke((Action) delegate() { mainForm.device_List1.Enabled = false; mainForm.disconnect_Device1.Visible = true; mainForm.connect_Device1.Enabled = false; }); } else { mainForm.device_List1.Enabled = false; mainForm.disconnect_Device1.Visible = true; mainForm.connect_Device1.Enabled = false; } break; case 2: if (mainForm.InvokeRequired) { mainForm.BeginInvoke((Action) delegate() { mainForm.device_List2.Enabled = false; mainForm.disconnect_Device2.Visible = true; mainForm.connect_Device2.Enabled = false; }); } else { mainForm.device_List2.Enabled = false; mainForm.disconnect_Device2.Visible = true; mainForm.connect_Device2.Enabled = false; } break; case 3: if (mainForm.InvokeRequired) { mainForm.BeginInvoke((Action) delegate() { mainForm.device_List3.Enabled = false; mainForm.disconnect_Device3.Visible = true; mainForm.connect_Device3.Enabled = false; }); } else { mainForm.device_List3.Enabled = false; mainForm.disconnect_Device3.Visible = true; mainForm.connect_Device3.Enabled = false; } break; case 4: if (mainForm.InvokeRequired) { mainForm.BeginInvoke((Action) delegate() { mainForm.device_List4.Enabled = false; mainForm.disconnect_Device4.Visible = true; mainForm.connect_Device4.Enabled = false; }); } else { mainForm.device_List4.Enabled = false; mainForm.disconnect_Device4.Visible = true; mainForm.connect_Device4.Enabled = false; } break; } MessageBox.Show("Succesfully connected to sensor for Device #" + device_No.ToString()); break; } else { MessageBox.Show("Failed"); } } while (connected) { //Console.WriteLine(mZenHandle); if (OpenZen.ZenWaitForNextEvent(device_Handle, zenEvent)) { if (zenEvent.component.handle != 0) { switch (zenEvent.eventType) { case (int)ZenImuEvent.ZenImuEvent_Sample: count++; // read raw accelerometer OpenZenFloatArray raw_fa = OpenZenFloatArray.frompointer(zenEvent.data.imuData.aRaw); // read calibrated accelerometer OpenZenFloatArray fa = OpenZenFloatArray.frompointer(zenEvent.data.imuData.a); // read raw accelerometer OpenZenFloatArray raw_fg = OpenZenFloatArray.frompointer(zenEvent.data.imuData.gRaw); // read calibrated gyroscope OpenZenFloatArray fg = OpenZenFloatArray.frompointer(zenEvent.data.imuData.g); // read raw magnetometer OpenZenFloatArray raw_fb = OpenZenFloatArray.frompointer(zenEvent.data.imuData.bRaw); // read calibrated magnetometer OpenZenFloatArray fb = OpenZenFloatArray.frompointer(zenEvent.data.imuData.b); // read euler angle OpenZenFloatArray fr = OpenZenFloatArray.frompointer(zenEvent.data.imuData.r); // read quaternion OpenZenFloatArray fq = OpenZenFloatArray.frompointer(zenEvent.data.imuData.q); // Create new imuData object IMUData imuData = new IMUData( raw_fa.getitem(0), raw_fa.getitem(1), raw_fa.getitem(2), fa.getitem(0), fa.getitem(1), fa.getitem(2), raw_fg.getitem(0), raw_fg.getitem(1), raw_fg.getitem(2), fg.getitem(0), fg.getitem(1), fg.getitem(2), raw_fb.getitem(0), raw_fb.getitem(1), raw_fb.getitem(2), fb.getitem(0), fb.getitem(1), fb.getitem(2), fr.getitem(0), fr.getitem(1), fr.getitem(2), fq.getitem(0), fq.getitem(1), fq.getitem(2) ); // Push data in to the new imuData Object switch (device_No) { case (1): transferDevice1_Data(imuData); //Debug.WriteLine(count); break; case (2): transferDevice2_Data(imuData); break; case (3): transferDevice3_Data(imuData); break; case (4): transferDevice4_Data(imuData); Debug.WriteLine(count); break; } break; } } } } } catch (ThreadAbortException) { } }