public static async Task SendAdminMenu() { if (!await AsyncCamCom.TryConnect().ConfigureAwait(false)) { return; } AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFB, 0x03 }); AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFD, 0x05 }); AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFC, 0x04 }); AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFE, 0x06 }); }
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()); } }
public async Task ConnectToCamera() { if (!MainForm.m.finishedLoading) { return; } ConfigControl.savedIP.UpdateValue(tB_IPCon_Adr.Text); int parsed; if (int.TryParse(cB_IPCon_Port.Text, out parsed)) { ConfigControl.savedPort.UpdateValue(parsed.ToString()); } AsyncCamCom.TryConnect(false).ConfigureAwait(false); }
async Task Fire(FireType type) { try { if (type == FireType.IP) { if (!await AsyncCamCom.TryConnect(false).ConfigureAwait(false)) { if (Tools.ShowPopup("Failed to connect to camera!\nIP: " + ConfigControl.savedIP.stringVal + "\nPort: " + ConfigControl.savedPort.stringVal + "\nCancel script execution?", "Failed to Connect!", null, false)) { b_PD_Fire.Enabled = true; return; } } } Invoke((MethodInvoker) delegate { b_PD_Fire.Enabled = false; b_PD_Stop.Enabled = true; }); loopAmount = 0; loopPos = -1; for (int i = 0; i < tB_Commands.Lines.Length; i++) { string l = tB_Commands.Lines[i]; if (!stop) { await CheckLine(l, i, type); } else { stop = false; break; } if (loopNow && loopPos != -1) { MainForm.m.WriteToResponses("Looped " + currentLoops.ToString() + "/" + loopAmount.ToString(), true, false); if (currentLoops < loopAmount) { i = loopPos; } else { loopPos = -1; currentLoops = 0; } loopNow = false; } await Task.Delay(100).ConfigureAwait(false); } } catch (Exception e) { Tools.ShowPopup("Failed to send commands!\nShow more?", "Command firing failed", e.ToString()); } Invoke((MethodInvoker) delegate { MessageBox.Show("Finished sending commands!"); stop = false; b_PD_Stop.Enabled = false; b_PD_Fire.Enabled = true; }); }
static async Task DoCustomCommand(ScriptCommand com, string line) { try { if (com.codeContent == PelcoD.pause) { int value = CheckForVal(line); MainForm.m.WriteToResponses("Waiting: " + value.ToString() + "ms", true); while (value > 0) { if (stopScript) { break; } value -= 200; await Task.Delay(200).ConfigureAwait(false); } stopScript = false; } else if (com.codeContent == PelcoD.connect) { int ipmarker = line.IndexOf(" "); int portmarker = line.IndexOf(":"); if (ipmarker == -1 || portmarker == -1) { MainForm.m.WriteToResponses("Failed to parse IP or port! (" + line + ")", false); return; } IPAddress parsed; int port; if (IPAddress.TryParse(line.Substring(ipmarker + 1, portmarker - ipmarker - 1), out parsed) && int.TryParse(line.Substring(portmarker + 1), out port)) { await AsyncCamCom.TryConnect(false, new IPEndPoint(parsed, port)); } } else if (com.codeContent == PelcoD.reconfig) { InfoPanel.i.CheckForCamera(); } else if (com.codeContent == PelcoD.mainplay) { int marker = line.IndexOf(" "); //maybe move this up if more customs need it if (marker <= 0) { marker = line.IndexOf(":"); } MainForm.m.mainPlayer.Play(false, false); } else if (com.codeContent == PelcoD.swapPreset) { //ComboBox cb = MainForm.m.setPage.cB_ipCon_CamType; //string oldVal = cb.Text; //int marker = line.IndexOf(" "); //if (marker <= 0) // marker = line.IndexOf(":"); //string val = line.Substring(marker + 1).Trim().ToLower(); //int foundInt; //if (int.TryParse(val, out foundInt) && cb.Items[foundInt - 1] != null) //index of preset // cb.SelectedIndex = foundInt - 1; //else { // foreach (DataGridViewRow row in MainForm.m.up.dgv_Presets.Rows) { // if (row.Cells[0].Value != null) { // if (row.Cells[0].Value.ToString().ToLower().Trim().Contains(val)) { //set it to the preset found // cb.Text = row.Cells[0].Value.ToString(); // break; // } // } // } //} //if (cb.Text != oldVal) // MainForm.m.setPage.UpdateID(cb); //else // MainForm.m.WriteToResponses("Failed to find user preset: " + val, false); } }catch (Exception e) { MainForm.m.WriteToResponses("Failed to execute custom command: " + line + Tools.ShowScriptCommandInfo(com, false) + "\n" + e.ToString(), false); } }