public static OCBotMemory Reload(string CustomName = "OpenCollarBot")
        {
            if (!File.Exists(CustomName + ".json"))
            {
                return(new OCBotMemory());                                    // We Must comply with the Singleton Pattern
            }
            try
            {
                if (instance != null)
                {
                    if (instance.SingletonInitialized)
                    {
                        return(Memory);
                    }
                }
            }
            catch (Exception e)
            {
            }
            SerialManager sm  = new SerialManager();
            OCBotMemory   ocb = sm.Read <OCBotMemory>(CustomName);

            ocb.CheckIntegrity();
            return(ocb);
        }
Example #2
0
    public void OpenSerialPort()
    {
        if (port == null)
        {
            port = new SerialPort();
            PortSetup(port, portName);
        }

        // Check if the port is already open
        if (!port.IsOpen)
        {
            port = new SerialPort();
            PortSetup(port, portName);
            port.Open();
        }

        port.DiscardInBuffer();

        if (readThread == null || (readThread != null && !readThread.IsAlive))
        {
            readThread = new Thread(() => SerialManager.Read(this));
            readThread.Start();
        }

        port.DiscardInBuffer();
    }
Example #3
0
        private SerialManager GetSM(string EntName)
        {
            XmlDocument xd = new XmlDocument();

            xd.Load("EntersConfig.xml");
            XmlNode node = xd.SelectSingleNode("Enters");

            if (node.ChildNodes.Count == 0)  //如果没有找到下属节点,说明配置错误
            {
                return(null);
            }
            XmlNodeList   nl = node.ChildNodes;
            SerialManager sm = null;

            foreach (XmlNode nod in nl)
            {
                if (nod.Name == EntName)
                {
                    SerialManager.Enters ent = (SerialManager.Enters)System.Enum.Parse(typeof(SerialManager.Enters), EntName);
                    string val = ((XmlElement)nod).GetAttribute("value");
                    sm = new SerialManager(ent, val);
                    return(sm);
                }
            }
            return(null);
        }
Example #4
0
    public void ClickedStartBtn()
    {
        int timer = (StaticVariableField.MinuteTimer * 60) + (StaticVariableField.SecondTimer);

        if (timer > 0)
        {
            createDomino.Create(timer);
            dominoTimerManager.StartDomino(timer);
            //cameraMove.CameraStart();
            mainCanvas.enabled = false;
        }
        else
        {
            if (!StaticVariableField.StartVibeFlag_bool)
            {
                SerialManager.Write("7");
                StaticVariableField.StartVibeFlag_bool = true;
            }
            else
            {
                SerialManager.Write("8");
                StaticVariableField.StartVibeFlag_bool = false;
            }
        }
        SelectSE_Play();
    }
Example #5
0
        public override void LoadContent()
        {
            if (Content == null)
            {
                Content = new ContentManager(XnaDartsGame.ScreenManager.Game.Services, @"Content");
            }

            _background = Content.Load <Texture2D>(@"Images\Backgrounds\AbstractBackground");
            // XnaDartsGame.Options.Theme

            SerialManager.Instance().OnDartRegistered = _registerDart;
            SerialManager.Instance().OnDartHit        = null;

            _dartboard = new Dartboard();
            _dartboard.LoadContent(Content);
            _dartboard.OnSegmentClicked += _registerDart;
            _dartboard.Scale             = 0.5f;

            _playerChangeScreen = new PlayerChangeScreen("Player Change",
                                                         TimeSpan.FromSeconds(XnaDartsGame.Options.PlayerChangeTimeout));
            _playerChangeScreen.LoadContent();
            _playerChangeScreen.OnTimeout += _playerChange;

            _throwDartsScreen                 = new TimeoutScreen(Mode.CurrentPlayer.Name + " throw darts!", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen            = new TimeoutScreen("Round 1", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen.OnTimeout += _startTurn;

            foreach (var drawableGameComponent in GuiComponents)
            {
                drawableGameComponent.LoadContent(Content);
            }

            _startGame();
        }
Example #6
0
        private void ProcStartSend(object obj)
        {
            int       index     = (int)obj;
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x03);

            byte[] frameData   = new byte[20];
            int    frameLength = 0;

            try
            {
                SerialManager.Send(new byte[] { 0x18, 0x01 }, 0, 2);
                Thread.Sleep(500);

                SerialManager.Send(new byte[] { 0x03, (byte)(index + 1) }, 0, 2);
                string txt = "";
                if (frameUnit.WaitData(15000))
                {
                    frameLength = frameUnit.ReadTotalData(frameData, frameData.Length);

                    if (frameData[7] == 0x81) //返回成功
                    {
                    }
                }
                ShowSendEnd(txt);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrameUnit(frameUnit);
            }
        }
Example #7
0
        private void ProcVersion()
        {
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x01);

            byte[] frameData   = new byte[20];
            int    frameLength = 0;

            try
            {
                SerialManager.Send(new byte[] { 0x01, 0x00 }, 0, 2);
                string txt = "";
                if (frameUnit.WaitData(2000))
                {
                    frameLength = frameUnit.ReadTotalData(frameData, frameData.Length);

                    if (frameData[4] == 0x77) //返回成功
                    {
                        txt = "版本:" + frameData[6] + "." + frameData[7] + " 日期:" + frameData[8] + "月" + frameData[9] + "日";
                    }
                }
                ShowVersion(txt);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrameUnit(frameUnit);
            }
        }
Example #8
0
        /// <summary>
        /// If TCP client receive data from server
        /// </summary>
        /// <param name="data"></param>
        private static void TcpListenTask(byte[] data)
        {
            string dataStr = Encoding.ASCII.GetString(data);

            string[] itemStrings = dataStr.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            if (itemStrings[0] == "Motor")
            {
                SerialManager tempSerialManager       = SerialManager.GetInstance();
                SerialManager.SerialPortWithGuid port = tempSerialManager.GetPort(RaspberrySerial.PortGuid);

                byte[] serialBytes = new byte[8];
                serialBytes[0] = 0x01;
                for (int i = 1; i < 5; i++)
                {
                    serialBytes[i] = Convert.ToByte(itemStrings[i]);
                }
                int time = Convert.ToInt32(itemStrings[5]);
                serialBytes[5] = (byte)(time / 256);
                serialBytes[6] = (byte)(time % 256);
                serialBytes[7] = 0xFF;
                port.Send(serialBytes);
            }
            else if (itemStrings[0] == "AcquirePicture")
            {
                SendPicture();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
 public PhysicalBike(String COMPort, IX7DataListener listener)
 {
     Outgoing = new Queue <string>();
     Manager  = new SerialManager(listener, this, COMPort, 9600, 0);
     worker   = new Thread(new ThreadStart(Manager.Start));
     worker.Start();
 }
Example #10
0
 // Start is called before the first frame update
 void Start()
 {
     if ((serial = gameObject.GetComponent <SerialManager>()) == null)
     {
         Debug.LogError("serial is NULL in ArdManager");
     }
 }
        public void Save(string CustomName)
        {
            //if (!File.Exists("OpenCollarBot.bdf")) return;
            SerialManager sm = new SerialManager();

            sm.Write <OCGroupCaches>("GroupCache/" + CustomName, this);
            sm = null;
        }
Example #12
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.V))
     {
         SerialManager.Write("9");
         Debug.Log("9");
     }
 }
Example #13
0
        public void Save(string CustomName = "OpenCollarBot")
        {
            //if (!File.Exists("OpenCollarBot.bdf")) return;
            SerialManager sm = new SerialManager();

            sm.Write <OCBotMemory>(CustomName, this);
            sm = null;
        }
Example #14
0
 /// <summary>
 /// 获取对应进制下的序列号
 /// </summary>
 /// <returns></returns>
 private string GetSNByEnter(SerialManager sm, int sn)
 {
     if (sm == null)
     {
         return(sn.ToString());
     }
     return(sm.GetEnterString(sn));
 }
Example #15
0
        /// <summary>
        /// 下传标准组态信息
        /// 2017-04-14 调整至基类中
        /// </summary>
        public virtual void SendStandardLinkageConfigInfo()
        {
            if (StandardLinkageConfigList != null)
            {
                if (StandardLinkageConfigList.Count > 0)
                {
                    byte[] sendingData = AssemblePackageBC(StandardLinkageConfigList[0]);

                    if (SendingCMD == "BC" && ReceivedBCConfirmCommand) //如果先前发送的BC命令,已收到66确认命令,则发送下一条数据
                    {
                        //if (lstPackagesByteses.Count > 0)
                        if (StandardLinkageConfigList.Count > 0) //移除已发送的数据
                        {
                            StandardLinkageConfigList.RemoveAt(0);
                        }

                        if (StandardLinkageConfigList.Count > 0)  //##edit
                        {
                            sendingData = AssemblePackageBC(StandardLinkageConfigList[0]);
                            SendingCMD  = "BC";
                            //    log.Info("Send BC Message && 66:");
                            ReceivedBCConfirmCommand = false;
                            SerialManager.WriteData(sendingData);
                        }
                        else
                        {
                            SetStatusForStandardLinkageConfigDownloaded();
                            SendingCMD = "BA";
                            //需要发送设置完成
                            SerialManager.WriteData(AssemblePackageBA());
                            ReceivedBAConfirmCommand = false;
                        }
                    }
                    else //否则重发本条数据
                    {
                        if (sendingData != null)
                        {
                            SendingCMD = "BC";
                            //  log.Info("Send BC Message && Without 66:");
                            SerialManager.WriteData(sendingData);
                        }
                    }
                }
                else
                {
                    Status = ControllerStatus.DataSended;
                    StandardLinkageConfigDownloaded = true;
                }
            }
            else
            {
                Status = ControllerStatus.DataSended;
                StandardLinkageConfigDownloaded = true;
            }
        }
Example #16
0
        private void cancelScreen()
        {
            showOptionsSaveResult();

            if (_hasChangedSerialSettings)
            {
                SerialManager.Instance().UpdateSerialPortPropertiesFromOptions();
            }

            base.CancelScreen();
        }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #18
0
        public void Update()
        {
            _lastKeyboarstState   = _currentKeyboardState;
            _currentKeyboardState = Keyboard.GetState();

            _lastMouseState   = CurrentMouseState;
            CurrentMouseState = Mouse.GetState();

            LastBoardButtonStates    = CurrentBoardButtonStates;
            CurrentBoardButtonStates = SerialManager.Instance().ButtonStates;
        }
 public void PlayFinishSE()
 {
     finishSE.Play();
     if (StaticVariableField.StartVibeFlag_bool)
     {
         Debug.Log("SerialPort_SendMessege_EndAction");
         //ドミノ終了時にバイブマンに送る信号
         SerialManager.Write("8");
         StaticVariableField.StartVibeFlag_bool = false;
     }
 }
Example #20
0
 /// <summary>
 /// Creates the form.
 /// </summary>
 public frmLobby()
 {
     InitializeComponent();
     activeForm         = null;
     leftBorderBtn      = new Panel();
     leftBorderBtn.Size = new Size(7, 90);
     pnlMenu.Controls.Add(leftBorderBtn);
     this.Text           = string.Empty;
     this.ControlBox     = false;
     this.DoubleBuffered = true;
     smr = new SerialManager <List <Robot> >();
     smb = new SerialManager <List <MaterialBucket> >();
 }
 public void StartDomino(int settingTime)
 {
     timeCount_bool = true;
     ratchTime      = settingTime;
     shotSECounter  = (int)Mathf.Ceil((ratchTime) % 60);
     Debug.Log("RatchTime : " + ratchTime.ToString());
     if (!StaticVariableField.StartVibeFlag_bool)
     {
         StaticVariableField.StartVibeFlag_bool = true;
         Debug.Log("SerialPort_SendMessege_StartAction");
         //ドミノ開始時にバイブマンに送る信号
         SerialManager.Write("7");
     }
 }
Example #22
0
        public BindSegmentScreen(string text, IntPair selectedSegment)
            : base("Bind Segments", text, MessageBoxButtons.Cancel)
        {
            _clear.OnSelected += clear_OnSelected;

            SelectedSegment = selectedSegment;

            MenuItems.Items.Add(_clear);

            MenuItems.Items.Reverse(); //Want clear to end up at the top of the list so reverse

            SerialManager.Instance().OnDartRegistered = null;
            SerialManager.Instance().OnDartHit        = handleDart;
        }
        public static OCGroupCaches Reload(string CustomName)
        {
            if (!File.Exists("GroupCache/" + CustomName + ".json"))
            {
                return(new OCGroupCaches());
            }
            SerialManager sm  = new SerialManager();
            OCGroupCaches ocb = sm.Read <OCGroupCaches>("GroupCache/" + CustomName);

            if (ocb == null)
            {
                return(new OCGroupCaches());
            }
            return(ocb);
        }
Example #24
0
    // Use this for initialization
    void Start()
    {
        //temp_bullet.renderer.material.color(1, 1, 1, 0);
        gun         = (GameObject.FindGameObjectWithTag("gun"));
        temp_bullet = (GameObject.FindGameObjectWithTag("EditorOnly"));
        temp_bullet.transform.parent = gun.transform;

        mySerialManager = new SerialManager();
        mySerialManager.SetSerialPort("COM3");
        mySerialManager.SetReadTimeout(100);
        mySerialManager.SetWriteTimeout(100);
        mySerialManager.SetSerialOpen();

        i = 0;
    }
Example #25
0
        public IList <INVStockSerial> getSerialFromSerialIDS(string serialids)
        {
            IList <INVStockSerial> invss = new List <INVStockSerial>();
            SerialManager          sm    = new SerialManager();

            string[] serids = serialids.Split(',');
            foreach (string serid in serids)
            {
                if (serid != "")
                {
                    invss.Add(sm.GetSerialByID(Convert.ToInt32(serid)));
                }
            }
            return(invss);
        }
    // Use this for initialization
    void Start()
    {
        if (!serialManager)
        {
            serialManager = GameObject.Find("GameManager").GetComponent <SerialManager>();
        }

        //Determine initial position based on Transform
        position = transform.position;
        //Setup camera variables
        cam    = Camera.main;
        height = 2f * cam.orthographicSize;
        width  = height * cam.aspect;

        turretScript = gameObject.GetComponentInChildren <TurretControl>();
    }
Example #27
0
 public void ClickedSecondBtn_Up()
 {
     if (StaticVariableField.SecondTimer < MAXSECONDTIME)
     {
         StaticVariableField.SecondTimer += SECOND;
     }
     else
     {
         StaticVariableField.SecondTimer = MINSECONDTIME;
     }
     if (StaticVariableField.StartVibeFlag_bool)
     {
         SerialManager.Write("8");
         StaticVariableField.StartVibeFlag_bool = false;
     }
     TimeTextChange();
     SelectSE_Play();
 }
Example #28
0
 public void ClickedMinuteBtn_Down()
 {
     if (StaticVariableField.MinuteTimer > MINMINUTETIME)
     {
         StaticVariableField.MinuteTimer -= MINUTE;
     }
     else
     {
         StaticVariableField.MinuteTimer = MAXMINUTETIME;
     }
     if (StaticVariableField.StartVibeFlag_bool)
     {
         SerialManager.Write("8");
         StaticVariableField.StartVibeFlag_bool = false;
     }
     TimeTextChange();
     SelectSE_Play();
 }
Example #29
0
        private async void Setup()
        {
            Logger.Log("Welcome to AstroPi!");


            Logger.Log("Configuring input manager...");

            _inputManager = new InputManger
            {
                OnInputRecieved = InputRecieved
            };

            Logger.Log("Configuring serial manager...");

            await SerialManager.Initialize();

            Logger.Log("AstroPi ready!");
        }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        if (!PhotonNetwork.isMasterClient)
        {
            switch (VibeManStates.WriteNumber)
            {
            case "9":
            {
                if (!vibe)
                {
                    SerialManager.Write("9");
                    Debug.Log("Vibe!!");
                    vibe = true;
                }
                StartCoroutine("Delay_Client_Write9");
                VibeManStates.WriteNumber = "";
                m_photonView.RPC("ResetWriteNumber", PhotonTargets.MasterClient);
                break;
            }

            case "8":
            {
                if (!vibe)
                {
                    SerialManager.Write("8");
                    Debug.Log("Vibe!!");
                    vibe = true;
                }
                StartCoroutine("Delay_Client_Write8");
                VibeManStates.WriteNumber = "";
                m_photonView.RPC("ResetWriteNumber", PhotonTargets.MasterClient);
                break;
            }
            }
        }

        /*else if(PhotonNetwork.isMasterClient)
         * {
         *  if(Input.GetButtonDown("Fire1") || Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.KeypadEnter))
         *  {
         *      ClickedVibeBtn();
         *  }
         * }*/
    }