private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (m_bStart) { timer1.Enabled = false; // disable timer adamCom.CloseComPort(); // close the COM port } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (m_bStart) { timer1.Enabled = false; // disable timer adamCom.CloseComPort(); // close the COM port } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (m_bStart) { timer1.Enabled = false; // disable timer if (m_b5000) { adamCom.CloseComPort(); // close the COM port } else { adamSocket.Disconnect(); } } }
public VoltageController(VM_MSConfig msConfig) { Config = msConfig; m_iCom = 3; // using COM4 m_iAddr = 1; // the slave address is 1 m_iCount = 0; // the counting start from 0 m_bStart = false; m_Adam4000Type = Adam4000Type.Adam4019P; // the sample is for ADAM-4019P m_iChTotal = AnalogInput.GetChannelTotal(m_Adam4000Type); m_byRange = new byte[m_iChTotal]; adamCom = new AdamCom(m_iCom); adamCom.Checksum = false; // disbale checksum Module = m_Adam4000Type.ToString(); if (adamCom.OpenComPort()) { // set COM port state, 9600,N,8,1 adamCom.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One); // set COM port timeout adamCom.SetComPortTimeout(500, 500, 0, 500, 0); m_iCount = 0; // reset the reading counter // get module config if (!adamCom.Configuration(m_iAddr).GetModuleConfig(out m_adamConfig)) { adamCom.CloseComPort(); LogHelper.WriteErrorLog("Failed to get module config!"); return; } // RefreshChannelEnable(); RefreshChannelRange(); // m_bStart = true; // starting flag } else { LogHelper.WriteErrorLog("Failed to open COM port!"); } }
private void buttonStart_Click(object sender, EventArgs e) { Socket svrSocket; if (buttonStart.Text == "Start") { m_com = new AdamCom(2); m_com.Checksum = false; // set the checksum disbale, if the checksum must be applied, set it to true m_com.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One); // 9600, N, 8, 1 m_com.SetComPortTimeout(m_SerialTimeout, m_SerialTimeout, 0, m_SerialTimeout, 0); if (!m_com.OpenComPort()) { MessageBox.Show("Failed to open COM!", "Error"); return; } m_SvrSocket = new UDPSocketServer(); m_SvrSocket.Create(m_ListenPort); svrSocket = m_SvrSocket.ServerSocket(); m_SvrStream = new SocketStream(ref svrSocket, m_UDPSendTimeout, m_UDPRecvTimeout); buttonStart.Text = "Stop"; m_UDPRecv = 0; m_UDPSent = 0; m_SerialSent = 0; m_SerialRecv = 0; textBoxUDPRecv.Text = m_UDPRecv.ToString(); textBoxUDPSent.Text = m_UDPSent.ToString(); textBoxSerialSent.Text = m_SerialSent.ToString(); textBoxSerialRecv.Text = m_SerialRecv.ToString(); timer1.Enabled = true; } else { timer1.Enabled = false; m_SvrSocket.Terminate(); m_com.CloseComPort(); buttonStart.Text = "Start"; } }
public void Open() { adamCom = new AdamCom(SerialPortNumber); adamCom.Checksum = Checksum; bool opened = false; try { if (!adamCom.IsOpen) { opened = adamCom.OpenComPort(); } if (!opened) { return; } // set COM port state, 9600,N,8,1 adamCom.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One, FlowControl.None); // set COM port timeout adamCom.SetComPortTimeout(500, 1000, 0, 1000, 0); if (!adamCom.Configuration(address).GetModuleConfig(out config)) { opened = false; adamCom.CloseComPort(); return; } } finally { Opened = opened; } }
public void Close() => Opened = adamCom.IsOpen ? !adamCom.CloseComPort() : false;