我试图将包含int,char和char数组的结构的成员复制到字节数组中以发送到串行线.到目前为止我有
struct msg_on_send
{
char descriptor_msg[5];
int address;
char space;
char cmdmsg[5];
char CR;
char LF;
};
void switch_output_on()
{
int member;
struct msg_on_send SendMsg_on[sizeof member] =
{
};
unsigned char buffer [ sizeof SendMsg_on[0] ];
showbytes(buffer, serialize(buffer, SendMsg_on));
}
/***************************************************************************
* Function: ArrayBuild *
* Purpose: Uses memcopy to transfer the struct members sequentially *
* into an array of char *
* Arguments: *
* Returns: size_t i = a count of the number of bytes in the …Run Code Online (Sandbox Code Playgroud) 我试图将C中的整数转换为包含该数字的每个数字的数组
即如果我有
int number = 5400
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
int numberArray[4]
Run Code Online (Sandbox Code Playgroud)
哪里
numberArray[0] = 0;
numberArray[1] = 0;
numberArray[2] = 4;
numberArray[3] = 5;
Run Code Online (Sandbox Code Playgroud)
任何建议都感激不尽.
我开发了一个嵌入式应用程序,它通过通信通道从设备请求状态信息.我的客户要求这些将在特定的时间段内发送,所以我要找的是PC终端应用程序,它可以在一段时间内以设定的间隔重复发送文本字符串命令.我目前使用的是串行设备测试仪,可以在发送内容时立即发回设置字符串,但我需要控制时间段和重复次数.
是否有任何应用程序(对于Windows)可以实现这一点?
在我的应用程序中,我定义了一个char数组,它可以采用以下三个选项之一:"okay","high","low",然后从串行端口发送到远程设备.我目前的数组大小可以取4个字符加上回车和换行,但是当我必须发送"低"字符时,我会在字符串中得到一个空字符,我担心这会混淆主机终端.
数组定义
char mod1_status_char[6] = {'0','0','0','0','0','0'};
char mod2_status_char[6] = {'0','0','0','0','0','0'};
char mod3_status_char[6] = {'0','0','0','0','0','0'};
Run Code Online (Sandbox Code Playgroud)
开关案例陈述样本:
void DCOKStatus(uint8_t *ptr_status)
{
uint8_t status = *ptr_status;
switch (status)
{
case 0x00:
strcpy(mod1_status_char, "okay");
strcpy(mod2_status_char, "okay");
strcpy(mod3_status_char, "okay");
break;
case 0x10:
strcpy(mod1_status_char, "okay");
strcpy(mod2_status_char, "okay");
strcpy(mod3_status_char, "low");
break;
}
Run Code Online (Sandbox Code Playgroud)
这是使消息字符串发送的结构
strcpy(MsgStatus_on.descriptor_msg, "$psu_");
MsgStatus_on.address01 = hex_addr[0];
MsgStatus_on.address02 = hex_addr[1];
MsgStatus_on.space01 = 0x20;
strcpy(MsgStatus_on.cmdmsg01, "op_en op1_");
strcpy(MsgStatus_on.statusmsg01, mod1_status_char);
MsgStatus_on.space02 = 0x20;
strcpy(MsgStatus_on.cmdmsg02, "op2_");
strcpy(MsgStatus_on.statusmsg02, mod2_status_char);
MsgStatus_on.space03 = 0x20;
strcpy(MsgStatus_on.cmdmsg03, "op3_");
strcpy(MsgStatus_on.statusmsg03, mod3_status_char);
MsgStatus_on.CR = 0x0D;
MsgStatus_on.LF …Run Code Online (Sandbox Code Playgroud)