async Task IPSend(ScriptCommand send, string curLine) { Command sendCommand = AsyncCamCom.SendScriptCommand(send); if (sendCommand == null || sendCommand.invalid) { MainForm.m.WriteToResponses("Command: " + curLine + " could not be sent because it's invalid!", true); } }
public static async Task QuickCommand(string command, bool sendAsync = true, int manualAdr = -5) { try { if (!await AsyncCamCom.TryConnect().ConfigureAwait(false)) { MessageBox.Show("Not connected to camera!\nTried sending: " + command); return; } uint adr = Tools.MakeAdr(); if (manualAdr != -5) //if sending preset { adr = Convert.ToUInt32(manualAdr); } ScriptCommand send = CheckForCommands(command, adr, false).Result; if (send.codeContent == PelcoD.noCommand) { if (command.Length == 0) { MessageBox.Show("Command length is 0!\nMake sure to check the command in the settings!"); return; } else { byte[] code = Tools.ConvertMsgToByte(command); if (code == null) { MessageBox.Show("Command invalid!\nMake sure to enter command in the correct format!\n(FF 0x xx xx xx xx yy OR [command] [value])"); return; } send = new ScriptCommand(new string[] { "custom" }, code, "", 0); } } if (!sendAsync) { AsyncCamCom.SendNonAsync(send.codeContent); } else { var t = Task.Factory.StartNew(() => { AsyncCamCom.SendScriptCommand(send); }); Task.WaitAll(); } } catch (Exception e) { Tools.ShowPopup("Failed to send quick command!\nShow more?", "Error Occurred!", e.ToString()); } }