Ejemplo n.º 1
0
        void OnChannelData(CMcsUsbDacqNet d, int cbHandle, int numSamples)
        {
            int sizeRet;

#if channelmethod
#if channeldata
            int totalchannels, offset, channels;
            device.ChannelBlock_GetChannel(0, 0, out totalchannels, out offset, out channels);
            ushort[] data = device.ChannelBlock_ReadFramesUI16(0, channelblocksize, out sizeRet);
            for (int i = 0; i < totalchannels; i++)
            {
                ushort[] data1 = new ushort[sizeRet];
                for (int j = 0; j < sizeRet; j++)
                {
                    data1[j] = data[j * mChannelHandles + i];
                }
                BeginInvoke(new OnChannelDataDelegate(OnChannelDataLater), new Object[] { data1, i });
            }
#else // !channeldata
            int totalchannels, offset, channels;
            device.ChannelBlock_GetChannel(CbHandle, 0, out totalchannels, out offset, out channels);
            Debug.Assert(totalchannels == 1);
            Debug.Assert(channels == 1);
            ushort[] data = device.ChannelBlock_ReadFramesUI16(CbHandle, numSamples, out size_ret);
            BeginInvoke(new OnChannelDataDelegate(OnChannelDataLater), new Object[] { data, offset });
#endif // !channeldata
#else // !channelmethod
            Dictionary <int, ushort[]> data = device.ChannelBlock_ReadFramesDictUI16(CbHandle, numSamples, out size_ret);
            BeginInvoke(new OnChannelDataDelegate(OnChannelDataLater), new Object[] { data });
#endif // !channelmethod
        }
Ejemplo n.º 2
0
        void OnChannelData(CMcsUsbDacqNet d, int CbHandle, int numSamples)
        {
            int size_ret;
            int totalchannels, offset, channels;

            device.ChannelBlock_GetChannel(0, 0, out totalchannels, out offset, out channels);
            ushort[] data = device.ChannelBlock_ReadFramesUI16(0, channelblocksize, out size_ret);

            for (int i = 0; i < 32; i++)
            {
                ushort[] data1 = new ushort[size_ret];
                for (int j = 0; j < size_ret; j++)
                {
                    data1[j] = data[j * m_channel_handles + i];
                    //Console.WriteLine((j * m_channel_handles + i) + " m_channel_handles " + m_channel_handles + " size_ret " + size_ret);
                }
                BeginInvoke(new OnChannelDataDelegate(OnChannelDataLater), new Object[] { data1, i });
            }

            if (ourStream != null)
            {
                try
                {
                    DateTime begin = DateTime.UtcNow;
                    data[0] = sequenceNumber++;
                    byte[] transferBuffer = new byte[data.Length * sizeof(ushort)];
                    //Console.WriteLine("transferBuffer.Length: " + transferBuffer.Length);
                    Buffer.BlockCopy(data, 0, transferBuffer, 0, transferBuffer.Length);
                    ourStream.Write(transferBuffer, 0, transferBuffer.Length);
                    DateTime end = DateTime.UtcNow;
                    Console.WriteLine("Measured time: " + (end - begin).TotalMilliseconds + " ms.");
                }
                catch (Exception e)
                {
                    Console.WriteLine("client is disconnected...");
                    if (listener != null)
                    {
                        Console.WriteLine("stopping listener...");
                        listener.Stop();
                        listener = null;
                    }

                    if (ourStream != null)
                    {
                        Console.WriteLine("closing stream...");
                        ourStream.Close();
                        ourStream = null;
                    }
                    if (ourTCP_Client != null)
                    {
                        ourTCP_Client.Close();
                        ourTCP_Client = null;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void mea_ChannelDataEvent(CMcsUsbDacqNet dacq, int CbHandle, int numFrames)
        {
            //Debug.WriteLine("data available " + numFrames);

            if (numFrames >= Samplerate)
            {
                int[] data = mea.ChannelBlock_ReadFramesI32(0, Samplerate, out int frames_read);
                BeginInvoke(new DisplayDataAction(DisplayData), data);
            }
            else
            {
                int[] data = mea.ChannelBlock_ReadFramesI32(0, numFrames, out int frames_read);
            }
        }
Ejemplo n.º 4
0
        void Port_1_ChannelDataEvent(CMcsUsbDacqNet dacq, int CbHandle, int numFrames)
        {
            FrameCount++;

            Console.WriteLine("data available " + numFrames);
            if (numFrames > Samplerate)
            {
                numFrames = Samplerate;
            }
            data = Port_1.ChannelBlock_ReadFramesI32(0, numFrames, out frames_read);
            //data = Port_1.ChannelBlock_ReadFramesI16 (0, numFrames, out frames_read);
            if (Port_1_Data_Event != null)
            {
                Port_1_Data_Event(this, EventArgs.Empty);
            }
        }
 private void OnChannelData(CMcsUsbDacqNet d, int cbHandle, int numSamples)
 {
     if (useChannelMethod)
     {
         if (useChannelData)
         {
             ChannelDataForChannelMethodAndChannelData();
         }
         else
         {
             ChannelDataForChannelMethodWithoutChannelData(cbHandle, numSamples);
         }
     }
     else
     {
         ChannelDataWithoutChannelMethod(cbHandle, numSamples);
     }
 }
Ejemplo n.º 6
0
        private void _onChannelData(CMcsUsbDacqNet d, int cbHandle, int numSamples)
        {
            try {
                int returnedFrames, totalChannels, offset, channels;

                int handle       = 0;
                int channelEntry = 0;
                int frames       = 0;

                dataAcquisitionDevice.ChannelBlock_GetChannel
                    (handle,
                    channelEntry,
                    out totalChannels,
                    out offset,
                    out channels);

                Dictionary <int, int[]> data = dataAcquisitionDevice.ChannelBlock_ReadFramesDictI32
                                                   (handle,
                                                   segmentLength,
                                                   out returnedFrames);

                if (barfCounter < 3000)
                {
                    if (barfCounter == 2999)
                    {
                        log.info($"totalChannels:  {totalChannels}", "DAQ DEBUG");
                        log.info($"offset:         {totalChannels}", "DAQ DEBUG");
                        log.info($"channels:       {totalChannels}", "DAQ DEBUG");
                        log.info($"returnedFrames: {totalChannels}", "DAQ DEBUG");
                    }
                    barfCounter++;
                }

                onChannelData(data, returnedFrames);
            }
            catch (Exception e) {
                Console.ForegroundColor = ConsoleColor.Red;
                log.err("DAQ ERROR", "DAQ ");
                Console.WriteLine(e);
                dataAcquisitionDevice.Disconnect();
                throw e;
            }
        }
Ejemplo n.º 7
0
        // TODO polish member function for the new DLL version.
        void ChannelDataCallback(CMcsUsbDacqNet UsbDacq, int cb_handle, int num_frames)
        {
            // Acquire raw data.
            int handle;

            // TODO understand MCS black magic.
            handle = 0;
            var channelEntry = 0;
            int totalChannels;
            int offset;
            int channels;

            device.ChannelBlock_GetChannel(handle, channelEntry, out totalChannels, out offset, out channels);
            // TODO understand MCS black magic.
            handle = 0;
            var frames = this.buf_size;
            int frames_ret;

            ushort[] data = device.ChannelBlock_ReadFramesUI16(handle, frames, out frames_ret);
            // TODO remove the following line.
            //this.textBoxLog.Text += (2 * data.Length) + " bytes\r\n";
            // Update the number of acquired buffers.
            this.buf_acq_nb = this.buf_acq_nb + 1;
            // Update the display of the number of acquired buffers.
            this.textBoxBufferAcquired.Text = this.buf_acq_nb.ToString();
            // Send data to backup if necessary.
            if (this.dataBackupWorker.IsBusy && (!this.checkBoxLockBackupBroadcast.Checked || tcpClient.Connected) && !this.dataBackupWorker.CancellationPending)
            {
                this.dataBackupBuffer.Add(data);
            }
            // Send data to broadcast if necessary.
            if (this.dataBroadcastWorker.IsBusy && tcpClient.Connected && !this.dataBroadcastWorker.CancellationPending)
            {
                // TODO modify the condition (i.e. #.IsBusy -> #.IsBusyAndAcceptedConnection)
                this.dataBroadcastBuffer.Add(data);
            }
        }
Ejemplo n.º 8
0
 public CHWInfo(CMcsUsbDacqNet device);
Ejemplo n.º 9
0
 protected void raise_ChannelDataEvent(CMcsUsbDacqNet value0, int value1, int value2);
Ejemplo n.º 10
0
 void Port_2_ChannelDataEvent(CMcsUsbDacqNet dacq, int CbHandle, int numFrames)
 {
 }