/// <summary> /// Sets the job media mode for the device. /// </summary> /// <param name="mode">The <see cref="JobMediaMode" /> to set.</param> /// <returns><c>true</c> if the job media mode was set successfully, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentException"><paramref name="mode" /> is set to <see cref="JobMediaMode.Unknown" />.</exception> public bool SetJobMediaMode(JobMediaMode mode) { if (mode == JobMediaMode.Unknown) { throw new ArgumentException($"Cannot set Job Media Mode to {mode}.", nameof(mode)); } //previously we were using telnet to send the UDW command, turns out the port was not fixed for a printer product and can //vary for each one. //the same can also be achieved by a REST command and works easily over port 80, the code has been modified to achieve the same //Veda - 16/04/2018 string crcCommand = (mode == JobMediaMode.Paperless) ? "smgr_pe.multi_button_push+58" : "smgr_pe.multi_button_push+59"; try { WebClient client = new WebClient(); client.QueryString.Add("entry", crcCommand); client.DownloadString($"http://{_device.Address}:80/UDW/Command"); return(true); } catch (Exception e) { LogWarn($"Printer is not on supported firmware, skipping paperless mode. {e.Message}"); return(false); } }
/// <summary> /// Sets Paperless Print Mode to ON or OFF on the device /// </summary> /// <param name="paperlessModeOn"></param> /// <returns></returns> private bool SetPaperlessPrintMode(string ipAddress, string adminPassword) { JobMediaMode mode = PaperlessModeOn ? JobMediaMode.Paperless : JobMediaMode.Paper; bool success = false; try { using (var device = DeviceFactory.Create(ipAddress, adminPassword)) { try { IDeviceSettingsManager manager = DeviceSettingsManagerFactory.Create(device); success = manager.SetJobMediaMode(mode); } catch (DeviceFactoryCoreException) { return(false); } } } catch (Exception ex) { return(false); } return(success); }
public bool SetJobMediaMode(JobMediaMode mode) { bool success = false; if (mode == JobMediaMode.Unknown) { throw new ArgumentException($"Cannot set Job Media Mode to '{mode}'.", nameof(mode)); } //Get current mode but set to allow PJL string currentPJLMode = AllowPJLAnyway(); JobMediaMode currentState = GetJobMediaMode(); if (currentState == mode) { LogDebug($"Job media mode already set to '{mode}' - no change required."); success = true; } else { LogDebug($"Job media mode set to '{currentState}', setting to '{mode}'."); int tries = 0; while (currentState != mode && tries++ < 3) { try { using (PjlMessenger pjl = new PjlMessenger(_address, _port)) { pjl.Connect(); pjl.SendCommand(_commands[mode]); } } catch (Exception ex) { LogWarn("Unable to set job media mode.", ex); } currentState = GetJobMediaMode(); if (currentState != mode) { LogDebug($"Job media mode failed to set. Attempt {tries}. Retrying..."); } } if (GetJobMediaMode() == mode) { LogDebug($"Job media mode '{mode}' set successfully."); success = true; } else { LogWarn($"Failed to set job media mode '{mode}'."); success = false; } } RestorePJL(currentPJLMode); return(success); }
private void m_listBoxLayerSettings_SelectedIndexChanged(object sender, EventArgs e) { m_PropertyGridStep.SelectedObject = null; JobMediaMode mode = (JobMediaMode)m_listBoxLayerSettings.SelectedItem; if (mode != null) { m_PropertyGridStep.SelectedObject = mode.Item; } }
public static void SetPaperlessMode(IPAddress ipaddress, bool paperlessModeOn) { JobMediaMode mode = paperlessModeOn ? JobMediaMode.Paperless : JobMediaMode.Paper; using (IDevice device = DeviceFactory.Create(ipaddress, "!QAZ2wsx")) { IDeviceSettingsManager manager = DeviceSettingsManagerFactory.Create(device); manager.SetJobMediaMode(mode); } Console.WriteLine(string.Format("Paperless mode was turned {0}.", paperlessModeOn ? "on" : "off")); }
private void Bind() { m_listBoxLayerSettings.DataSource = null; m_listBoxLayerSettings.DataSource = m_LayerSettings.Items; m_listBoxLayerSettings.DisplayMember = "Name"; m_listBoxLayerSettings.ValueMember = "Name"; JobMediaMode mode = (JobMediaMode)m_listBoxLayerSettings.SelectedItem; if (mode != null) { m_PropertyGridStep.SelectedObject = mode.Item; } }
public static bool SetPaperlessPrintMode(bool PaperlessModeOn, IDevice device) { JobMediaMode mode = PaperlessModeOn ? JobMediaMode.Paperless : JobMediaMode.Paper; bool success = false; try { IDeviceSettingsManager manager = DeviceSettingsManagerFactory.Create(device); success = manager.SetJobMediaMode(mode); } catch (DeviceFactoryCoreException) { return(false); } return(success); }
public static void SetPaperlessMode(string address, string adminPassword, bool paperlessModeOn) { JobMediaMode mode = paperlessModeOn ? JobMediaMode.Paperless : JobMediaMode.Paper; IPAddress ipaddress; if (IPAddress.TryParse(address, out ipaddress)) { using (IDevice device = DeviceFactory.Create(ipaddress, adminPassword)) { IDeviceSettingsManager manager = DeviceSettingsManagerFactory.Create(device); manager.SetJobMediaMode(mode); } MessageBox.Show(string.Format("Paperless mode was turned {0}.", paperlessModeOn ? "on" : "off")); } else { MessageBox.Show("IP address was invalid."); } }
private void DownMode_Click(object sender, EventArgs e) { if (m_listBoxLayerSettings.SelectedItems.Count > 0) { int curIdx = m_listBoxLayerSettings.SelectedIndex; if (curIdx < m_listBoxLayerSettings.Items.Count - 1) { JobMediaMode Mode = (JobMediaMode)m_listBoxLayerSettings.SelectedItem; m_LayerSettings.Items.Remove(Mode); curIdx++; m_LayerSettings.Items.Insert(curIdx, Mode); Bind(); m_listBoxLayerSettings.SelectedIndex = curIdx; } } }
private void CopyAs_Click(object sender, EventArgs e) { if (m_listBoxLayerSettings.SelectedIndex < 0) { return; } try { JobMediaMode Mode = (JobMediaMode)m_listBoxLayerSettings.SelectedItem; if (Mode != null) { List <string> ExistModes = new List <string>(); foreach (JobMediaMode item in m_LayerSettings.Items) { ExistModes.Add(item.Name); } NameEdit Form = new NameEdit(ExistModes); Form.Text = ResString.GetResString("Add_Mode"); if (DialogResult.OK == Form.ShowDialog()) { JobMediaMode newMode = new JobMediaMode(); newMode.Name = Form.Input; newMode.Item = Mode.Item.Clone(); newMode.LayerNum = Mode.LayerNum; newMode.LayerColorArray = Mode.LayerColorArray; newMode.SpotColor1Mask = Mode.SpotColor1Mask; m_LayerSettings.Items.Add(newMode); Bind(); m_listBoxLayerSettings.SelectedIndex = m_listBoxLayerSettings.Items.Count - 1; } } } catch (Exception ex) { MessageBox.Show("Failed to save the config:" + ex.Message); } }
public bool SetJobMediaMode(JobMediaMode mode) { if (mode == JobMediaMode.Unknown) { throw new ArgumentException($"Cannot set Job Media Mode to {mode}.", nameof(mode)); } try { using (PjlMessenger pjl = new PjlMessenger(_address, _port)) { pjl.Connect(); pjl.SendCommand(_commands[mode]); } return(true); } catch (Exception ex) { LogWarn("Unable to set job media mode.", ex); return(false); } }
private void AddMode_Click(object sender, EventArgs e) { List <string> ExistModes = new List <string>(); foreach (JobMediaMode Mode in m_LayerSettings.Items) { ExistModes.Add(Mode.Name); } NameEdit Form = new NameEdit(ExistModes); Form.Text = ResString.GetResString("Add_Mode"); if (DialogResult.OK == Form.ShowDialog()) { JobMediaMode Mode = new JobMediaMode(); Mode.Name = Form.Input; m_LayerSettings.Items.Add(Mode); Bind(); m_listBoxLayerSettings.SelectedIndex = m_listBoxLayerSettings.Items.Count - 1; } }
public void ExecuteReboot() { JobMediaMode jobMediaModeNeeded = JobMediaMode.Paper; RebootDeviceActivityData activityData = _activityData; IDevice device = DeviceConstructor.Create(_deviceInfo); IDeviceSettingsManager settingsManager = DeviceSettingsManagerFactory.Create(device); if (activityData.JobMediaMode == JobMediaModeDesired.Preserve) { OnUpdateStatus("Getting job media mode because it will return to default after a reboot..."); jobMediaModeNeeded = settingsManager.GetJobMediaMode(); OnUpdateStatus($"Current job media mode is {jobMediaModeNeeded}."); } else { jobMediaModeNeeded = EnumUtil.Parse <JobMediaMode>(activityData.JobMediaMode.ToString()); } DateTime startTime = DateTime.Now; if (activityData.ShouldWaitForReady) { OnUpdateStatus("Reboot Begin"); } Reboot(activityData.ShouldWaitForReady); if (activityData.ShouldWaitForReady) { OnUpdateStatus("Reboot Complete"); ExecutionServices.SystemTrace.LogDebug($"Device rebooted"); if (jobMediaModeNeeded == JobMediaMode.Paperless) { OnUpdateStatus($"Setting job media mode to {jobMediaModeNeeded}."); settingsManager.SetJobMediaMode(JobMediaMode.Paperless); } } }
/// <summary> /// Sets the job media mode for the device. /// </summary> /// <param name="mode">The <see cref="JobMediaMode" /> to set.</param> /// <returns><c>true</c> if the job media mode was set successfully, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentException"><paramref name="mode" /> is set to <see cref="JobMediaMode.Unknown" />.</exception> public bool SetJobMediaMode(JobMediaMode mode) { if (mode == JobMediaMode.Unknown) { throw new ArgumentException($"Cannot set Job Media Mode to {mode}.", nameof(mode)); } // We need to have debug telnet enabled on this device, to do that, we will send a payload to the printer opening it up if (EnableTelnetDebug()) { // Now that debug telnet is open, we open telnet session and send the command const string crcCommandDirectory = "cd print/debug"; string crcCommand = (mode == JobMediaMode.Paperless) ? "VideoCRCMode true" : "VideoCRCMode false"; using (Telnet telnet = new Telnet(_device.Address, 23000)) { try { telnet.ReceiveUntilMatch(">"); telnet.SendLine(crcCommandDirectory); telnet.ReceiveUntilMatch(">"); telnet.SendLine(crcCommand); telnet.ReceiveUntilMatch(">"); return(true); } catch (SocketException ex) { LogWarn($"Printer does not have telnet enabled, skipping paperless mode. {ex.Message}"); return(false); } } } return(false); }
private void RemoveMode_Click(object sender, EventArgs e) { if (m_listBoxLayerSettings.SelectedIndex < 0) { return; } try { JobMediaMode Mode = (JobMediaMode)m_listBoxLayerSettings.SelectedItem; if (Mode != null) { if (DialogResult.Cancel == MessageBox.Show(string.Format(ResString.GetResString("Confirm_DeleteMode"), Mode.Name), "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)) { return; } foreach (JobMediaMode item in m_LayerSettings.Items) { if (item.Name == Mode.Name) { m_LayerSettings.Items.Remove(item); break; } } Bind(); m_listBoxLayerSettings.SelectedIndex = m_listBoxLayerSettings.Items.Count - 1; } } catch (Exception ex) { MessageBox.Show("Failed to save the config:" + ex.Message); } }