C#使用NPOI进行Excel导入时ICSharpCode.SharpZipLib版本冲突

错误描述

程序中原有 ICSharpCode.SharpZipLib 的版本为1.1.0.145 ,但是NPOI的的依赖版本为0.86.0.518 ,导致使用时版本错误

解决办法

改为引用0.86.0.518版本的 ICSharpCode.SharpZipLib ,同时非常重要的一点,需要更改webconfig中的配置。将<bindingRedirect oldVersion="0.86.0.518" newVersion="1.1.0.145" />修改为<bindingRedirect oldVersion="0.0.0.0-0.86.0.518" newVersion="0.86.0.518" />,错误得以完美解决

以下是一个简单的示例代码,用于在STM32F407上通过软件模拟IO口的IIC通信读取INA260寄存器内的数据: ```c #include "stm32f4xx.h" #define SDA_H GPIO_SetBits(GPIOB, GPIO_Pin_11) #define SDA_L GPIO_ResetBits(GPIOB, GPIO_Pin_11) #define SCL_H GPIO_SetBits(GPIOB, GPIO_Pin_10) #define SCL_L GPIO_ResetBits(GPIOB, GPIO_Pin_10) #define SDA_READ GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) #define INA260_ADDR 0x80 // INA260设备地址 #define CONFIG_REG 0x00 // 配置寄存器地址 #define SHUNT_VOLTAGE_REG 0x01 // 母线电压寄存器地址 void IIC_GPIO_Config(void); void IIC_Start(void); void IIC_Stop(void); void IIC_SendByte(uint8_t Data); uint8_t IIC_ReadByte(void); void INA260_ReadData(void); int main(void) { IIC_GPIO_Config(); INA260_ReadData(); while(1); } void IIC_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); } void IIC_Start(void) { SDA_H; SCL_H; delay_us(5); SDA_L; delay_us(5); SCL_L; } void IIC_Stop(void) { SDA_L; SCL_H; delay_us(5); SDA_H; delay_us(5); } void IIC_SendByte(uint8_t Data) { uint8_t i; for(i = 0; i < 8; i++) { if(Data & 0x80) SDA_H; else SDA_L; SCL_H; delay_us(5); SCL_L; Data <<= 1; } } uint8_t IIC_ReadByte(void) { uint8_t i; uint8_t Data = 0; SDA_H; for(i = 0; i < 8; i++) { Data <<= 1; SCL_H; delay_us(5); if(SDA_READ) Data++; SCL_L; } return Data; } void INA260_ReadData(void) { uint16_t Config_Reg_Val = 0x0187; // 配置寄存器值 uint16_t Shunt_Voltage_Val = 0; uint8_t buf[2] = {0}; // 缓存数组 IIC_Start(); IIC_SendByte(INA260_ADDR); if(IIC_ReadByte() != 0x00) // 确认应答 while(1); IIC_SendByte(CONFIG_REG); // 配置寄存器地址 if(IIC_ReadByte() != 0x00) while(1); IIC_SendByte(Config_Reg_Val >> 8); // 配置寄存器高位 if(IIC_ReadByte() != 0x00) while(1); IIC_SendByte(Config_Reg_Val & 0xff); // 配置寄存器低位 if(IIC_ReadByte() != 0x00) while(1); IIC_Stop(); delay_ms(10); IIC_Start(); IIC_SendByte(INA260_ADDR); if(IIC_ReadByte() != 0x00) while(1); IIC_SendByte(SHUNT_VOLTAGE_REG); // 母线电压寄存器地址 if(IIC_ReadByte() != 0x00) while(1); IIC_Stop(); IIC_Start(); IIC_SendByte(INA260_ADDR | 0x01); if(IIC_ReadByte() != 0x00) while(1); buf[0] = IIC_ReadByte(); buf[1] = IIC_ReadByte(); IIC_Stop(); Shunt_Voltage_Val = (buf[0] << 8) | buf[1]; // 输出母线电压寄存器值 printf("Shunt Voltage Value: %04x\r\n", Shunt_Voltage_Val); } ``` 这个代码的核心部分是`INA260_ReadData()`函数,它用于读取INA260设备的母线电压寄存器值。首先,我们需要向配置寄存器写入配置值,然后等待一段时间,最后读取母线电压寄存器的值。在IIC通信中,我们需要先发送设备地址,并等待设备应答。然后,我们发送寄存器地址,再次等待设备应答。最后,我们读取寄存器的值,再次等待设备应答。读取16位值需要先读取高8位,然后读取低8位,然后将它们组合成一个完整的16位值。 请注意,在此示例中,我们使用GPIOB的第10和11引脚作为IIC总线的SCL和SDA引脚。您需要根据自己的硬件设置更改这些引脚。同时,您还需要自行实现`delay_us()`和`delay_ms()`函数,以便在IIC通信中添加一些延迟。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值