c#原生TCP连接工具支持IPV4和IPV6 源代码
方便调试编写的一个TCP通讯工具,支持IPV4和IPV6连接,支持多种编码在线更改,自动发送。
STM32F1系列单片机4路ADC采集程序
使用STM32内部ADC通过DMA通道采集4路模拟量数据,转换为0-24mA信号,0-3.3V对应值为0-24mA,硬件电路采样电阻为150Ω。
STM32 JSON例子,数据序列化为Json格式
将数据序列化为JSON格式,序列化操作完成后务使用Myfree()函数来释放内存
void Josn_format()
{
//cJSON构造方法
cJSON *root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "ADC1", Dev_data.ai1);
cJSON_AddNumberToObject(root, "ADC2", Dev_data.ai2);
cJSON_AddNumberToObject(root, "ADC3", Dev_data.ai3);
cJSON_AddNumberToObject(root,"DI1", Dev_data.input[0]);
cJSON_AddNumberToObject(root,"DI2", Dev_data.input[1]);
cJSON_AddNumberToObject(root,"DI3", Dev_data.input[2]);
cJSON_AddNumberToObject(root,"DI4", Dev_data.input[3]);
cJSON_AddNumberToObject(root,"DI5", Dev_data.input[4]);
cJSON_AddNumberToObject(root,"DI6", Dev_data.input[5]);
cJSON_AddNumberToObject(root,"DI7", Dev_data.input[6]);
cJSON_AddNumberToObject(root,"DI8", Dev_data.input[7]);
cJSON_AddNumberToObject(root,"DI9", Dev_data.input[8]);
cJSON_AddNumberToObject(root,"DI10", Dev_data.input[9]);
cJSON_AddNumberToObject(root,"DI11", Dev_data.input[10]);
cJSON_AddNumberToObject(root,"DI12", Dev_data.input[11]);
cJSON_AddNumberToObject(root,"DI13", Dev_data.input[12]);
cJSON_AddNumberToObject(root,"DI14", Dev_data.input[13]);
cJSON_AddNumberToObject(root,"DI15", Dev_data.input[14]);
cJSON_AddNumberToObject(root,"DI16", Dev_data.input[15]);
char *s = cJSON_PrintUnformatted(root);
int size=strlen(s)+1;
memcpy(Dev_data.json_string,s,size);
cJSON_Delete(root);
myfree(s);
}