大学生
最后登录1970-1-1
在线时间 小时
注册时间2017-2-7
|
各位大神,我又来叨扰了……之前请教的问题“如何使用串口发送图片”,我已经找到解决方法了,就是不能用发字符串的方法,要用发数组的方法就可以了,代码如下:
res_sd = f_open(&fnew, "0:pic1.bmp", FA_OPEN_EXISTING | FA_READ);
if(res_sd == FR_OK)
{
LED_GREEN;
//printf("》打开文件成功。\r\n");
if(res_sd==FR_OK)
{
while(res_sd == FR_OK)
{
res_sd = f_read(&fnew,ReadBuffer, sizeof(ReadBuffer), &fnum);
Usart_SendArray(DEBUG_USARTx,ReadBuffer,fnum);
if(res_sd||fnum==0)break;
}
//printf("%s", ReadBuffer);
}
else
{
//printf("!!文件读取失败:(%d)\n",res_sd);
}
}
我现在遇到的问题是,怎么用esp8266模块发送数组,火哥给的例程只有发送字符串,下面的两个关于esp8266发送数据的函数看也不太懂,求大神指导或提供一下思路,万分感谢!!!
bool ESP8266_SendString ( FunctionalState enumEnUnvarnishTx, char * pStr, u32 ulStrLength, ENUM_ID_NO_TypeDef ucId, uint16_t num )
{
char cStr [20];
bool bRet = false;
if ( enumEnUnvarnishTx )
{
macESP8266_Usart ( "%s", pStr );
bRet = true;
}
else
{
if ( ucId < 5 )
sprintf ( cStr, "AT+CIPSEND=%d,%d", ucId, ulStrLength + 2 );
else
sprintf ( cStr, "AT+CIPSEND=%d", ulStrLength + 2 );
ESP8266_Cmd ( cStr, "> ", 0, 1000 );
bRet = ESP8266_Cmd ( pStr, "SEND OK", 0, 1000 );
}
return bRet;
}
void USART_printf ( USART_TypeDef * USARTx, char * Data, ... )
{
const char *s;
int d;
char buf[16];
va_list ap;
va_start(ap, Data);
while ( * Data != 0 ) // 判断是否到达字符串结束符
{
if ( * Data == 0x5c ) //'\'
{
switch ( *++Data )
{
case 'r': //回车符
USART_SendData(USARTx, 0x0d);
Data ++;
break;
case 'n': //换行符
USART_SendData(USARTx, 0x0a);
Data ++;
break;
default:
Data ++;
break;
}
}
else if ( * Data == '%')
{ //
switch ( *++Data )
{
case 's': //字符串
s = va_arg(ap, const char *);
for ( ; *s; s++)
{
USART_SendData(USARTx,*s);
while( USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET );
}
Data++;
break;
case 'd':
//十进制
d = va_arg(ap, int);
itoa(d, buf, 10);
for (s = buf; *s; s++)
{
USART_SendData(USARTx,*s);
while( USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET );
}
Data++;
break;
default:
Data++;
break;
}
}
else USART_SendData(USARTx, *Data++);
while ( USART_GetFlagStatus ( USARTx, USART_FLAG_TXE ) == RESET );
}
}
|
|