private void BTNimportplayersforday_Click(object sender, EventArgs e) { Day recentDayInHistory = history.LastOrDefault(); if (recentDayInHistory != null && !string.IsNullOrEmpty(recentDayInHistory.date)) { OFDplayersinday.FileName = Tools.GuessFilename(recentDayInHistory) + ".txt"; } if (OFDplayersinday.ShowDialog() == DialogResult.Cancel) { return; } ReadWriteTable.ImportPlayerForDay(OFDplayersinday.FileName, players, playersSelectedForDay, out List <string> namesNotImported); if (namesNotImported.Count == 1) { MessageBox.Show($"I could not find anyone with the name {namesNotImported[0]}", "Incomplete import"); } else if (namesNotImported.Count > 1) { string msg = "I could not find anyone with these names:"; foreach (string name in namesNotImported) { msg += "\n" + name; } MessageBox.Show(msg, "Incomplete import"); } RefreshPageMatchesPlayers(); }
protected abstract bool writeTable(ReadWriteTable value, int timeoutval);
void _processAllData() { while (_need_to_stop == false) { int interdelay = 1; Thread.Sleep(20); clearInput(); AllCyclesNumber++; if (readTable(_gen_data, 100)) { if (_gen_data.DataWasUpdated()) { UInt16[] t = _gen_data.ReadDeviceData(); _RO_data = new ReadOnlyTable(MiniModbusCommand.READ_RO_COMMAND, t[3]); _RW_data = new ReadWriteTable(MiniModbusCommand.READ_RW_COMMAND, MiniModbusCommand.WRITE_RW_COMMAND, t[4]); _RW_flash = new ReadWriteTable(MiniModbusCommand.READ_FLASH_BUFFER_COMMAND, MiniModbusCommand.WRITE_FLASH_BUFFER_COMMAND, t[5]); _RW_flash.WriteFlag = false; if (deviceWasChanged != null) { deviceWasChanged(this, null); ResetCounters(); } } } else { continue; } Thread.Sleep(interdelay); if (readTable(_RO_data, 100) == false) { continue; } Thread.Sleep(interdelay); if (readTable(_RW_data, 100) == false) { continue; } Thread.Sleep(interdelay); if (readTable(_RW_flash, 100) == false) { continue; } Thread.Sleep(interdelay); if (readingIsComplete != null) { readingIsComplete(this, null); } Thread.Sleep(interdelay); if (writeTable(_RW_data, 100) == false) { continue; } Thread.Sleep(interdelay); if (writeTable(_RW_flash, 100) == false) { continue; } if (_request_to_write_ROM) { _request_to_write_ROM = false; if (writeRom(100) == false) { continue; } } GoodCyclesNumber++; if (cycleIsComplete != null) { cycleIsComplete(this, null); } } }
protected override bool writeTable(ReadWriteTable table, int timeoutval) { Debug.Assert(table.Size != 0); if (table.WriteFlag) { UInt16[] transmit_data = table._readControl(); int waswritten = 0; while (waswritten != table.Size) { int size = table.Size - waswritten; if (size > max_write_size) { size = max_write_size; } Debug.Assert(size < 0x80); Debug.Assert(waswritten < 0x200); byte[] tosend = new byte[4 + size * 2]; tosend[0] = _id; tosend[1] = (byte)table.WriteCmd; tosend[2] = (byte)waswritten; tosend[3] = (byte)size; if (waswritten >= 0x100) { tosend[3] |= 0x80; } for (int i = 0; i < size; i++) { tosend[4 + 2 * i] = Convert.ToByte(transmit_data[waswritten + i] & 0xff); tosend[4 + 2 * i + 1] = Convert.ToByte((transmit_data[waswritten + i] >> 8) & 0xff); } if (!_serial.Send(tosend)) { return(false); } byte[] toreceive = null; do { Thread.Sleep(1); toreceive = _serial.Receive(); }while ((toreceive == null) && (timeoutval-- != 0)); if (toreceive == null) { return(false); } if (toreceive.Length != 4) { return(false); } if (toreceive[0] != _id) { return(false); } if (toreceive[1] != (byte)MiniModbusCommand.SHORT_RESPONCE_COMMAND) { return(false); } if (toreceive[2] != (byte)table.WriteCmd) { return(false); } if (toreceive[3] != 0) { return(false); } waswritten += size; } } return(true); }