.NET/Rotor源码研究1补遗 - 解决无法检测操作系统版本的错误

本文解决在编译Rotor过程中遇到的无法检测操作系统版本的问题。通过修改env.core.pl脚本来确保正确识别非英文版Windows的版本信息。
2007年10月21日 20:46:00
最近不少朋友反映在编译Rotor 的时候出现无法检测操作系统版本的错误,具体现象为执行env.bat 的时候报错:

Could not get platform OS version

出现该错误的原因是env.bat 会调用env.core.pl 设置环境,而env.core.pl 在检测操作系统版本的时候会使用到ver 命令的输出结果:

if (Windows()) {

# The output of ver looks like:

#

# Microsoft Windows XP [Version 5.1.2600]

#

# (including the empty line before)

$platform_os_version = `ver`;

# we keep the first two fields of the version number

if (! ($platform_os_version =~ s//nMicrosoft.*/[Version +([0-9]+/.[0-9]+)/..*/]/$1/g)) {

$platform_os_version = "";

}

if ($platform_os_version =~ /^5/..*/) {

$platform_os_version = "5.1";

}
} else {

$platform_os_version = `uname -r`;

# we keep all fields of the version number

if (! ($platform_os_version =~ s/^[^0-9]*([0-9.]+).*$/$1/s)) {

$platform_os_version = "";

}
}

chomp ($platform_os);

chomp ($platform_os_version);

if (! $platform_os_version ) {

CorFail ("Could not get platform OS version");

}

可以看到env.core.pl使用正则表达式s//nMicrosoft.*/[Version +([0-9]+/.[0-9]+)/..*/]/$1/g来分析Ver的输出结果。如果操作系统为非中文版本或者安装了界面包的情况下,ver命令便有可能输出中文结果,导致脚本出错。虽然可以通过修改系统Locale的方式解决,不过更简单的解决方法显然是直接修改脚本,把$platform_version固定为某个值,比如5.1,修改后代码如下:

if (Windows()) {

# assume 5.1 version because the original code cannot parse the output of ver command correctly in non-English OS

$platform_os_version = "5.1";

} else {

$platform_os_version = `uname -r`;

# we keep all fields of the version number

if (! ($platform_os_version =~ s/^[^0-9]*([0-9.]+).*$/$1/s)) {

$platform_os_version = "";

}
}

chomp ($platform_os);

chomp ($platform_os_version);

if (! $platform_os_version ) {

CorFail ("Could not get platform OS version");

}

这里有一个已经修改好的env.core.pl (放在我的Windows Live Skydrive账户里面),有需要的朋友可以点击下载,然后覆盖SSCLI20目录下的env.core.pl即可。

作者: 张羿(ATField)
Blog: http://blog.youkuaiyun.com/atfield
http://blogs.msdn.com/yizhang
转载请注明出处



Trackback: http://tb.blog.youkuaiyun.com/TrackBack.aspx?PostId=1836028


/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6000000) #error "不支持使用 Keil ARM Compiler V5编译器 请使用 Keil ARM Compiler V6编译" #endif /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "adc.h" #include "dma.h" #include "spi.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include <stdio.h> #include "motor/motor_runtime_param.h" #include "motor/foc.h" #include "global_def.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ void set_pwm_duty(float d_u, float d_v, float d_w) { d_u = min(d_u, 0.9); // 留出10%的电流采样时间 d_v = min(d_v, 0.9); d_w = min(d_w, 0.9); __disable_irq(); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, d_u * htim1.Instance->ARR); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, d_v * htim1.Instance->ARR); __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, d_w * htim1.Instance->ARR); __enable_irq(); } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_SPI1_Init(); MX_USART2_UART_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_ADC1_Init(); MX_ADC2_Init(); /* USER CODE BEGIN 2 */ set_motor_pid( 3.5, 0, 7, 0.02, 0.001, 0, 1.2, 0.02, 0, 1.2, 0.02, 0); extern uint8_t mt6701_rx_data[3]; HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // 磁编码器mt6701 SPI的片选引脚 HAL_SPI_TransmitReceive_DMA(&hspi1, mt6701_rx_data, mt6701_rx_data, 3); HAL_Delay(10); // 延时一会,让角度变量被赋值,不然默认角度是0 HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3); HAL_TIM_Base_Start_IT(&htim3); HAL_ADCEx_Calibration_Start(&hadc1); HAL_ADCEx_Calibration_Start(&hadc2); HAL_ADCEx_InjectedStart_IT(&hadc1); HAL_ADCEx_InjectedStart(&hadc2); encoder_init_angle = encoder_angle; set_pwm_duty(0.5, 0, 0); // d轴强拖,形成SVPWM模型中的基础矢量1,即对应转子零度位置 HAL_Delay(400); // 保持一会 rotor_zero_angle = encoder_angle; set_pwm_duty(0, 0, 0); // 松开电机 HAL_Delay(100); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ // 【电流模式】 motor_control_context.torque_norm_d = 0; motor_control_context.torque_norm_q = 0.4; // 百分比强度 motor_control_context.type = control_type_torque; HAL_Delay(1000); // 【位置(角度)模式】 motor_control_context.position = deg2rad(90); // 上电时的角度当作0度 // motor_control_context.position = deg2rad(90) - encoder_init_angle; // 编码器零位当作0度 motor_control_context.type = control_type_position; // 【速度模式】 // motor_control_context.speed = 30; //每秒转30弧度 // motor_control_context.type = control_type_speed; // 理论讲解以及FOC代码逐步实现讲解请前往查看:https://blog.csdn.net/qq570437459/category_12672491.html while (1) { printf("%.3f\n", rad2deg(motor_logic_angle)); HAL_Delay(100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); HAL_Delay(100); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ 什么意思,请帮我翻译
最新发布
08-24
在STM32嵌入式开发中,C语言代码通常涉及底层硬件操作,例如外设初始化、中断处理、GPIO控制等。为了帮助理解代码功能,代码中通常会包含注释,以说明关键函数的作用、寄存器配置逻辑或特定模块的用途。以下是对典型STM32 C代码中注释和关键函数的解释与翻译。 ### 示例代码片段 ```c #include "stm32l4xx_hal.h" // 初始化LED GPIO void LED_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; // 使能GPIOA时钟 __HAL_RCC_GPIOA_CLK_ENABLE(); // 配置PA5为推挽输出模式 GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } // 主循环中调用此函数以翻转LED状态 void Toggle_LED(void) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(500); // 延迟500毫秒 } ``` ### 代码解释与注释翻译 1. `#include "stm32l4xx_hal.h"` 引入STM32L4系列的HAL(硬件抽象层)库头文件,该库提供了封装好的外设驱动函数,简化了寄存器操作[^1]。 2. `// 初始化LED GPIO` 表示接下来的函数用于初始化LED所连接的GPIO引脚。 3. `void LED_Init(void)` 定义一个无返回值的函数`LED_Init`,用于配置LED所连接的GPIO端口。 4. `GPIO_InitTypeDef GPIO_InitStruct = {0};` 声明一个`GPIO_InitTypeDef`结构体变量`GPIO_InitStruct`,用于存储GPIO配置参数,如引脚号、模式、速度等[^2]。 5. `__HAL_RCC_GPIOA_CLK_ENABLE();` 使能GPIOA的时钟。在STM32中,所有外设在使用前必须先开启对应的时钟,否则无法访问其寄存器[^2]。 6. `GPIO_InitStruct.Pin = GPIO_PIN_5;` 设置GPIO引脚为PA5,即LED连接的物理引脚。 7. `GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;` 设置GPIO模式为推挽输出(Push-Pull),适用于驱动LED等负载。 8. `GPIO_InitStruct.Pull = GPIO_NOPULL;` 设置无上拉或下拉电阻,引脚电平由外部电路决定。 9. `GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;` 设置GPIO引脚的输出速度为低频模式,适用于低速信号(如LED控制)。 10. `HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);` 调用HAL库函数`HAL_GPIO_Init`,将配置写入GPIOA寄存器,完成初始化[^1]。 11. `void Toggle_LED(void)` 定义一个函数`Toggle_LED`,用于在主循环中切换LED状态。 12. `HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);` 调用HAL库函数`HAL_GPIO_TogglePin`,翻转PA5引脚的高低电平,实现LED闪烁效果。 13. `HAL_Delay(500);` 调用HAL库函数`HAL_Delay`,延时500毫秒。该函数基于系统滴答定时器(SysTick),用于实现简单的延时操作[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值