ZigBee Serial printing can not display or garbled resolution method

Source: Internet
Author: User
Tags strlen
ZigBee Serial printing problem

When the endpoint sends data to the coordinator, it is accompanied by the network address of the node in the data stream, and sometimes cannot be printed by the PC side. 1. There may be a problem with the serial software:

  Use several serial port software, sometimes appear stop, or garbled behavior, in after many Exchange software, found **securecrt** This software is good, solve most of the problem
2. The data sent is not converted:
  In general, in the terminal sends the data function, adds ' 0 ' the conversion to be OK.
    Sendbuf[0]= ' $ ';
    sendbuf[1]= ' @ '; 
    SENDBUF[2] = hi_uint16 (Enddeviceid);
    SENDBUF[3] = lo_uint16 (Enddeviceid);
    SENDBUF[4] = zigbee_fun_code_rfid_conflict; FC
    sendbuf[5]=5;   Data len
    sendbuf[6]= (revbuffer[1]==0) 1:0;   Success
    Sendbuf[7]=revbuffer[2];  Data
    sendbuf[8]=revbuffer[3];  Data
    sendbuf[9]=revbuffer[4];  Data
    sendbuf[10]=revbuffer[5];  Data
    sendbuf[11] = Xorchecksum (&sendbuf[2], 9);
    SENDBUF[12] = ' \ r ';
    SENDBUF[13] = ' \ n ';

Add ' 0 ' to the data section, it's okay.

    SENDBUF[8]=REVBUFFER[3] + ' 0 ';  Data
    sendbuf[9]=revbuffer[4] + ' 0 ';  Data
    sendbuf[10]=revbuffer[5] + ' 0 ';  Data
3. You can try the Zigbbe data conversion function _ltoa (unsigned long l, unsigned char *buf, unsigned char radix)

In the Osal.c file:

unsigned char * _LTOA (unsigned long l, unsigned char *buf, unsigned char radix) {#if defined (__gnuc__) return ((Char
*) Ltoa (L, buf, Radix));
  #else unsigned char tmp1[10] = "", tmp2[10] = "", tmp3[10] = "";
  unsigned short num1, num2, num3;

  unsigned char i;

  Buf[0] = ' + ';
    if (radix = =) {NUM1 = l% 10000;
    num2 = (l/10000)% 10000;

    NUM3 = (unsigned short) (l/100000000);
    if (num3) _itoa (num3, Tmp3, 10);
    if (num2) _itoa (num2, TMP2, 10);

    if (NUM1) _itoa (NUM1, TMP1, 10);
      if (num3) {strcpy ((char*) buf, (char const*) Tmp3);
    for (i = 0; i < 4-strlen (char const*) tmp2) i++) strcat ((char*) buf, "0");
    } strcat ((char*) buf, (char const*) TMP2);
    if (num3 | | num2) {for (i = 0; I < 4-strlen ((char const*) TMP1); i++) strcat ((char*) buf, "0");
    } strcat ((char*) buf, (char const*) TMP1);
  if (!num3 &&!num2 &&!num1) strcpy ((char*) buf, "0"); } else if (Radix = = +) {NUM1 = L & 0x0000ffff;

    num2 = l >> 16;
    if (num2) _itoa (num2, TMP2, 16);

    if (NUM1) _itoa (NUM1, TMP1, 16);
      if (num2) {strcpy ((char*) buf, (char const*) TMP2);
    for (i = 0; i < 4-strlen (char const*) tmp1) i++) strcat ((char*) buf, "0");
    } strcat ((char*) buf, (char const*) TMP1);
  if (!num2 &&!num1) strcpy ((char*) buf, "0");

  } else return NULL;
return buf; #endif}

L represents the array to be converted.
BUF represents a pointer to the converted Array
Radix represents a binary, 10 or 16

This is the conversion function I wrote myself (I opened a dual serial port):

Port print function convert  uart:0->uart0,1->uart1;data destination array; Len length; Slen begins with the first; Elen countdown to the end of the
static void uart_printf (Uint8 uart,uint8 *data,uint8 len,uint8 slen,uint8 Elen)
{    
     uint8 i;
     Uint8 data[30]={0};
     Uint8 *ltoas;
     Ltoas=data;
     for (i=slen;i<len-elen;i++)
     {
       _ltoa (data[i],ltoas,16);
       ltoas+=2;
       *ltoas++= ';
     }
    *ltoas++= ' + ';
    if (uart==0)
      haluartwrite (Uart0,data,len-slen);
    else
      Haluartwrite (Uart1,data,len-slen);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.