示例#1
0
 private static void OnTimedEvent(Object source, ElapsedEventArgs e)
 {
     if (!isConnectedtoFSUIPC)
     {
         try
         {
             Console.Write(".");
             FSUIPCConnection.Open();
             isConnectedtoFSUIPC = true;
         } catch (Exception ex)
         {
             isConnectedtoFSUIPC = false;
         }
     }
     else
     {
         try
         {
             FSUIPCConnection.Process();
         } catch (Exception ex)
         {
             Errormessage.sendErrorMessage("FSUIPC Process", ex.Message);
             FSUIPCConnection.Close();
             isConnectedtoFSUIPC = false;
         }
     }
 }
示例#2
0
 // Send Value directly to Offset
 public void SendControlToFS(int controlNumber, int parameterValue)
 {
     try
     {
         Console.WriteLine("Called Offset : {0} = {1}", controlNumber, parameterValue);
         this.sendControl.Value  = controlNumber;
         this.controlParam.Value = parameterValue;
         FSUIPCProcess("sendControl");
     } catch (Exception ex)
     {
         Errormessage.sendErrorMessage("FSUIPC SendControlToFS", ex.Message);
     }
 }
示例#3
0
        public void setOffsetValue(string offsetname, string value)
        {
            if (fuipcoffsets.TryGetValue(offsetname, out OffsetItem op))
            {
                try
                {
                    switch (op.type.ToLower())
                    {
                    case "int":
                        (op.offset as Offset <int>).Value = Convert.ToInt32(value);
                        break;

                    case "byte":
                        (op.offset as Offset <byte>).Value = Convert.ToByte(value);
                        break;

                    case "long":
                        (op.offset as Offset <long>).Value = Convert.ToInt64(value);
                        break;

                    case "short":
                        (op.offset as Offset <short>).Value = Convert.ToInt16(value);

                        break;

                    case "bitarray":
                        (op.offset as Offset <BitArray>).Value = JsonConvert.DeserializeObject <BitArray>(value);
                        break;

                    default:
                        Errormessage.sendErrorMessage("FSUIPC setOffsetValue", "Invalid Type of Offset found");
                        break;
                    }
                } catch (Exception ex)
                {
                    Errormessage.sendErrorMessage("FSUIPC setOffsetValue", "Error while setting value");
                }
            }
            else
            {
                Errormessage.sendErrorMessage("FSUIPC setOffsetValue", "Offsetvalue not found");
            }
        }
示例#4
0
        void handleRequest(string name, MessageEventArgs e)
        {
            string json = "";

            //Console.WriteLine(!name.IsNullOrEmpty() ? String.Format("\"{0}\" to {1}", e.Data, name) : e.Data);
            Console.WriteLine("Name: {0}", name.IsNullOrEmpty() ? "-" : name);
            try {
                WS_Task ws_task = JsonConvert.DeserializeObject <WS_Task>(e.Data);
                Console.WriteLine(ws_task.taskname);
                Console.WriteLine(JsonConvert.SerializeObject(ws_task));
                if (ws_task.taskname == null)
                {
                    return;
                }
                switch (ws_task.taskname.ToUpper())
                {
                case "ADDOFFSET":
                    if (ws_task.offsetMessage != null)
                    {
                        fsuipcconnector.AddOffset(ws_task.offsetMessage);
                    }
                    else
                    {
                        Errormessage.sendErrorMessage("ADDOFFSET", "Invalid ADD Object");
                    }

                    break;

                case "GETPANELITEMS":
                    if (ws_task.panelname != null)
                    {
                        json = fsuipcconnector.getPanelState(ws_task.panelname);
                        Send(json);
                    }
                    else
                    {
                        Errormessage.sendErrorMessage("GETPANELITEMS", "NO Parameter Panelname");
                    }

                    break;

                case "SETVALUE":
                    if (ws_task.offsetname != null && ws_task.value != null)
                    {
                        fsuipcconnector.setOffsetValue(ws_task.offsetname, ws_task.value);
                        Send(json);
                    }
                    else
                    {
                        Errormessage.sendErrorMessage("SETVALUE", "OFFESTNAME and OFFSETVALUE REQUIRED");
                    }

                    break;

                case "SETVALUEDIRECT":
                    if (ws_task.offsetname != null && ws_task.value != null)
                    {
                        try
                        {
                            fsuipcconnector.SendControlToFS(Convert.ToInt32(ws_task.offsetname), Convert.ToInt32(ws_task.value));
                        } catch (Exception ex)
                        {
                            Errormessage.sendErrorMessage("SETVALUE", "OFFSETNAME and OFFSETVALUE mut be type int");
                        }
                    }
                    else
                    {
                        Errormessage.sendErrorMessage("SETVALUE", "OFFSETNAME and OFFSETVALUE REQUIRED");
                    }

                    break;

                case "CONNECT":
                    try
                    {
                        FSUIPCConnection.Open();
                        Console.WriteLine("Connected to {0}", FSUIPCConnection.FlightSimVersionConnected);
                    }
                    catch (FSUIPCException ex)
                    {
                    }

                    break;
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }