Exemplo n.º 1
0
 private void closePort_Click(object sender, EventArgs e)
 {
     _serialPort.StopTransfer();
     _serialPort.StopWaveTransfer();
     _serialPort.Close();
     MessageBox.Show("关闭成功");
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("VitalSignsCaptureDraegerVent v1.003 (C)2017-20 John George K.");
            // Create a new SerialPort object with default settings.
            DSerialPort _serialPort = DSerialPort.getInstance;

            Console.WriteLine("Select the Port to which Draeger Ventilator (Medibus.X protocol) is to be connected, Available Ports:");
            foreach (string s in SerialPort.GetPortNames())
            {
                Console.WriteLine(" {0}", s);
            }


            Console.Write("COM port({0}): ", _serialPort.PortName.ToString());
            string portName = Console.ReadLine();

            if (portName != "")
            {
                // Allow the user to set the appropriate properties.
                _serialPort.PortName = portName;
            }

            Console.WriteLine();
            Console.WriteLine("Numeric Data Transmission sets:");
            Console.WriteLine("1. 5 second");
            Console.WriteLine("2. 10 second");
            Console.WriteLine("3. 1 minute");
            Console.WriteLine("4. 5 minute");
            Console.WriteLine("5. Single poll");
            Console.WriteLine();
            Console.Write("Choose Data Transmission interval (1-5):");

            string sIntervalset = Console.ReadLine();

            int[] setarray     = { 5, 10, 60, 300, 0 };
            short nIntervalset = 2;
            int   nInterval    = 10;

            if (sIntervalset != "")
            {
                nIntervalset = Convert.ToInt16(sIntervalset);
            }
            if (nIntervalset > 0 && nIntervalset < 6)
            {
                nInterval = setarray[nIntervalset - 1];
            }

            Console.WriteLine();
            Console.WriteLine("Waveform data export options:");
            Console.WriteLine("0. None");
            Console.WriteLine("1. Airway Pressure, Flow, Resp Volume");
            Console.WriteLine("2. Pleth, O2 conc.(%), CO2 conc.(mmHg), Primary agent conc.(%)");
            Console.WriteLine("3. Tracheal pressure, Inspiratory Flow");
            Console.WriteLine("4. All");
            Console.WriteLine();
            Console.Write("Choose Waveform data export priority option (0-4):");

            string sWaveformSet = Console.ReadLine();
            short  nWaveformSet = 0;

            if (sWaveformSet != "")
            {
                nWaveformSet = Convert.ToInt16(sWaveformSet);
            }


            try
            {
                _serialPort.Open();
                _serialPort.m_nWaveformSet = nWaveformSet;

                if (_serialPort.OSIsUnix())
                {
                    dataEvent += new EventHandler((object sender, EventArgs e) => ReadData(sender));
                }

                if (!_serialPort.OSIsUnix())
                {
                    _serialPort.DataReceived += new SerialDataReceivedEventHandler(p_DataReceived);
                }

                Console.WriteLine("You may now connect the serial cable to the Draeger Ventilator");
                Console.WriteLine("Press any key to continue..");

                Console.ReadKey(true);


                Console.WriteLine();
                //Console.WriteLine("Requesting Transmission from monitor");
                Console.WriteLine("Requesting Transmission set {0} from monitor", nIntervalset);


                Console.WriteLine();
                Console.WriteLine("Data will be written to CSV file DrgVentExportData.csv in same folder");

                _serialPort.RequestICC();
                WaitForMilliSeconds(200);

                Task.Run(() => _serialPort.SendCycledRequests(nInterval));

                //RequestRealtimeData after DevID response

                Task.Run(() => _serialPort.KeepConnectionAlive(2));

                Console.WriteLine("Press Escape button to Stop");

                if (_serialPort.OSIsUnix())
                {
                    do
                    {
                        if (_serialPort.BytesToRead != 0)
                        {
                            dataEvent.Invoke(_serialPort, new EventArgs());
                        }

                        if (Console.KeyAvailable == true)
                        {
                            if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                            {
                                break;
                            }
                        }
                    }while (Console.KeyAvailable == false);
                }

                if (!_serialPort.OSIsUnix())
                {
                    ConsoleKeyInfo cki;

                    do
                    {
                        cki = Console.ReadKey(true);
                    }while (cki.Key != ConsoleKey.Escape);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error opening/writing to serial port :: " + ex.Message, "Error!");
            }
            finally
            {
                _serialPort.StopTransfer();

                _serialPort.Close();
            }
        }