Visual Studio 2015 Background Application GrovePi.dll - c#

using System.Text;
using System.Net.Http;
using Windows.ApplicationModel.Background;
using GrovePi.Sensors;
using GrovePi.Common;
using GrovePi.I2CDevices;
using System.IO;
using System.Data;
using Windows.Devices;
using GrovePi;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CompassXYZ
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Pin Compass = Pin.DigitalPin3;
string CompassX = Compass.ToString();
string CompassY = Compass.ToString();
string CompassZ = Compass.ToString();
while (true)
{
System.Diagnostics.Debug.WriteLine($"X = {CompassX.GetHashCode()}, Y = {CompassY.GetHashCode()}, Z = {CompassZ.GetHashCode()}");
}
}
}
}
Hi Guys!
I'm a student trying to display 3 values from my Compass sensor on my GrovePi connected to my raspberry pi 3 running on Visual Studio 2015 Background Application, I need some pointers on how to display it correctly, so I really hope you guys could help me. Thanks!

Related

"Can't find" NS*Types (eg. NSFileManager or NSUrl) in Xamarin Forms project

I get "Not Found" errors in Xamarin Forms with things like NSFileManager and NSUrl. These are my imports of my class where I'm getting these errors:
using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
And the class which I'm using is located in DrinkUp.iOS.
Whenever and wherever I type something with the NS prefix it says that it could not find the object. Can someone please tell me what I'm doing wrong here?
Here's my full class
using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Video), typeof(VideoRenderer))]
namespace DrinkUp.iOS.Renderers
{
public class VideoRenderer : ViewRenderer<Video, UIView>
{
MPMoviePlayerController videoPlayer;
object notification = null;
void InitVideoPlayer()
{
var path = Path.Combine(NSBundle.MainBundle.BundlePath, Element.Source);
if (!NSFileManager.DefaultManager.FileExists(path)) {
Console.WriteLine("Video not exist");
videoPlayer = new MPMoviePlayerController();
videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = MPMovieRepeatMode.One;
videoPlayer.View.BackgroundColor = UIColor.Clear;
SetNativeControl(videoPlayer.View);
return;
}
// Load the video from the app bundle.
NSUrl videoURL = new NUrl(path, false);
// Create and configure the movie player.
videoPlayer = new MPMoviePlayerController(videoURL);
videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = Element.Loop ? MPMovieRepeatMode.One : MPMovieRepeatMode.None;
videoPlayer.View.BackgroundColor = UIColor.Clear;
foreach (UIView subView in videoPlayer.View.Subviews) {
subView.BackgroundColor = UIColor.Clear;
}
videoPlayer.PrepareToPlay();
SetNativeControl(videoPlayer.View);
}
}
}
The first comment worked, I had to get the NS types from Foundation.
Like Foundation.NSUrl etc. This fixed my problem.

C# Emgu, could not be found Capture and HaarCascade

What did I miss?
VS could not be found Capture and HaarCascade.
I added all opencv .dll and "Copy always".
And added References of Emgu.
My Emgu is emgucv-windesktop 3.2.0.2682-сuda. Visual Studio 2017
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
using System.Windows;
namespace Emgu.FaceDetection
{
public partial class Form1 : Form
{
private Capture cap;
private HaarCascade haar;
public Form1()
{
InitializeComponent();
}
}
}
You can't use HaarCascade when using EmguCV3.X, it has been deprecated and replaced with CascadeClassifier
See here for an explination, the summary being it has changed to something akin to this:
CascadeClassifier _cascadeClassifier = new CascadeClassifier(#"C:\OPENCV_3.0.0\opencv\build\etc\haarcascades\" + "haarcascade_frontalface_alt2.xml");
A more complete example, and tutorial, using 3.X can be found here, a snippet from that blog:
private CascadeClassifier _cascadeClassifier;
_cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");
using (var imageFrame = _capture.QueryFrame().ToImage<Bgr, Byte>())
{
if (imageFrame != null)
{
var grayframe = imageFrame.Convert<Gray, byte>();
var faces = _cascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty); //the actual face detection happens here
foreach (var face in faces)
{
imageFrame.Draw(face, new Bgr(Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them
}
}
imgCamUser.Image = imageFrame;
}

Windows.Storage error: the type of namespace Storage does not exist in namespace windows

I am very new to C#, visual studio, and related Microsoft work. So it is very likely that I messed something up and I hope some one can help me a bit on this.
I create an Console application and I am trying to run some tutorial C# code. There is a red line under when I try to load Windos.Storage.Pickers and all namespaces after it. I attempt to add the references, but I can't find what I need there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.Graphics.Imaging;
using Windows.Media.FaceAnalysis;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Shapes;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
FaceDetector faceDetector;
IList<DetectedFace> detectedFaces;
FileOpenPicker photoPicker = new FileOpenPicker();
photoPicker.ViewMode = PickerViewMode.Thumbnail;
photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
photoPicker.FileTypeFilter.Add(".jpg");
photoPicker.FileTypeFilter.Add(".jpeg");
photoPicker.FileTypeFilter.Add(".png");
photoPicker.FileTypeFilter.Add(".bmp");
StorageFile photoFile = await photoPicker.PickSingleFileAsync();
if (photoFile == null)
{
return;
}
}
}
}
the namespace you are tying to use is use for UWP development.
The problem is that you are trying to use it in Console Development.
Read about it here

troubles with running SlimDX C# application on Windows XP machine

I've made a simple C# WinForms app, which makes a screen-capture
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
using SlimDX;
namespace KMPP
{
public class DxScreenCapture
{
Device d;
public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}
public Surface CaptureScreen()
{
Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}
now to call it:
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SlimDX.Direct3D9;
using SlimDX;
using KMPP;
using System.Diagnostics;
using System.Threading;
namespace dxcapture
{
public partial class Form1 : Form
{
DxScreenCapture sc = new DxScreenCapture();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
DateTime current = DateTime.Now;
string n = string.Format(#"text-{0:yyyy-MM-dd_hh-mm-ss-tt}.bmp",DateTime.Now);
string directory = (#"C:\temp\");
string name = (".bmp");
string filename = String.Format("{0:hh-mm-ss}{1}", DateTime.Now, name);
string path = Path.Combine(directory, filename);
stopwatch.Start();
Thread.Sleep(1000);
Surface s = sc.CaptureScreen();
Surface.ToFile(s, path, ImageFileFormat.Bmp);
stopwatch.Stop();
s.Dispose();
textBox1.Text = ("Elapsed:" + stopwatch.Elapsed.TotalMilliseconds);
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
Everything works fine when I run this app on Windows 7 x64 (it was compiled here)
Unfortunately, when I try to run this app on Windows XP x86 machine - I'm getting following error:
How I tried to fix it?
installed latest DX on WinXP
installed latest SlimDX on WinXP (btw this step solved my previous problem)
installed latest .Net Framework v.4 on WinXP
compiled this app as x86 and used SlimDX.dll x86 for the same reason
I also put slimdx.dll into the same folder where dxcapture.exe (app name) is located
What might be the problem? Does WinXP support Directx9 screen capture?
edit: I've tried to comment-out different code-lines and it seems like "device creation" is the problem.. I mean this line:
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
WinXP machine has integrated ATI graphics, so, I don't know.. maybe that's the problem, maybe not, but I can't check my program on some other pc.
As mentioned in the bug report you filed, the problem appears to be with your system, whether it be missing DirectX components or your graphics adapter not supporting Direct3D 9. If your card doesn't at least support D3D9, you won't be able to use SlimDX (or any of the other DirectX wrappers) for any kind of rendering.

Registry Problem

I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.
using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string InstallPath, WoWExe, PatchPath;
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey LocalMachineKey_Existence;
MessageBox.Show("Browse your install location.", "Select Wow.exe");
OpenFileDialog BrowseInstallPath = new OpenFileDialog();
BrowseInstallPath.Filter = "wow.exe|*.exe";
if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
{
InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
WoWExe = InstallPath + "\\wow.exe";
PatchPath = InstallPath + "\\Data\\";
LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\ExistenceWoW");
LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
}
}
}
}
The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S
Look at this picture:
http://img21.imageshack.us/img21/2829/regedita.jpg
My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.
Can you debug and see what InstallPath contains?
Try it with Path.Combine instead of string concatenation, e.g.:
WowExe = Path.Combine(InstallPath, "wow.exe");
PatchPath = Path.Combine(InstallPath, #"\Data\");

Categories

Resources