private void button5_Click(object sender, EventArgs e) { DateTime lockal = DateTime.Now; setDate.Text = lockal.Day.ToString("D2") + ":" + lockal.Month.ToString("D2") + ":" + lockal.Year.ToString("D2"); setTime.Text = lockal.Hour.ToString("D2") + ":" + lockal.Minute.ToString("D2") + ":" + lockal.Second.ToString("D2"); setDate_TextChanged(this, null); setTime_TextChanged(this, null); ushort[] tBuff = ValueUtil.StructToBuff <ushort, common.devices.DateTimeRegisters>(USM_Reg.DateTime); ushort[] Password = new ushort[1]; Password[0] = 257; ushort[] Pass = new ushort[1]; Pass[0] = 16; ushort[] PassNull = new ushort[1]; PassNull[0] = 0; try { if (!COM3.IsOpen) { COM3.Open(); } //Thread read = //WorkState m_state_prev = m_state; //m_state = WorkState.Idle; m_mbMaster.WriteMultipleRegisters(0x01, 0x00, Password); m_mbMaster.WriteMultipleRegisters(0x01, 241, Pass); Thread.Sleep(10); m_mbMaster.WriteMultipleRegisters(0x01, 10, tBuff); Thread.Sleep(10); m_mbMaster.WriteMultipleRegisters(0x01, 241, PassNull); //m_state = m_state_prev; //m_mbMaster.WriteMultipleRegisters(0x01, 0x00, Password); //m_mbMaster.WriteMultipleRegisters(0x01, 10, tBuff); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button4_Click(object sender, EventArgs e) { try { COM3.PortName = comboBox5.Text; COM3.BaudRate = 9600; COM3.DataBits = 8; COM3.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); COM3.Parity = (Parity)Enum.Parse(typeof(Parity), "None"); COM3.Open(); progressBar2.Value = 100; } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button3_Click(object sender, EventArgs e) { if (!COM3.IsOpen) { try { COM3.Open(); richTextBox1.Text = "открыт"; //Thread read = m_mbMaster = ModbusSerialMaster.CreateRtu(COM3); m_state = WorkState.Update; } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка !!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } ; }