protected void SendProgram() { currentTask = 0; var startMode = (RunMode)Enum.Parse(typeof(RunMode), cbStartMode.SelectedItem + ""); var endMode = (RunMode)Enum.Parse(typeof(RunMode), cbEndMode.SelectedItem + ""); currentSettings = new EBoxSettings(startMode, endMode); SendCommand(UartCommand.set, 0, currentSettings.GetBytes()); }
void port_OnReceive(byte[] data) { var command = (UartCommand)data[0]; if (command == UartCommand.get) { OnDeviceStateChange(EDeviceState.Online); ushort addr = (ushort)(data[1] << 8); addr += data[2]; if (addr == 0) { currentSettings = new EBoxSettings(data, 3); Invoke(showSettingsMethod); } else { if (data[3] + data[4] + data[5] + data[6] == 0) { readedTask = null; ShowProgram(); return; } var cTask = new Task(data, 3); cTask.Address = addr; readedTask = cTask; Invoke(showTaskMethod); } addr++; SendCommand(UartCommand.get, addr); } if (command == UartCommand.set) { ushort addr = (ushort)(data[1] << 8); addr += data[2]; if (TaskList != null && currentTask < TaskList.Count) { addr++; Invoke(writeProgressMethod); SendCommand(UartCommand.set, addr, TaskList[currentTask]); currentTask++; } else { if (currentTask == TaskList.Count) { addr++; SendCommand(UartCommand.set, addr, new byte[4]); currentTask++; } else { Invoke(writeCompleteMethod); } } } }