This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/MSP432E411Y:使用 TCPIP 发送命令。

Guru**** 2582775 points
Other Parts Discussed in Thread: MSP432E411Y

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/948249/ccs-msp432e411y-use-the-tcpip-send-command

器件型号:MSP432E411Y

工具/软件:Code Composer Studio

大家好、我始终感谢您的帮助。

我目前正在创建和使用 TCPIP.c 和 mainthread.c

这是我的 TCPIP.c 代码。

#include
#include
#include

#include
/* BSD 支持*/
#include
#include
#include
#include

#include

#include

静态 int 服务器=-1;
静态字符 ip_address[]={"xxx.xxx.xxx"};

#define TCPPACKETSIZE 256
#define NUMTCPWORKERS 3.
#define MAXPORTLEN   6.

extern Display_Handle 显示;

extern void fdOpenSession();
extern void fdCloseSession();
extern void *TaskSelf();

void senddata (char* adcname、int time、int adcresult)

   if (服务器>-1)
   {
       char data[100]={0};
       sprintf (数据、"%s_%d_%d"、adcname、time、adcresult);
       SEND (server、data、strlen (data)、0);
   }


void *tcpHandler (void *arg0)

   INT 状态;
   struct sockaddr_in  pc_addr;
   char buffer[256];
   int PC =-1;

   fdOpenSession (TaskSelf());

   memset (&PC_addr、0、sizeof (PC_addr));
   PC_addr.sin 系列= AF_iNet;
   PC_addr.sin 端口  = htons (15000);
   pc_addr.sin addr.s_addr = inet_addr (ip_address);

   while (1)
   {
       PC =套接字(AF_iNet、SOCK_STREAM、0);
       status = connect (PC、(struct sockaddr *)&PC_addr、sizeof (PC_addr));

       if (状态< 0)
       {
           如果(PC!=-1)关闭(PC);
       }
       否则中断;
   }

   服务器= PC;

   while (1)
   {
       if (recv (PC、buffer、2、0)>0)
       {
           SEND (PC、buffer、strlen (buffer)、0);
       }
   }

   关闭(PC);

   fdCloseSession(TaskSele());

   返回(空);

这是我的 mainthread.c

#include
#include

#include

#include "ti_drivers_config.h"


#define ADC_SAMPLE_COUNT (10)

#define THREADSTACKSIZE  (768)

extern void senddata (char* adcname、int time、int adcresult);

void timerCallback (Timer_handle myHandle、int_fast16_t 状态);

int sec = 0;

void * mainThread (void * arg0)

   Timer_handle timer0;
   Timer_Params 参数;
   timer_init();

   Timer_Params_init (&params);
   params.period = 1000000;
   Params.periodUnits = Timer_Period_US;
   params.timerMode = Timer_Continuous_callback;
   params.timerCallback = timerCallback;

   timer0 = Timer_open (CONFIG_TIMER_0、params);

   if (timer0 == NULL){
       while (1){}
   }

   如果(Timer_start (timer0)= Timer_STATUS_ERROR){
       while (1){}
   }

   返回(空);

空 timerCallback (Timer_handle myHandle、int_fast16_t 状态)

   sec++;
   senddata ("A"、秒、1000);

使用 TCPIP.c 中的 senddata 函数可以很好地将数据传输到 PC。

但是、如果在 mainthread.c 中调用该函数、则不会传输数据。

我可能已经愚蠢地进行了编码。

经过几天的思考,我无法弄明白。

发送函数服务器被声明为 extern、并被 mainthread.c 使用、但结果相同。

我出了什么问题?

请帮帮我。