在串口通讯中如何自定义数据包,有没有相关的网上资料。

解决方案 »

  1.   

    自己定义一个结构:
    例如:
    typedef struct
    {
        char name[20];
        char xb[5];
        int age;
    }people;每次发送的时候,你就发送一个这样的结构数据包……
    如:
    people p1;
    strcpy(p1.name,"abc");
    strcpy(p1.xb,"1);
    p1.age=20;long ret;
    WriteFile(hfile,(void*)&p1,sizeof(people),&ret,NULL);
    ……
      

  2.   

    谢谢mfc168,我想在接收到的字符串中包括我在发送时自己加的起始位和异或校验,不知发送时的代码该怎么写才能实现我的要求。