void timer_Tick(object sender, EventArgs e) { int size_ret; #if channelmethod #if channeldata uint frames = device.ChannelBlock_AvailFrames(0); if (frames > channelblocksize) { 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 < totalchannels; i++) { ushort[] data1 = new ushort[channelblocksize]; for (int j = 0; j < channelblocksize; j++) { data1[j] = data[j * m_channel_handles + i]; } OnChannelDataLater(data1, i); } } #else // !channeldata for (int i = 0; i < m_channel_handles; i++) { uint frames = device.ChannelBlock_AvailFrames(i); if (frames > channelblocksize) { int totalchannels, offset, channels; device.ChannelBlock_GetChannel(i, 0, out totalchannels, out offset, out channels); Debug.Assert(totalchannels == 1); Debug.Assert(channels == 1); ushort[] data = device.ChannelBlock_ReadFramesUI16(i, channelblocksize, out size_ret); OnChannelDataLater(data, offset); } } #endif // !channeldata #else // !channelmethod uint frames = device.ChannelBlock_AvailFrames(0); if (frames > channelblocksize) { Dictionary <int, ushort[]> data = device.ChannelBlock_ReadFramesDictUI16(0, channelblocksize, out size_ret); OnChannelDataLater(data); } #endif // !channelmethod }
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; } } } }
private void TimerTickForChannelMethodAndChannelData() { uint frames = device.ChannelBlock_AvailFrames(0); if ((LastData == 1 || frames > channelblocksize) && frames > 0) { device.ChannelBlock_GetChannel(0, 0, out int totalChannels, out int byte_offset, out int channel_offset, out int channels); ushort[] data = device.ChannelBlock_ReadFramesUI16(0, channelblocksize, out int sizeRet); for (int i = 0; i < totalChannels; i++) { ushort[] channelData = new ushort[sizeRet]; for (int j = 0; j < sizeRet; j++) { channelData[j] = data[j * totalChannels + i]; } DrawChannelDataWithChannelMethod(channelData, i); } } }
// 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); } }