private void button3_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex > -1) { var selected_prn = listBox1.SelectedItem.ToString(); var selected_bin = Path.ChangeExtension(selected_prn, "bin"); listBox2.Items.Add("printing " + selected_bin); var text_to_print = File.ReadAllText(trabajo_folder + "\\" + selected_bin); RawPrinterHelper.SendStringToPrinter(printerName.Text, text_to_print); print_count++; label7.Text = print_count.ToString(); } }
private void timer1_Tick(object sender, EventArgs e) { //Connect to Server if (modbusClient.Connected && modbusClient.Available(1)) { try { int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10); //Read 10 Holding Registers from Server, starting with Address 1 var new_text = String.Join(" - ", readHoldingRegisters); if (old_registers != new_text) { old_registers = new_text; var to_print = readHoldingRegisters[0]; if (to_print == 1) { var number = readHoldingRegisters[1].ToString(); listBox1.SelectedIndex = -1; for (int i = 0; i < listBox1.Items.Count; i++) { if (listBox1.Items[i].ToString().StartsWith(number)) { listBox1.SelectedIndex = i; var selected_prn = listBox1.Items[i].ToString(); var selected_bin = Path.ChangeExtension(selected_prn, "bin"); listBox2.Items.Add("printing " + selected_bin); var text_to_print = File.ReadAllText(trabajo_folder + "\\" + selected_bin); RawPrinterHelper.SendStringToPrinter(printerName.Text, text_to_print); print_count++; label7.Text = print_count.ToString(); } } } listBox2.Items.Add(new_text); } } catch (Exception ex) { plcStatus.Text = ex.Message; modbusClient.Disconnect(); } } else { modbusClient.Disconnect(); connect_to_plc(); } }