Example #1
0
        private void UAS_Click(object sender, EventArgs e)
        {
            if (UAS_C == false)
            {
                UAS.Text = "Uncheck all Addons";
            }
            else
            {
                UAS.Text = "Check all Addons";
            }
            UAS.Refresh();

            for (int i = 0; i < surv_addons.Items.Count; i++)
            {
                if (UAS_C == false)
                {
                    surv_addons.SetItemCheckState(i, CheckState.Checked);
                }
                if (UAS_C == true)
                {
                    surv_addons.SetItemCheckState(i, CheckState.Unchecked);
                }
            }
            UAS_C = !UAS_C;
        }
        //public FileService FileService { get; set; }
        //public UserService UserService { get; set; }
        //public SubscriptionService SubscriptionService { get; set; }



        public OmniCoreSession(Address ip, [Optional] UAS uas) : base(ip, uas)
        {
            Address = ip;

            IsOmnicore        = true;
            TemplateUrl       = "https://{0}/{1}";
            AcceptHeader      = "application/hal+json;v=2.0";
            ContentTypeHeader = "application/x-www-form-urlencoded;v=2.0";

            UAS = uas ?? new UAS("Default User", "robotics");

            InitServices();
        }
Example #3
0
        private async Task SocketThreadAsync(HttpClient client, string ip, Dictionary <string, string> httpContent, UAS uas, CancellationToken cancelToken)
        {
            //post that you want to subscribe on values

            using (FormUrlEncodedContent fued = new FormUrlEncodedContent(httpContent))
            {
                var resp = await client.PostAsync(new Uri($"http://{ip}/subscription"), fued).ConfigureAwait(true);

                resp.EnsureSuccessStatusCode();

                //Get the ABB cookie, which will be used to connect to to the websocket
                var    header    = resp.Headers.FirstOrDefault(p => p.Key == "Set-Cookie");
                var    val       = header.Value.Last();
                string abbCookie = val.Split('=')[1].Split(';')[0];


                //Setup the websocket connection
                using (ClientWebSocket wSock = new ClientWebSocket())
                {
                    wSock.Options.Credentials = new NetworkCredential(uas.User, uas.Password);
                    wSock.Options.Proxy       = null;
                    CookieContainer cc = new CookieContainer();
                    cc.Add(new Uri($"http://{ip}"), new Cookie("ABBCX", abbCookie, "/", ip));
                    wSock.Options.Cookies           = cc;
                    wSock.Options.KeepAliveInterval = TimeSpan.FromMilliseconds(5000);
                    wSock.Options.AddSubProtocol("robapi2_subscription");

                    //Connect
                    await wSock.ConnectAsync(new Uri($"ws://{ip}/poll"), cancelToken).ConfigureAwait(true);

                    var bArr = new byte[1024];
                    ArraySegment <byte> arr = new ArraySegment <byte>(bArr);

                    SubscriptionSockets.Add(ValueChangedEventHandler, wSock);

                    while (ValueChangedEventHandler != null)
                    {
                        try
                        {
                            var res = await wSock.ReceiveAsync(arr, cancelToken).ConfigureAwait(true);

                            if (ValueChangedEventHandler == null)
                            {
                                break;
                            }

                            //parse message
                            var s = Encoding.ASCII.GetString(arr.Array);

                            s = s.Split(new string[] { "lvalue\">" }, StringSplitOptions.None)[1].Split('<')[0].Trim();

                            ValueChangedEventHandler(this, new IOEventArgs()
                            {
                                LValue = int.Parse(s, CultureInfo.InvariantCulture)
                            });
                        }
                        catch (Exception ex)
                        {
                            if (ex is WebSocketException && wSock.State == WebSocketState.Aborted)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }