c# - Most efficient way to transmit 32768 int16_t values over USB?
问题描述
I've got a project that produces 32768 int16_t values every 1.125 seconds. What's the most efficient way to "package" these for transmission over USB? Currently I'm pumping them out with commas between every value (and semicolons every 4096 values, with an "X" as the final character). It occurs to me that the host won't know that a given value is one or two bytes, so pre-allocating a buffer and waiting for it to fill won't work.
The USB device is programmed in C++ and the host is programmed in C#, if that helps. On the host end, I've got this function from a UWP sample:
private async Task ReadAsync(CancellationToken cancellationToken)
{
Task<UInt32> loadAsyncTask;
uint ReadBufferLength = 98305;
// Don't start any IO if we canceled the task
lock (ReadCancelLock)
{
cancellationToken.ThrowIfCancellationRequested();
// Cancellation Token will be used so we can stop the task operation explicitly
// The completion function should still be called so that we can properly handle a canceled task
DataReaderObject.InputStreamOptions = InputStreamOptions.Partial;
loadAsyncTask = DataReaderObject.LoadAsync(ReadBufferLength).AsTask(cancellationToken);
}
UInt32 bytesRead = await loadAsyncTask;
if (bytesRead > 0)
{
ReadBytesTextBlock.Text += DataReaderObject.ReadString(bytesRead);
ReadBytesCounter += bytesRead;
UpdateReadBytesCounterView();
}
rootPage.NotifyUser("Read completed - " + bytesRead.ToString() + " bytes were read", NotifyType.StatusMessage);
}
Is there a method that allows me to read until a certain character is detected, like "X"? Ultimately these values need to be parsed into int16_t arrays so I can do some FFTs.
I admit that right now I'm really hacking this together and hoping it works, but I would love a reliable and robust way to do this properly.
解决方案
推荐阅读
- python - 循环或迭代 DataFrame 中的列以替换空值
- python - 如何从符号列表构建树?
- sql - SQL从另一个数据库表中复制数据,在目标上具有指定的列格式
- python - Pandas GroupBy 对象:它是什么?
- ios - 逻辑问题:如何让单元格图像在用户平移一次后继续翻转?
- ios - 在 xamarin 表单中,ios Launchscreen 和 App 图标没有改变
- c# - 使用 Linq 按名称频率对列表进行排序
- pandas - pandas groupby 和 nan
- bash - 将两个不同文件夹中具有相同条形码的fastq文件合并到另一个文件夹
- c# - 使用未分配的局部变量“KubeClient”