c# - Can't Send more Than 64 Byte to Arduino
问题描述
I need to communicate with Arduino from PC.
I have C# code. I send 87 bytes to the Arduino.
C# Code
byte[] MyBuffer = new byte[87];
// I initialize buffer with bytes(0-255) details are not important.
serialport1.Write(MyBuffer, 0, 87);
Arduino part is the most important. Because I am going to split these bytes to 5 different arrays.
byte FirstBlock[16];
byte SecondBlock[16];
byte ThirdBlock[16];
byte FourthBlock[16];
byte FifthBlock[16];
byte ReceivedBuffer[87];
int counter = 0
bool SYNC = false;
void loop(){
if(Serial.available())
CropBytes();
if(SYNC == true){
SplitBytes();
DoSomeStaffWithBlocks();
SYNC = false;
} } //End Loop
void CropBytes(){
while(Serial.available()){
byte ReceivedByte = Serial.read();
ReceivedBuffer[counter] = ReceivedByte;
// byte 35 means my byte transfer is over for ReceivedBuffer[86]
if(counter == 86 && ReceivedBuffer[counter] == 35){
SYNC = true;
counter = 0;
}
else{
counter = counter + 1;
}
}
}
void SplitBytes(){
for (int i = 5; i < 21; i++)
{
FirstBlock[i - 5] = ReceivedBuffer[i];
}
for (int i = 21; i < 37; i++)
{
SecondBlock[i - 21] = ReceivedBuffer[i];
}
for (int i = 37; i < 53; i++)
{
ThirdBlock[i - 37] = ReceivedBuffer[i];
}
for (int i = 53; i < 69; i++)
{
FourthBlock[i - 53] = ReceivedBuffer[i];
}
for (int i = 69; i < 85; i++)
{
FifthBlock[i - 69] = ReceivedBuffer[i];
}
}
The problem - FirstBlock[]
, SecondBlock[]
, ThirdBlock[]
received successfully no problem. But after ThirdBlock
, FourthBlock
(after 11th byte) and FifthBlock
(all bytes) arrays don't initialize successfully.
I don't know where is the problem.
解决方案
推荐阅读
- c# - 无法从 HttpListener .NET 读取数据
- scala - 有没有办法以通用方式将 Hlist 转换为适当的案例类?
- python - 如何只计算熊猫中的新数据,而不是整个表?
- c - 为什么 strtok_r 在 '.'(peroid)而不是 ','(逗号)处断开字符串?
- c# - Unity:使用 Rigidbody2D 的 Drag 来减慢飞行角色的速度
- mysql - 如何在“清洁架构”中实现“SQL 事务”?
- tarantool - 在 tarantool 从站中优先读取与写入
- css - 如何在引导期间为 react.js 中的包导入 CSS 文件?
- python - 如何跟踪我从矩阵中随机选择的行的行索引?
- c# - 如何从 IDictionary 中获取价值
在 VisitMember 通话中?