You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.4 KiB
165 lines
4.4 KiB
|
10 months ago
|
/*
|
||
|
|
* msp_DAM0404D.c
|
||
|
|
*
|
||
|
|
* Created on: Nov 22, 2024
|
||
|
|
* Author: akeguo
|
||
|
|
*/
|
||
|
|
#include "msp_DAM0404D.h"
|
||
|
|
#include "BHBF_ROBOT.h"
|
||
|
|
#include "bsp_MB_host.h"
|
||
|
|
|
||
|
|
void MB_WriteNumsCoilWithOneByte(uint8_t *Tx_Buf, uint8_t *TxCount_t, uint8_t _addr,
|
||
|
|
uint16_t _reg, uint16_t _num, uint8_t _databuf);
|
||
|
|
|
||
|
|
int32_t* DMA_DAM0404D_Output_Value[4];
|
||
|
|
void decode_DAM(uint8_t *buffer, uint16_t length);
|
||
|
|
void DAM_0_Set();
|
||
|
|
void DAM_1_Set();
|
||
|
|
void DAM_2_Set();
|
||
|
|
void DAM_3_Set();
|
||
|
|
void DAM040D_Set_ALL();
|
||
|
|
|
||
|
|
struct UARTHandler *DAM0404D_Relay;
|
||
|
|
|
||
|
|
DispacherController *DAM0404D_Relay_dispacherController;
|
||
|
|
void DAM0404D_Relay_intialize(struct UARTHandler *Handler)
|
||
|
|
{
|
||
|
|
//uartHandler_intialize(&Force_sensor,Handler,10);
|
||
|
|
DAM0404D_Relay = Handler;
|
||
|
|
DAM0404D_Relay->UART_Decode = decode040D_DAM;
|
||
|
|
DAM0404D_Relay->Wait_time = 6; //等待10ms 最低不要低于4;
|
||
|
|
DAM0404D_Relay_dispacherController = Handler->dispacherController;
|
||
|
|
DAM0404D_Relay_dispacherController->DispacherCallTime = 100; //10 是100ms 难道这个2ms的定时器是10ms的?
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// DAM0404D_Relay_dispacherController->Add_Dispatcher_List(
|
||
|
|
// DAM0404D_Relay_dispacherController, DAM040D_0_Set);
|
||
|
|
// DAM0404D_Relay_dispacherController->Add_Dispatcher_List(
|
||
|
|
// DAM0404D_Relay_dispacherController, DAM040D_1_Set);
|
||
|
|
// DAM0404D_Relay_dispacherController->Add_Dispatcher_List(
|
||
|
|
// DAM0404D_Relay_dispacherController, DAM040D_2_Set);
|
||
|
|
// DAM0404D_Relay_dispacherController->Add_Dispatcher_List(
|
||
|
|
// DAM0404D_Relay_dispacherController, DAM040D_3_Set);
|
||
|
|
DAM0404D_Relay_dispacherController->Add_Dispatcher_List(
|
||
|
|
DAM0404D_Relay_dispacherController, DAM040D_Set_ALL);
|
||
|
|
HardWareErrorController->Add_PCOMHardWare(HardWareErrorController, "DAM040D",
|
||
|
|
0,DAM040D_Relay_ErrorBitFlag);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void DAM040D_0_Set()
|
||
|
|
{
|
||
|
|
if (*DMA_DAM0404D_Output_Value[0] == 1)
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
0, 1);
|
||
|
|
} else
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
0, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
DAM0404D_Relay->UART_Tx(DAM0404D_Relay); //send the data from the modbus command;
|
||
|
|
|
||
|
|
}
|
||
|
|
void DAM040D_1_Set()
|
||
|
|
{
|
||
|
|
if (*DMA_DAM0404D_Output_Value[1] == 1)
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
1, 1);
|
||
|
|
|
||
|
|
} else
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
1, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
DAM0404D_Relay->UART_Tx(DAM0404D_Relay); //send the data from the modbus command;
|
||
|
|
|
||
|
|
}
|
||
|
|
void DAM040D_2_Set()
|
||
|
|
{
|
||
|
|
if (*DMA_DAM0404D_Output_Value[2] == 1)
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
2, 1);
|
||
|
|
} else
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
2, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
DAM0404D_Relay->UART_Tx(DAM0404D_Relay); //send the data from the modbus command;
|
||
|
|
|
||
|
|
}
|
||
|
|
void DAM040D_3_Set()
|
||
|
|
{
|
||
|
|
if (*DMA_DAM0404D_Output_Value[3] == 1)
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
3, 1);
|
||
|
|
} else
|
||
|
|
{
|
||
|
|
MB_WriteCoil(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
3, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
DAM0404D_Relay->UART_Tx(DAM0404D_Relay); //send the data from the modbus command;
|
||
|
|
|
||
|
|
}
|
||
|
|
uint8_t sendbufCoils=0;
|
||
|
|
void DAM040D_Set_ALL()
|
||
|
|
{
|
||
|
|
for(int i=0;i<4;i++)
|
||
|
|
{
|
||
|
|
sendbufCoils|=(((uint8_t)*DMA_DAM0404D_Output_Value[i])<<i);
|
||
|
|
}
|
||
|
|
MB_WriteNumsCoilWithOneByte(DAM0404D_Relay->Tx_Buf, DAM0404D_Relay->TxCount, 0xfe,
|
||
|
|
0, 4, sendbufCoils);
|
||
|
|
|
||
|
|
DAM0404D_Relay->UART_Tx(DAM0404D_Relay); //send the data from the modbus command;
|
||
|
|
|
||
|
|
}
|
||
|
|
void decode040D_DAM(uint8_t *buffer, uint16_t length)
|
||
|
|
{
|
||
|
|
/* CRC 校验 */
|
||
|
|
uint16_t crc_check = ((buffer[length - 1] << 8) | buffer[length - 2]);
|
||
|
|
/* CRC 校验正确 */
|
||
|
|
if (crc_check == MB_CRC16(buffer, length - 2))
|
||
|
|
{
|
||
|
|
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,"DAM040D",1);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void MB_WriteNumsCoilWithOneByte(uint8_t *Tx_Buf, uint8_t *TxCount_t, uint8_t _addr,
|
||
|
|
uint16_t _reg, uint16_t _num, uint8_t _databuf)
|
||
|
|
{
|
||
|
|
uint16_t TxCount = 0;
|
||
|
|
uint16_t crc = 0;
|
||
|
|
Tx_Buf[TxCount++] = _addr; /* 从站地址 */
|
||
|
|
Tx_Buf[TxCount++] = 0x0F; /* 功能码 */
|
||
|
|
Tx_Buf[TxCount++] = _reg >> 8; /* 寄存器地址 高字节 */
|
||
|
|
Tx_Buf[TxCount++] = _reg; /* 寄存器地址 低字节 */
|
||
|
|
Tx_Buf[TxCount++] = _num >> 8; /* 寄存器(16bits)个数 高字节 */
|
||
|
|
Tx_Buf[TxCount++] = _num; /* 低字节 */
|
||
|
|
Tx_Buf[TxCount++] = 1;
|
||
|
|
Tx_Buf[TxCount++] = _databuf;
|
||
|
|
/* 数据个数 */
|
||
|
|
|
||
|
|
crc = MB_CRC16(Tx_Buf, TxCount);
|
||
|
|
Tx_Buf[TxCount++] = crc; /* crc 低字节 */
|
||
|
|
Tx_Buf[TxCount++] = crc >> 8; /* crc 高字节 */
|
||
|
|
//UART_Tx((uint8_t *)&Tx_Buf,TxCount);
|
||
|
|
*TxCount_t = TxCount;
|
||
|
|
}
|