Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
发送一个类似“quot;111"013";用python_Python_C - Fatal编程技术网

发送一个类似“quot;111"013";用python

发送一个类似“quot;111"013";用python,python,c,Python,C,我已经用c语言为我的微控制器编写了一个代码,它的工作方式是,当我使用HW group的Hercules 3.2.8应用程序发送一个111#013时,我板上的一个led亮起,但我不知道如何使用python发送相同的东西我的代码如下: import tkinter as tk import serial port=serial.Serial(port='COM3',baudrate=115200,timeout=0) def led1_on(): port.write("111&q

我已经用c语言为我的微控制器编写了一个代码,它的工作方式是,当我使用HW group的Hercules 3.2.8应用程序发送一个111#013时,我板上的一个led亮起,但我不知道如何使用python发送相同的东西我的代码如下:

import tkinter as tk
import serial
port=serial.Serial(port='COM3',baudrate=115200,timeout=0)
def led1_on():
    port.write("111".encode(encoding="ascii"))
    print("111".encode(encoding="ascii"))
    port.write(13)
之后,当我调用led1_on()时,它就不起作用了 说明:“111#013”表示它发送一个字符串111,然后是数字13,C代码使用uart

这是c代码

int i=0,j=0,k=100,len=0;
float v;
char buffer[100];
char Tem[32];
char Rx_data[2],Rx_indx,Rx_Buffer[100],Transfer_cplt;
"

void图表点(char*str)
{
j=0;
而(*str!=0)
{
如果(*str='0')
{j=j*10+(*str-'0');}
str++;
}
}
无效HAL_UART_RxCpltCallback(UART_HandletTypeDef*huart)
{
uint8_t i;
如果(huart->Instance==USART1)
{
图表点(缓冲区);
如果(Rx_indx==0)

{for(i=0;i)什么是“111#013”?什么字节序列代表它?很难猜测C代码的确切功能。我们也能看到吗?你能澄清你的问题吗?你似乎已经发送了
“111”
13
,为什么不发送中间的
“0”
同样?PySerial只能发送字节–字符串
“111”
和数字
13
。您的C程序需要什么字节?必须
“111”
进行ASCII编码(即
char[3]
),
13
应该是有符号的还是无符号的,大小是多少?
\013
可能指CR(
“000\x0D”
)什么是“111#013”?什么字节序列代表它?很难猜测C代码的确切功能。我们也能看到吗?你能澄清你的问题吗?你似乎已经发送了
“111”
13
,为什么不发送中间
“\0”
同样?PySerial只能发送字节–字符串
“111”
和数字
13
。您的C程序需要什么字节?必须
“111”
进行ASCII编码(即
char[3]
),
13
应该是有符号的还是无符号的,大小是多少?
\013
可能指CR(
“000\x0D”
void chartoint(char *str)
{
  j=0;
  while (*str != 0)
  {
    if(*str <= '9' && *str >= '0')
    {j = j*10+(*str - '0');}
    str++;
  }
}

void HAL_UART_RxCpltCallback (UART_HandleTypeDef *huart)
{
  uint8_t i;
  if(huart->Instance==USART1)
  {
    chartoint(buffer);
    
    if(Rx_indx==0)
    {for(i=0;i<100;i++)
      Rx_Buffer[i]=0;}
    if(Rx_data[0]!=13)
    {Rx_Buffer[Rx_indx++]=Rx_data[0];}
    else
    {Rx_indx=0;
    Transfer_cplt=1;}
    HAL_UART_Receive_IT(&huart1,Rx_data,1);
  }
}
if(Transfer_cplt)
{
  sprintf(buffer,"%s\r\n",Rx_Buffer);
  chartoint(buffer);
  //LED on-off
  if(j == 103)
    HAL_GPIO_WritePin(GPIOC,1<<8,GPIO_PIN_RESET);
  if(j == 113)
    HAL_GPIO_WritePin(GPIOC,1<<8,GPIO_PIN_SET);
  if(j == 102)
    HAL_GPIO_WritePin(GPIOC,1<<7,GPIO_PIN_RESET);
  if(j == 112)
    HAL_GPIO_WritePin(GPIOC,1<<7,GPIO_PIN_SET);
  if(j == 101)
    HAL_GPIO_WritePin(GPIOB,1<<15,GPIO_PIN_RESET);
  if(j == 111)
    HAL_GPIO_WritePin(GPIOB,1<<15,GPIO_PIN_SET);
  //LED on-off
  if(j<=100)
    k=j*2;
  Transfer_cplt=0;
}