1.VCä¸ç¨CSerialPortç±»è¿è¡ä¸²å£ç¼ç¨
VCä¸ç¨CSerialPortç±»è¿è¡ä¸²å£ç¼ç¨
serialPort.Readè¿ä¸ªå½æ°ç¨ä¸èµ·?串口串口客源采集源码è¿æ¯ä¸èµ·ä½ç¨å¸§å
å®ä¹ä¸ä¸ª BYTE buffer[1++1]; ä¹å°±æ¯ buffer[];
åå®ä¹ä¸ä¸ªint bufferLength = 0;
OnCommunication(...)ä¸{
if (0 == bufferLength) // 帧头è¿æªæ¥æ¶
{
if (0xAF != ch) // ä¸æ¯å¸§å¤´
return; // è¿å
}
if ( == bufferLength) // 帧尾è¿æªæ¥æ¶
{
if (0xFA != ch) // ä¸æ¯å¸§å°¾
{
bufferLength = 0; // 丢å¼å·²ç»æ¥æ¶çæ°æ®ï¼éç½®ç¼å²åºæææ°æ®é¿åº¦ä¸ºé¶
return; // è¿å
}
}
// è¦å®æ¶æ¾ç¤ºæ¥æ¶å°ç ch ï¼å¨è¿éæ·»å 代ç å³å¯
buffer[bufferLength] = ch;
bufferLength++;
if ( == bufferLength)
{
// ä¸å¸§å·²ç»æ¥æ¶å®æ¯ï¼æ°æ®å¨ buffer ä¸
bufferLength = 0; // ååºå¸§åï¼éç½®ç¼å²åºæææ°æ®é¿åº¦ä¸ºé¶
}
}
2024-11-27 12:16
2024-11-27 12:12
2024-11-27 11:58
2024-11-27 11:50
2024-11-27 11:28
2024-11-27 09:52