I have “no route to host” error when I try to send data to my Arduino.
Arduino hasn’t problems at all. I sent many commands to him with simple code on C# and Python through VS and PyCharm
So he’s ok.
There’s code:
// ViewController.cs
using System;
using AppKit;
using Foundation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace Control
{
public partial class ViewController : NSViewController
{
public ViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidAppear()
{
base.ViewDidAppear();
this.View.Window.BackgroundColor = NSColor.Black;
this.View.Window.Title = "Control";
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Do any additional setup after loading the view.
}
public void GetRgb(ref int red, ref int green, ref int blue)
{
colorPicker.Color.GetRgba(out nfloat r, out nfloat g, out nfloat b, out nfloat a);
red = (int)(r * 255);
green = (int)(g * 255);
blue = (int)(b * 255);
}
public void SendData(ref long dateToSend, int r, int g, int b)
{
dateToSend = (dateToSend << 8) + BitConverter.GetBytes(b)[0]; // Blue
dateToSend = (dateToSend << 8) + BitConverter.GetBytes(g)[0]; // Green
dateToSend = (dateToSend << 8) + BitConverter.GetBytes(r)[0]; // Red
dateToSend = (dateToSend << 8) + 0x02; // RGB color space
dateToSend = (dateToSend << 8) + 0x01; // MonoColor mode
dateToSend = (dateToSend << 8) + 0xa0; // AnimationMode change
}
partial void actionButtonSet(NSObject sender)
{
int red = 0, green = 0, blue = 0;
long date = 0;
GetRgb(ref red, ref green, ref blue); // get RGB colors from NSColorWell
SendData(ref date, red, green, blue); // saving commands for send
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect("192.168.1.3", 80);
NetworkStream stream = tcpClient.GetStream();
stream.Write(BitConverter.GetBytes(date));
Thread.Sleep(30);
tcpClient.Close();
} finally
{
tcpClient.Dispose();
}
}
public override NSObject RepresentedObject {
get {
return base.RepresentedObject;
}
set {
base.RepresentedObject = value;
// Update the view, if already loaded.
}
}
}
}
actionButtonSet is button which should to take color from NSColorWell and to send it to 192.168.1.3:80 IP
I think my app haven’t permission to connect to unit in my private network, but I dunno how to give that permission
pls help me with that, how I can fix that issue
—- Edited —-
My thoughts were right.
I tested simple code in VS and he’s ask for permission.
I give it to him and simple code did it.
Problem is in another now.
How to give permissions to app?
3