📄 commrs485.c
字号:
CommSendByteWithChk(CommCid); //CID 07
CommSendWordWithChk(0xA006); //LENTH
CommSendByteWithChk(0x01); //
CommSendWordWithChk(0x0000); //写系数错误
ComCalculChkSum = (~ComCalculChkSum)+1;
CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
CommSendByteWithoutChk((uint8)(ComCalculChkSum));
Suart_Send_Byte(0x0D);
}
/********************************************************************************************************
** 函数名称: void Comm_rs485_handshake(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Comm_rs485_handshake(void)
{
Suart_Send_Byte(0x7E); //报文头
ComCalculChkSum = 0;
CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
CommSendByteWithChk(CommCid); //CID 01
CommSendWordWithChk(0xA006); //LENTH
CommSendByteWithChk(0x01); //
CommSendWordWithChk(0x55AA);
ComCalculChkSum = (~ComCalculChkSum)+1;
CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
CommSendByteWithoutChk((uint8)(ComCalculChkSum));
Suart_Send_Byte(0x0D);
}
/********************************************************************************************************
** 函数名称: void Comm_rs485_readanalog(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Comm_rs485_readanalog(void)
{
uint8 i;
Suart_Send_Byte(0x7E); //报文头
ComCalculChkSum = 0;
CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
CommSendByteWithChk(CommCid); //CID 02
CommSendWordWithChk(0xF05C); //LENTH
CommSendByteWithChk(0x01); //
for(i = 0;i < 15;i++) //15只池电电压
{
CommSendWordWithChk(CellVoltage[i]);
}
CommSendByteWithChk(0x02); //
for(i = 0;i < 9;i++) //15只电池温度,1路环境温度
{
CommSendByteWithChk(Temperature[i]);
}
CommSendByteWithChk(0x03);
CommSendWordWithChk(ChargeCurrent); //充电电流
CommSendWordWithChk(DisChargeCurrent); //放电电流
ComCalculChkSum = (~ComCalculChkSum)+1;
CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
CommSendByteWithoutChk((uint8)(ComCalculChkSum));
Suart_Send_Byte(0x0D);
}
/********************************************************************************************************
** 函数名称: void Comm_rs485_read_digital(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Comm_rs485_read_digital(void)
{
Suart_Send_Byte(0x7E); //报文头
ComCalculChkSum = 0;
CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
CommSendByteWithChk(CommCid); //CID 03
CommSendWordWithChk(0x501A); //LENTH
CommSendByteWithChk(0x01); //
CommSendByteWithChk(ComAlarmET ); //综合告警
CommSendByteWithChk(ComAlarmVh0); //1~ 8只电池过压告警
CommSendByteWithChk(ComAlarmVh1); //9~15只电池过压告警
CommSendByteWithChk(ComAlarmVl0); //1~ 8只电池欠压告警
CommSendByteWithChk(ComAlarmVl1); //9~15只电池欠压告警
CommSendByteWithChk(ComAlarmScCTh); //1~15只电池充电过温
CommSendByteWithChk(ComAlarmScCTl); //1~15只电池充电欠温
CommSendByteWithChk(ComAlarmSDcTh); //1~15只电池放电过温
CommSendByteWithChk(ComAlarmSDcTl); //1~15只电池放电欠温
CommSendByteWithChk(ComTemperaSensor ); //1~ 8路温度传感器失效
CommSendByteWithChk(ComVoltageSensor0); //电压传感器失效
ComCalculChkSum = (~ComCalculChkSum)+1;
CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
CommSendByteWithoutChk((uint8)(ComCalculChkSum));
Suart_Send_Byte(0x0D);
}
/********************************************************************************************************
** 函数名称: void Comm_rs232_read_config(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Comm_rs485_read_config(void)
{
uint8 i;
Suart_Send_Byte(0x7E); //报文头
ComCalculChkSum = 0;
CommSendByteWithChk((uint8)(ModeSysConfig[8])); //BoardAddress地址范围0~16
CommSendByteWithChk(CommCid); //CID 05
CommSendWordWithChk(0x9052); //LENTH
CommSendByteWithChk(0x01); //电压限值配置信息
for(i = 0;i < 9;i++)
{
CommSendWordWithChk(ModeSysConfig[i]);
}
CommSendByteWithChk(0x02); //温度限值配置信息
for(i = 0;i < 12;i++)
{
CommSendByteWithChk(ModeTempCofing[i]);
}
CommSendByteWithChk(0x03); //系数
CommSendWordWithChk(CUK);
CommSendWordWithChk(CTK);
CommSendWordWithChk(OTK);
ComCalculChkSum = (~ComCalculChkSum)+1;
CommSendByteWithoutChk((uint8)(ComCalculChkSum>>8));
CommSendByteWithoutChk((uint8)(ComCalculChkSum));
Suart_Send_Byte(0x0D);
}
/********************************************************************************************************
** 函数名称: void Comm_rs485_write_vconfig(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
//void Comm_rs485_write_vconfig(void) //电压限值存储在第一扇区
//{
// uint8 i,c;
// uint16 address;
// c = 0;
// address = 0x2800;
// for(i = 1;i < 17;)
// {
// MoveVXdata[c] = ((CommRxBuf[i] << 8)|CommRxBuf[i+1]);
// i++;
// i++;
// c++;
// }
// EepSectotErase(address);
// for(i = 0;i < 8;i++)
// {
// EepWriteWord(MoveVXdata[i],address);
// address++;
// address++;
// }
// for(i = 0;i < 8;i++) //将修正值赋给动作变量
// {
// ModeSysConfig[i] = EepReadWord(address);
// }
// CommRight();
//}
/********************************************************************************************************
** 函数名称: void Comm_rs485_write_tconfig(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
//void Comm_rs485_write_tconfig(void) //温度限值存储在第二扇区
//{
// uint8 i;
// uint16 address;
// address = 0x2A00;
// for(i = 1;i < 13;i++)
// {
// MoveTdata[i] = CommRxBuf[i];
// }
// EepSectotErase(address);
// for(i = 0;i < 12;i++)
// {
// EepWriteByte(MoveTdata[i],address);
// address++;
// }
// for(i = 0;i < 12;i++) //将修正值赋给动作变量
// {
// ModeTempCofing[i] = EepReadByte(address);
// }
// CommRight();
//}
/********************************************************************************************************
** 函数名称: void Comm_rs485_write_xconfig(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月20日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Comm_rs485_write_xconfig(void) //系数存储在第三扇区
{
uint8 i,c,j;
uint16 address;
c = 0;
j = 0;
address = 0x2C00;
for(i = 1;i < 7;)
{
MoveVXdata[c] = ((CommRxBuf[i] << 8)|CommRxBuf[i+1]);
i++;
i++;
c++;
}
for(i = 0;i < 3;i++)
{
if((MoveVXdata[i] > 6000) && (MoveVXdata[i] < 15000))j++;
}
if(j == 3)
{
j = 0;
EepSectotErase(address);
for(i = 0;i < 3;i++)
{
EepWriteWord(MoveVXdata[i],address);
address++;
address++;
}
CUK = EepReadWord(address);
CTK = EepReadWord(address+2);
OTK = EepReadWord(address+4);
CommRight();
}
else
{
j = 0;
CommWrong();
}
}
/*********************************************************************************************************
** 函数名称: void CommRs485Manage(void)
** 功能描述:
** 输 入: 无
** 输 出: 无
** 全局变量:
** 调用模块:
**
** 作 者: 李伟
** 日 期: 2008年12月10日
**-------------------------------------------------------------------------------------------------------
** 修 改 人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void CommRs485Manage(void)
{
switch(CommCid)
{
case RS232_HAND_SHAKE: //握手命令 1
{
Comm_rs485_handshake();
}break;
case RS232_READ_ANALOG: //读模拟量 2
{
Comm_rs485_readanalog();
}break;
case RS232_READ_DIGITAL: //读数字量 3
{
Comm_rs485_read_digital();
}break;
case RS232_READ_CONFIG: //读配置 4
{
Comm_rs485_read_config();
}break;
case RS232_WRITE_VCONFIG: //电压限值配置 5
{
// Comm_rs485_write_vconfig();
}break;
case RS232_WRITE_TCONFIG: //温度限值配置 6
{
// Comm_rs485_write_tconfig();
}break;
case RS232_WRITE_XCONFIG: //系数配置 7
{
Comm_rs485_write_xconfig();
}break;
default: break;
}
}
/********************************************************************************************************
End of file
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -