public IndexForm() { #region 检查版本升级 #if !DEBUG Task.Run(async() => { while (true) { //检查版本升级 await CheckUpgradeAsync(); await Task.Delay(1000 * 60 * 60 * 1);//一小时 } }); #endif #endregion InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; FormBorderStyle = FormBorderStyle.FixedSingle; //加载模拟服务的历史数据 DataPersist.LoadData(); #region 初始化设置上次选择的tab var tabName = GetTabName(); if (!string.IsNullOrWhiteSpace(tabName)) { foreach (TabPage item in tabControl1.TabPages) { if (item.Name == tabName?.Trim()) { //设置上次选择的tab tabControl1.SelectedTab = item; } //还未实现,先隐藏 else if (item.Name == "OmronFinsTcp") { tabControl1.TabPages.Remove(item); } //加载用户控件 SelectedTab(item); } } //切换到上次选择的Tab SelectedTab(tabControl1.SelectedTab); #endregion Task.Run(async() => { await Task.Delay(1000 * 60 * 1);//1分钟自动保存一次 DataPersist.SaveData(); }); }
public IndexForm() { InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; FormBorderStyle = FormBorderStyle.FixedSingle; DataPersist.LoadData(); SelectedTab(tabControl1.SelectedTab); Task.Run(async() => { await Task.Delay(1000 * 60 * 1);//1分钟自动保存一次 DataPersist.SaveData(); }); }
public void GetLeaderboard(bool isFB, DataPersist dataPersist) { bool fbFailed = false; for (int i = 0; i < _entries.Count; i++) { Destroy(_entries[i]); } _entries.Clear(); if (isFB) { try { new LeaderboardDataRequest_highScoreLeaderboard().SetEntryCount(10).Send((response) => { foreach (var entry in response.Data) { GameObject go = Instantiate(_leaderboardEntryPrefab); go.transform.SetParent(_leaderboardGrid.transform, false); LeaderboardEntry leaderboardEntry = go.GetComponent <LeaderboardEntry>() as LeaderboardEntry; leaderboardEntry.rankString = entry.Rank.ToString(); leaderboardEntry.usernameString = entry.UserName.ToString(); leaderboardEntry.scoreString = entry.GetNumberValue("score").ToString(); leaderboardEntry.UpdateText(); _entries.Add(leaderboardEntry); } }); } catch { fbFailed = true; } } else { GameObject go = Instantiate(_leaderboardEntryPrefab); go.transform.SetParent(_leaderboardGrid.transform, false); LeaderboardEntry leaderboardEntry = go.GetComponent <LeaderboardEntry>() as LeaderboardEntry; string entry = dataPersist.readStringFromFile("scores"); string[] entries = dataPersist.parseFileString(entry); leaderboardEntry.rankString = "1"; leaderboardEntry.usernameString = entries[0].ToString(); leaderboardEntry.scoreString = entries[1].ToString(); _entries.Add(leaderboardEntry); } }
public ModBusRtuServer(string portName, int baudRate, int dataBits, StopBits stopBits) { if (serialPort == null) { serialPort = new SerialPort(); } serialPort.PortName = portName; serialPort.BaudRate = baudRate; serialPort.DataBits = dataBits; serialPort.StopBits = stopBits; serialPort.Encoding = Encoding.ASCII; #if !DEBUG serialPort.ReadTimeout = 1000;//1秒 #endif serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); dataPersist = new DataPersist("ModBusTcpServer"); }
public ModbusRtuServer(string portName, int baudRate, int dataBits, StopBits stopBits, Parity parity, int timeout = 1500) { if (serialPort == null) { serialPort = new SerialPort(); } serialPort.PortName = portName; serialPort.BaudRate = baudRate; serialPort.DataBits = dataBits; serialPort.StopBits = stopBits; serialPort.Encoding = Encoding.ASCII; serialPort.Parity = parity; serialPort.ReadTimeout = timeout; serialPort.WriteTimeout = timeout; serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); dataPersist = new DataPersist("ModbusTcpServer"); }
private void IndexForm_FormClosing(object sender, FormClosingEventArgs e) { DataPersist.SaveData(); }
public ModBusTcpServer_test() { DataPersist.LoadData(); }
/// <summary> /// /// </summary> /// <param name="port"></param> /// <param name="ip"></param> public MitsubishiA1EServer(int port, string ip = null) { this.ip = ip; this.port = port; dataPersist = new DataPersist("MitsubishiA1EServer"); }
private void button6_Click(object sender, EventArgs e) { DataPersist.Clear(); AppendText($"数据清空成功\r\n"); }
private void button3_Click(object sender, EventArgs e) { DataPersist.Clear(); txt_content.AppendText($"[{DateTime.Now.ToLongTimeString()}]数据清空成功\r\n\r\n"); }
/// <summary> /// 接收客户端发送的消息 /// </summary> /// <param name="newSocket"></param> void Receive(Socket newSocket) { while (newSocket.Connected) { try { byte[] requetData1 = new byte[8]; //读取客户端发送过来的数据 int readLeng = newSocket.Receive(requetData1, 0, requetData1.Length, SocketFlags.None); if (readLeng == 0)//客户端断开连接 { newSocket.Shutdown(SocketShutdown.Both); newSocket.Close(); return; } byte[] requetData2 = new byte[requetData1[5] - 2]; readLeng = newSocket.Receive(requetData2, 0, requetData2.Length, SocketFlags.None); if (readLeng == 0)//客户端断开连接 { newSocket.Shutdown(SocketShutdown.Both); newSocket.Close(); return; } var requetData = requetData1.Concat(requetData2).ToArray(); byte[] responseData1 = new byte[8]; //复制请求报文中的报文头 Buffer.BlockCopy(requetData, 0, responseData1, 0, responseData1.Length); DataPersist data = new DataPersist(redisConfig); switch (requetData[7]) { //读取线圈 case 1: //TODO break; //写入线圈 case 5: //TODO break; //读取 case 3: { var value = data.Read(requetData[9]);//TODO 数据存在 8、9 short.TryParse(value, out short resultValue); var bytes = BitConverter.GetBytes(resultValue); //当前位置到最后的长度 responseData1[5] = (byte)(3 + bytes.Length); //TODO byte[] responseData2 = new byte[3] { (byte)bytes.Length, bytes[1], bytes[0] }; var responseData = responseData1.Concat(responseData2).ToArray(); newSocket.Send(responseData); } break; //写入 case 16: { //TODO var value = requetData[requetData.Length - 2] * 256 + requetData[requetData.Length - 1]; data.Write(requetData[9], value.ToString()); var responseData = new byte[12]; Buffer.BlockCopy(requetData, 0, responseData, 0, responseData.Length); responseData[5] = 6; newSocket.Send(responseData); } break; } } catch (SocketException ex) { //todo if (ex.SocketErrorCode != SocketError.ConnectionRefused || ex.SocketErrorCode != SocketError.ConnectionReset) throw ex; } } }
/// <summary> /// /// </summary> /// <param name="port"></param> /// <param name="ip"></param> public OmronFinsServer(int port, string ip = null) { this.ip = ip; this.port = port; dataPersist = new DataPersist("OmronFinsServer"); }
public SiemensServer(int port, string ip = null) { this.ip = ip; this.port = port; dataPersist = new DataPersist("SiemensServer"); }
/// <summary> /// /// </summary> /// <param name="port"></param> /// <param name="ip"></param> public AllenBradleyServer(int port, string ip = null) { this.ip = ip; this.port = port; dataPersist = new DataPersist("AllenBradley"); }
public ModBusTcpServer(int port, string ip = null) { this.ip = ip; this.port = port; dataPersist = new DataPersist("ModBusTcpServer"); }
public void SetupScene(int level, WordGen wordGen, Board board, Themes themes, GameManager gameManager) { // Properties _wordGen = wordGen; _level = level; _board = board; _gameManager = gameManager; _camera = Camera.main; _points = 0; _timer = 0f; _themes = themes; int challenge1StartTime = 0; int challenge1EndTime = (int)(_secondsLeft * .333); int challenge2StartTime = challenge1EndTime; int challenge2EndTime = (int)(_secondsLeft * .665); int challenge3StartTime = challenge2EndTime; int challenge3EndTime = (int)_secondsLeft; _challengeTimes.Add(UnityEngine.Random.Range(challenge1StartTime, challenge1EndTime)); _challengeTimes.Add(UnityEngine.Random.Range(challenge2StartTime, challenge2EndTime)); _challengeTimes.Add(UnityEngine.Random.Range(challenge3StartTime, challenge3EndTime)); //Bug timer.... fix here patch _totalTimeFloat = 0f; _secondsLeft = _secondsLeftPreserve; //Display Points _canvas = GameObject.FindGameObjectWithTag("Canvas").GetComponent <Canvas>(); _dataPersistInstance = Instantiate(_dataPersistPrefab).GetComponent <DataPersist>(); GameObject scoreTimeInstance = Instantiate(_scoreAndTimePrefab) as GameObject; scoreTimeInstance.transform.SetParent(_canvas.transform, false); _pauseButton = Instantiate(_pauseButtonPrefab) as Button; _pauseButton.transform.SetParent(_canvas.transform, false); _pauseButton.onClick.AddListener(() => { PauseGame(); }); _backButton = Instantiate(_backButtonPrefab) as Button; _backButton.transform.SetParent(_canvas.transform, false); _backButton.onClick.AddListener(() => { _gameManager.RestartGame(); }); _shuffleInstance = Instantiate(_shufflePrefab) as GameObject; _shuffleInstance.transform.SetParent(_canvas.transform, false); _shuffleButton = _shuffleInstance.GetComponentInChildren <Button>(); _shuffleButton.onClick.AddListener(() => { ShuffleBoard(); }); _scrollView = _canvas.GetComponentInChildren <ScrollRect> (); _scrollBar = _canvas.GetComponentInChildren <Scrollbar> (); _content = _scrollView.content; _gameDetails_Panel = GameObject.FindGameObjectWithTag("PointsPanel"); _gameDetails_RectTransform = _gameDetails_Panel.GetComponent <RectTransform> (); GameObject timePanel = Instantiate(_timePanelPrefab); timePanel.transform.SetParent(_canvas.transform, false); _time_Panel = GameObject.FindGameObjectWithTag("TimePanel"); _time_RectTransform = _time_Panel.GetComponent <RectTransform> (); // Points display _pointsText = Instantiate(_textPrefab, new Vector3(0f, -6f, 0f), Quaternion.identity) as Text; _pointsText.text = "Points: " + _points.ToString(); _pointsText.transform.SetParent(_gameDetails_RectTransform.transform, false); // Timer display _timeText = Instantiate(_secondsLeftTextPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity) as Text; _secondsLeftInt = (int)_secondsLeft; _timeText.text = _secondsLeftInt.ToString(); _timeText.transform.SetParent(_time_Panel.transform, false); //Theme related UI changes switch (_themes.Theme) { case Themes.Setting.Wood: _content.GetComponent <Image>().color = new Color(1f, 0.973f, 0.522f, .5f); _gameDetails_Panel.GetComponent <Image>().color = new Color(1f, 0.973f, 0.522f, .5f); break; case Themes.Setting.Beach: _content.GetComponent <Image>().color = new Color(0.65f, 0.72f, 0.8f, .5f); _gameDetails_Panel.GetComponent <Image>().color = new Color(0.65f, 0.72f, 0.8f, .5f); break; case Themes.Setting.Grass: _content.GetComponent <Image>().color = new Color(0.4f, 0.82f, 0.8f, 0.5f); _gameDetails_Panel.GetComponent <Image>().color = new Color(0.4f, 0.82f, 0.8f, 0.5f); break; default: break; } _removeSound = Instantiate(_wordRemoved_SoundPrefab) as AudioSource; _multiplierRemoveSound = Instantiate(_multiplierRemoved_SoundPrefab) as AudioSource; // Get Started with board definition and setup _activePieces = new List <GamePiece> (); _boardHolder = new GameObject("Board").transform; InitializeList(); BoardSetup(_gridPositions, false); initialized = true; }