示例#1
0
    public static void ConnectPort(string port_name, ref CFSControl cfs_control)
    {
        UpdateSerialPortComboBox();
        if (String.IsNullOrEmpty(port_name))
        {
            return;
        }
        cfs_control.port = new SerialPort(port_name, BAUDRATE, Parity.None, 8, StopBits.One);
        try
        {
            cfs_control.port.Open();
            cfs_control.port.DtrEnable = true;
            cfs_control.port.RtsEnable = true;
            ConnectButton.Content      = "Disconnect";
            Console.WriteLine("Connected.");
            cfs_control.port.DiscardInBuffer();
            //serial_control.SetReceiveInterrupt();

            cfs_control.Init();
            Connected_list.Add(port_name);
        }
        catch (Exception err)
        {
            Console.WriteLine("Unexpected exception : {0}", err.ToString());
        }
    }
示例#2
0
 public static void DisconnectPort(string port_name, ref CFSControl cfs_control)
 {
     if (IsConnected(port_name))
     {
         cfs_control.RequestDisconnection();
         //cfs_control.Disconnect();
         ConnectButton.Content = "Connect";
         Console.WriteLine("Disconnected.");
         Connected_list.Remove(port_name);
     }
 }