コード例 #1
0
        public static void ConnectviaMIB()
        {
            // Create a new SerialPort object with default settings.
            MPSerialPort _serialPort = MPSerialPort.getInstance;

            Console.WriteLine("Select the Port to which Intellivue Monitor 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;
            }


            try
            {
                _serialPort.Open();

                //EventHandler dataEvent = new EventHandler((object sender, EventArgs e)=>ReadData(sender));


                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 Intellivue Monitor MIB port");
                Console.WriteLine("Press any key to continue..");

                Console.ReadKey(true);

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

                string sIntervalset = Console.ReadLine();
                int[]  setarray     = { 1, 12, 60, 300, 0 };
                short  nIntervalset = 2;
                int    nInterval    = 12;
                if (sIntervalset != "")
                {
                    nIntervalset = Convert.ToInt16(sIntervalset);
                }
                if (nIntervalset > 0 && nIntervalset < 6)
                {
                    nInterval = setarray[nIntervalset - 1];
                }

                Console.WriteLine();
                Console.WriteLine("CSV Data Export Options:");
                Console.WriteLine("1. Single value list");
                Console.WriteLine("2. Data packet list");
                Console.WriteLine("3. Consolidated data list");
                Console.WriteLine();
                Console.Write("Choose CSV export option (1-3):");

                string sCSVset = Console.ReadLine();
                int    nCSVset = 3;
                if (sCSVset != "")
                {
                    nCSVset = Convert.ToInt32(sCSVset);
                }

                Console.WriteLine();
                Console.WriteLine("Waveform data export priority options:");
                Console.WriteLine("0. None");
                //Selecting all waves can lead to data loss due to bandwidth issues
                //Console.WriteLine("1. All");
                Console.WriteLine("1. ECG I, II, III");
                Console.WriteLine("2. ECG II, ECG V5, RESP, PLETH, ART IBP, CVP, CO2, AWP, AWF");
                Console.WriteLine("3. ECG AVR, ECG AVL, ECG AVF");
                Console.WriteLine("4. ECG V1, ECG V2, ECG V3");
                Console.WriteLine("5. ECG V4, ECG V5, ECG V6");
                Console.WriteLine("6. EEG1, EEG2, EEG3, EEG4");
                Console.WriteLine("7. Compound ECG");
                Console.WriteLine("8. Compound ECG, PLETH, ART, CVP, CO2");
                Console.WriteLine("9. All");

                Console.WriteLine();
                Console.WriteLine("Selecting all waves can lead to data loss due to bandwidth issues");
                Console.Write("Choose Waveform data export priority option (0-9):");


                string sWaveformSet = Console.ReadLine();
                short  nWaveformSet = 0;
                if (sWaveformSet != "")
                {
                    nWaveformSet = Convert.ToInt16(sWaveformSet);
                }

                Console.WriteLine("Requesting Transmission set {0} from monitor", nIntervalset);
                Console.WriteLine();
                Console.WriteLine("Data will be written to CSV file MPDataExport.csv in same folder");
                Console.WriteLine();


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

                if (nCSVset > 0 && nCSVset < 4)
                {
                    _serialPort.m_csvexportset = nCSVset;
                }

                _serialPort.SendWaveAssociationRequest();

                //Send Extended PollData Requests cycled every second
                Task.Run(() => _serialPort.SendCycledExtendedPollDataRequest(nInterval));

                WaitForMilliSeconds(500);

                if (nWaveformSet != 0)
                {
                    _serialPort.GetRTSAPriorityListRequest();
                    //_serialPort.SetRTSAPriorityListRequest();
                    if (nWaveformSet != 9)
                    {
                        _serialPort.SetRTSAPriorityList(nWaveformSet);
                    }

                    Task.Run(() => _serialPort.SendCycledExtendedPollWaveDataRequest(nInterval));
                }

                //Keep Connection Alive
                Task.Run(() => _serialPort.KeepConnectionAlive(nInterval));

                //Receive PollDataResponse message

                if (_serialPort.OSIsUnix())
                {
                    do
                    {
                        if (_serialPort.BytesToRead != 0)
                        {
                            //dataEvent.Invoke(new object(), new EventArgs());
                            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();
            }
        }
コード例 #2
0
        public static void ConnectviaMIB(string[] args)
        {
            // Create a new SerialPort object with default settings.
            MPSerialPort _serialPort = MPSerialPort.getInstance;

            var parser = new CommandLineParser();

            parser.Parse(args);

            string portName;

            if (parser.Arguments.ContainsKey("port"))
            {
                portName = parser.Arguments["port"][0];
            }
            else
            {
                Console.WriteLine("Select the Port to which Intellivue Monitor is to be connected, Available Ports:");
                foreach (string s in SerialPort.GetPortNames())
                {
                    Console.WriteLine(" {0}", s);
                }


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


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


            try
            {
                _serialPort.Open();

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

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

                if (!parser.Arguments.ContainsKey("port"))
                {
                    Console.WriteLine("You may now connect the serial cable to the Intellivue Monitor MIB port");
                    Console.WriteLine("Press any key to continue..");

                    Console.ReadKey(true);
                }


                string sIntervalset;
                if (parser.Arguments.ContainsKey("interval"))
                {
                    sIntervalset = parser.Arguments["interval"][0];
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Numeric Data Transmission sets:");
                    Console.WriteLine("1. 1 second (Real time)");
                    Console.WriteLine("2. 12 second (Averaged)");
                    Console.WriteLine("3. 1 minute (Averaged)");
                    Console.WriteLine("4. 5 minute (Averaged)");
                    Console.WriteLine("5. Single poll");
                    Console.WriteLine();
                    Console.Write("Choose Data Transmission interval (1-5):");

                    sIntervalset = Console.ReadLine();
                }

                int[] setarray     = { 1000, 12000, 60000, 300000, 0, 100 }; //milliseconds
                short nIntervalset = 2;
                int   nInterval    = 12000;
                if (sIntervalset != "")
                {
                    nIntervalset = Convert.ToInt16(sIntervalset);
                }
                if (nIntervalset > 0 && nIntervalset < 6)
                {
                    nInterval = setarray[nIntervalset - 1];
                }

                string sDataExportset;
                if (parser.Arguments.ContainsKey("export"))
                {
                    sDataExportset = parser.Arguments["export"][0];
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Data export options:");
                    Console.WriteLine("1. Export as CSV files");
                    Console.WriteLine("2. Export as CSV files and JSON to URL");
                    Console.WriteLine();
                    Console.Write("Choose data export option (1-2):");

                    sDataExportset = Console.ReadLine();
                }

                int nDataExportset = 1;
                if (sDataExportset != "")
                {
                    nDataExportset = Convert.ToInt32(sDataExportset);
                }

                if (nDataExportset == 2)
                {
                    if (parser.Arguments.ContainsKey("devid"))
                    {
                        DeviceID = parser.Arguments["devid"][0];
                    }
                    else
                    {
                        Console.Write("Enter Device ID/Name:");
                        DeviceID = Console.ReadLine();
                    }

                    if (parser.Arguments.ContainsKey("url"))
                    {
                        JSONPostUrl = parser.Arguments["url"][0];
                    }
                    else
                    {
                        Console.Write("Enter JSON Data Export URL(http://):");
                        JSONPostUrl = Console.ReadLine();
                    }
                }
                _serialPort.m_DeviceID    = DeviceID;
                _serialPort.m_jsonposturl = JSONPostUrl;

                if (nDataExportset > 0 && nDataExportset < 3)
                {
                    _serialPort.m_dataexportset = nDataExportset;
                }

                /*Console.WriteLine();
                 * Console.WriteLine("CSV Data Export Options:");
                 * Console.WriteLine("1. Single value list");
                 * Console.WriteLine("2. Data packet list");
                 * Console.WriteLine("3. Consolidated data list");
                 * Console.WriteLine();
                 * Console.Write("Choose CSV export option (1-3):");*/

                //string sCSVset = Console.ReadLine();
                int nCSVset = 3;
                //if (sCSVset != "") nCSVset = Convert.ToInt32(sCSVset);

                string sWaveformSet;
                if (parser.Arguments.ContainsKey("waveset"))
                {
                    sWaveformSet = parser.Arguments["waveset"][0];
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Waveform data export priority options:");
                    Console.WriteLine("0. None");
                    Console.WriteLine("1. ECG I, II, III");
                    Console.WriteLine("2. ECG II, ABP, ART IBP, PLETH, CVP, RESP");
                    Console.WriteLine("3. ECG AVR, ECG AVL, ECG AVF");
                    Console.WriteLine("4. ECG V1, ECG V2, ECG V3");
                    Console.WriteLine("5. ECG V4, ECG V5, ECG V6");
                    Console.WriteLine("6. EEG1, EEG2, EEG3, EEG4");
                    Console.WriteLine("7. ABP, ART IBP");
                    Console.WriteLine("8. Compound ECG, PLETH, ABP, ART IBP, CVP, CO2");
                    Console.WriteLine("9. All");

                    Console.WriteLine();
                    Console.WriteLine("Selecting all waves can lead to data loss due to bandwidth issues");
                    Console.Write("Choose Waveform data export priority option (0-9):");

                    sWaveformSet = Console.ReadLine();
                }

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

                string sWavescaleSet;
                if (parser.Arguments.ContainsKey("scale"))
                {
                    sWavescaleSet = parser.Arguments["scale"][0];
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Waveform data export scale and calibrate options:");
                    Console.WriteLine("1. Export scaled values");
                    Console.WriteLine("2. Export calibrated values");
                    Console.WriteLine();
                    Console.Write("Choose Waveform data export scale option (1-2):");

                    sWavescaleSet = Console.ReadLine();
                }

                short nWavescaleSet = 1;
                if (sWavescaleSet != "")
                {
                    nWavescaleSet = Convert.ToInt16(sWavescaleSet);
                }
                if (nWavescaleSet == 1)
                {
                    _serialPort.m_calibratewavevalues = false;
                }
                if (nWavescaleSet == 2)
                {
                    _serialPort.m_calibratewavevalues = true;
                }

                Console.WriteLine();
                Console.WriteLine("Requesting Transmission set {0} from monitor", nIntervalset);
                Console.WriteLine();
                Console.WriteLine("Data will be written to CSV file MPDataExport.csv in same folder");
                Console.WriteLine();


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

                if (nCSVset > 0 && nCSVset < 4)
                {
                    _serialPort.m_csvexportset = nCSVset;
                }

                _serialPort.SendWaveAssociationRequest();

                //Send Extended PollData Requests cycled every second
                Task.Run(() => _serialPort.SendCycledExtendedPollDataRequest(nInterval));

                WaitForMilliSeconds(500);

                if (nWaveformSet != 0)
                {
                    _serialPort.GetRTSAPriorityListRequest();
                    if (nWaveformSet != 9)
                    {
                        _serialPort.SetRTSAPriorityList(nWaveformSet);
                    }

                    Task.Run(() => _serialPort.SendCycledExtendedPollWaveDataRequest(nInterval));
                }

                //Keep Connection Alive
                Task.Run(() => _serialPort.KeepConnectionAlive(nInterval));

                //Receive PollDataResponse message

                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();
            }
        }