我在STM32上很新,我遇到了一个问题。
使用Qt App,我可以使用以下代码通过USB发送内容:
if (m_hidDevice->isOpen())
{
QByteArray buffer(m_hidDevice->readOutputBufferSize(), 0);
buffer[0] = 16;
buffer[1] = 18;
uint16_t number = 4096;
uint16_t randomValue = qrand() % number;
buffer[2] = (char)((randomValue >> 8) & 0x00ff);
buffer[3] = (char)(randomValue & 0x00ff);
buffer[4] = (char)((2556 >> 8) & 0x00ff);
buffer[5] = (char)(2556 & 0x00ff);
qDebug() << "------------" << randomValue;
qDebug() << "//" << (uint8_t)buffer[2] << "//" << (uint8_t)buffer[3];
qDebug() << "//" << (uint8_t)buffer[4] << "//" << (uint8_t)buffer[5];
m_hidDevice->write(buffer);
和使用
的STM32F4switch (buffer[1])
{
case 18:
x = ((uint16_t)buffer[2] << 8) + buffer[3];
y = ((uint16_t)buffer[4] << 8) + buffer[5];
sr.m_value1[0] = x;
sr.m_value1[1] = y;
do(M);
m_value的大小为4,它是uint16_t;
Qt App上的输出是
------------ 2083
// 8 // 35
// 9 // 252
在STM32F4上,x和y具有值
x = 2083 (as expected)
y = 0
现在缓冲区的大小应该是64字节,而我的数据是8 * 5 = 40字节。 那么我的问题是为什么我无法正确检索缓冲区中的值?
此致
答案 0 :(得分:0)
0x09, 0x01, // USAGE (Vendor Usage x) --> x = 1,2,3
0x75, 0x08, // REPORT_SIZE (8) --> 2^8 = 255
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
0x85, 0x02, // REPORT_ID (n) --> n must be the report id
0x95, 0x3f, // REPORT_COUNT (63) --> size
0x91, 0x02 // OUTPUT (Data,Var,Abs)