Exemplo n.º 1
0
        public static void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the state object and the client
                // from the asynchronous state object.
                UdpState state = (UdpState)ar.AsyncState;

                MPudpclient Client = state.udpClient;

                string path = Path.Combine(Directory.GetCurrentDirectory(), "MPrawoutput.txt");

                // Read data from the remote device.
                byte[] readbuffer = Client.EndReceive(ar, ref state.remoteIP);
                int    bytesRead  = readbuffer.GetLength(0);

                if (bytesRead > 0)
                {
                    // There might be more data, so store the data received so far.

                    Client.ByteArrayToFile(path, readbuffer, bytesRead);

                    Client.ReadData(readbuffer);

                    //  Get the rest of the data.
                    Client.BeginReceive(new AsyncCallback(ReceiveCallback), state);
                }
                else
                {
                    // All the data has arrived; put it in response.


                    // Signal that all bytes have been received.
                    receiveDone.Set();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 2
0
        public static void ConnectviaLAN()
        {
            Console.WriteLine("You may connect an Ethernet cable to the Philips Intellivue monitor LAN port");
            Console.WriteLine("Note the IP address from the Network Status menu in the monitor");

            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 options:");
            Console.WriteLine("0. None");
            //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);
            }

            // Create a new UdpClient object with default settings.
            MPudpclient _MPudpclient = MPudpclient.getInstance;

            Console.WriteLine("Enter the target IP address of the monitor assigned by DHCP:");

            string IPAddressRemote = Console.ReadLine();

            Console.WriteLine("Connecting to {0}...", IPAddressRemote);
            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)
            {
                _MPudpclient.m_csvexportset = nCSVset;
            }

            if (IPAddressRemote != "")
            {
                //Default Philips monitor port is 24105
                _MPudpclient.m_remoteIPtarget = new IPEndPoint(IPAddress.Parse(IPAddressRemote), 24105);


                try
                {
                    _MPudpclient.Connect(_MPudpclient.m_remoteIPtarget);

                    UdpState state = new UdpState();
                    state.udpClient = _MPudpclient;
                    state.remoteIP  = _MPudpclient.m_remoteIPtarget;

                    //Send AssociationRequest message
                    //_MPudpclient.SendAssociationRequest();
                    _MPudpclient.SendWaveAssociationRequest();

                    string path = Path.Combine(Directory.GetCurrentDirectory(), "MPrawoutput.txt");

                    //Receive AssociationResult message and MDSCreateEventReport message
                    byte[] readassocbuffer = _MPudpclient.Receive(ref _MPudpclient.m_remoteIPtarget);
                    _MPudpclient.ByteArrayToFile(path, readassocbuffer, readassocbuffer.GetLength(0));


                    byte[] readmdsconnectbuffer = _MPudpclient.Receive(ref _MPudpclient.m_remoteIPtarget);
                    _MPudpclient.ByteArrayToFile(path, readmdsconnectbuffer, readmdsconnectbuffer.GetLength(0));

                    //Send MDSCreateEventResult message
                    _MPudpclient.ProcessPacket(readmdsconnectbuffer);

                    //Send PollDataRequest message
                    //_MPudpclient.SendPollDataRequest();
                    // _MPudpclient.SendExtendedPollDataRequest();

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

                    //WaitForSeconds(1);

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

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

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

                    //Receive PollDataResponse message
                    _MPudpclient.BeginReceive(new AsyncCallback(ReceiveCallback), state);

                    //Parse PollDataResponses
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error opening/writing to UDP port :: " + ex.Message, "Error!");
                }
            }
            else
            {
                Console.WriteLine("Invalid IP Address");
            }
        }
Exemplo n.º 3
0
        public static void ConnectviaLAN(string[] args)
        {
            var parser = new CommandLineParser();

            parser.Parse(args);

            string sIntervalset;

            if (parser.Arguments.ContainsKey("interval"))
            {
                sIntervalset = parser.Arguments["interval"][0];
            }
            else
            {
                Console.WriteLine("You may connect an Ethernet cable to the Philips Intellivue monitor LAN port");
                Console.WriteLine("Note the IP address from the Network Status menu in the monitor");

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

            /*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 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);
            }

            // Create a new UdpClient object with default settings.
            MPudpclient _MPudpclient = MPudpclient.getInstance;

            string IPAddressRemote;

            if (parser.Arguments.ContainsKey("port"))
            {
                IPAddressRemote = parser.Arguments["port"][0];
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("Enter the target IP address of the monitor assigned by DHCP:");

                IPAddressRemote = Console.ReadLine();
            }

            Console.WriteLine("Connecting to {0}...", IPAddressRemote);
            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 (nDataExportset > 0 && nDataExportset < 3)
            {
                _MPudpclient.m_dataexportset = nDataExportset;
            }

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

            if (nWavescaleSet == 1)
            {
                _MPudpclient.m_calibratewavevalues = false;
            }
            if (nWavescaleSet == 2)
            {
                _MPudpclient.m_calibratewavevalues = true;
            }

            if (IPAddressRemote != "")
            {
                //Default Philips monitor port is 24105
                _MPudpclient.m_remoteIPtarget = new IPEndPoint(IPAddress.Parse(IPAddressRemote), 24105);

                _MPudpclient.m_DeviceID    = DeviceID;
                _MPudpclient.m_jsonposturl = JSONPostUrl;

                try
                {
                    _MPudpclient.Connect(_MPudpclient.m_remoteIPtarget);

                    UdpState state = new UdpState();
                    state.udpClient = _MPudpclient;
                    state.remoteIP  = _MPudpclient.m_remoteIPtarget;

                    //Send AssociationRequest message
                    //_MPudpclient.SendAssociationRequest();
                    _MPudpclient.SendWaveAssociationRequest();

                    string path = Path.Combine(Directory.GetCurrentDirectory(), "MPrawoutput.txt");

                    //Receive AssociationResult message and MDSCreateEventReport message
                    byte[] readassocbuffer = _MPudpclient.Receive(ref _MPudpclient.m_remoteIPtarget);
                    _MPudpclient.ByteArrayToFile(path, readassocbuffer, readassocbuffer.GetLength(0));


                    byte[] readmdsconnectbuffer = _MPudpclient.Receive(ref _MPudpclient.m_remoteIPtarget);
                    _MPudpclient.ByteArrayToFile(path, readmdsconnectbuffer, readmdsconnectbuffer.GetLength(0));

                    //Send MDSCreateEventResult message
                    _MPudpclient.ProcessPacket(readmdsconnectbuffer);

                    //Send PollDataRequest message
                    //_MPudpclient.SendPollDataRequest();

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

                    //WaitForSeconds(1);

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

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

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

                    //Receive PollDataResponse message
                    _MPudpclient.BeginReceive(new AsyncCallback(ReceiveCallback), state);

                    //Parse PollDataResponses
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error opening/writing to UDP port :: " + ex.Message, "Error!");
                }
            }
            else
            {
                Console.WriteLine("Invalid IP Address");
            }
        }