通过串口发送数据到远程服务器上面
1.首先要打开网络串口助手,设置好本机的IP(192.168.1.231)和端口号5002,协议类型为TCP Server(关键)。否则是连接不上远程端口的,也就是说不会返回CONNECT OK
2.串口调试:
AT+CIPHEAD=1(回车换行发送,非十六进制去发送) //1----GPRS 接收方式
ok
AT+CIPSTART="TCP","60.186.20.162","5002" (回车换行发送,非十六进制去发送)
ok
CONNECT OK
CONNECT OK
AT+CIPSEND(回车换行发送,非十六进制去发送)
>
所要发送的数据。。。
1A(结束符,以十六进制去发送)
SEND OK (当数据成功发送后,会返回SEND OK)
附录AT指令表
const unsigned char OK[] ="OK";
const unsigned char ALRDY_CONCT[] ="ALREADY CONNECT";
const unsigned char TCP_CONNECTING[] ="TCP CONNECTING";
const unsigned char CONNECT_OK[] ="CONNECT OK";
const unsigned char code_ERROR[] ="ERROR";
const unsigned char PDP_DEACT[] ="PDP DEACT";
const unsigned char TCP_CLOSED[] ="TCP CLOSED";
const unsigned char IP_INITIAL[] ="IP INITIAL";
const unsigned char AT[] ="AT";//握手信号
const unsigned char ATI[] ="ATI";//设备初始化
const unsigned char ATE0V1[] ="ATE0";//关回显设置命令返回OK/V1 0/V0
const unsigned char AT_IPR[] ="AT+IPR=9600";//波特率设置
const unsigned char AT_CPIN[] ="AT+CPIN?";//查询SIM卡状态
const unsigned char AT_CSQ[] ="AT+CSQ";//查询信号
const unsigned char AT_COPS[] ="AT+COPS?";//查询网络运营商
const unsigned char AT_CDSNORIP[] ="AT+CDNSORIP=0";//0----GPRS IP 方式
const unsigned char AT_CIPHEAD[] ="AT+CIPHEAD=1";//1----GPRS 接收方式,设置IP头,IP头格式为:"+IPD(data length):"
const unsigned char AT_CIPSEND[] ="AT+CIPSEND";//GPRS发送信息命令
const unsigned char AT_CIPCLOSE[] ="AT+CIPCLOSE";//TCP连接关闭
const unsigned char AT_CIPSHUT[] ="AT+CIPSHUT";//GPRS连接关闭
const unsigned char AT_CIPSTATUS[] ="AT+CIPSTATUS";
const unsigned char AT_CIPSPRT[] ="AT+CIPSPRT=2";
static void BSP_IntHandlerUSART1 (void)
{
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL();
OSIntNesting++;
OS_EXIT_CRITICAL();
/*
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
re_RFID=1;
Res =(USART_ReceiveData(USART1)& 0x7F);//(USART1->DR);//读取接收到的数据
USART_RX_BUF[USART_RX_STA]=Res ;
USART_RX_STA++;
}
*/
//////下面的中断更能够精确的接受来自PC串口助手的数据,发送的数据必须以回车的方式发送
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
re_RFID=1;
Res =USART_ReceiveData(USART1);//(USART1->DR);//读取接收到的数据
if((USART_RX_STA&0x8000)==0)//接收未完成
{
if(USART_RX_STA&0x4000)//接收到了0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
else USART_RX_STA|=0x8000; //接收完成了
}
else //还没收到0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收
}
}
}
}
OSIntExit();
}