2015-01-28 02:28 PM
i can send string with lwip.
how send NULL string with lwip sprintf(BUF,''(%c%c%c%c'',len/256,len%256,Cmd/256,Cmd%256);strncat(&BUF[5],buf,len);
strncat(&BUF[5+len],'')'',1);
tcp_write(TcpPCB,BUF,BufLen+6,1);
if value at location 1 or 3 is 0 tcp_write send 1 or 3 byte
#stm32 #lwip #null #pascalstring2015-01-28 04:58 PM
If you're sending binary data, don't use string functions to do it. Are you sure the problem isn't at the receiving end?
2015-01-29 12:59 AM
Yes
I send binary data.when data have 0 , receiving and sending have problemwhich function send and receive binary data in lwip?Thanks2015-01-29 01:08 AM
lpiw is innocent in this case.
You must not use str(n)cpy()/str(n)cat() for copying binary data; use memcpy(). JW2015-01-29 01:27 AM
i use strncat(
&BUF[5]
,buf,len);problem in sending and receivingi change code to this :BUF[0]='(';BUF[1]=(len/256);BUF[2]=(len%256);BUF[3]=(Cmd/256);BUF[4]=(Cmd%256);for(i=0;i<len;i++) BUF[5+i]=dbuf[i];BUF[5+i]=')'; tcp_write(TcpPCB,BUF,BufLen+6,1);when len<10 send and receive 1 byte
when len=10 or 20 or 30 , ... send and receive 2 byte
when 0 in dbuf send and receive until 0 index2015-01-29 03:51 AM
> tcp_write(TcpPCB,BUF,BufLen+6,1);
What is BufLen? Where do you have it from? What is its value at that moment? (You should also use the symbols defined for the apiFlag parameter instead of numbers, namely TCP_WRITE_FLAG_COPY instead of 1, but that is not what causes your problem at the moment.) JW2015-01-29 06:57 AM
static err_t SendPacket(uint16_t Cmd,unsigned char *dbuf,int len,int
BufLen
){ char BUF[600]; int i; if(TcpPCB->state==CLOSED){ return ERR_CLSD; }BUF[0]='(';
BUF[1]=(len/256);
BUF[2]=(len%256);
BUF[3]=(Cmd/256);
BUF[4]=(Cmd%256);
for(i=0;i<len;i++)
BUF[5+i]=dbuf[i];
BUF[5+i]=')';
tcp_write(TcpPCB,BUF,BufLen+6,1);
}
2015-01-29 07:02 AM
Nice, but this still did not answer, what is the value of it and where does it come from (i.e. show how do you invoke this function).
JW2015-01-29 07:38 AM