📄 modbustxd.c
字号:
/*********************************************************************
* FileName : modbustxd.c
* Author : Jack Zhang
* Date : 06/6/2008
*********************************************************************/
#include <psos.h>
#include <custom_defs.h>
#include <tmInterrupts.h>
#include <AppModel.h>
#include <stdio.h>
#include <string.h>
#include <tmNxTypes.h>
#include <tmDbg.h>
#include <tmosal.h>
#include <dprintf.h>
#include <tmbslCore.h>
#include <tmosal.h>
#include "modbus.h"
#include "uart_local.h"
#include "uart.h"
//------------------------------
void error_send(int,unsigned char*,char); //发送错误信息
void ok_send(int,unsigned char*,char); //成功发送函数
extern unsigned char lrc8(unsigned char *,unsigned short);
//--------------------函数声明---------------------------
//---------------------------------------------------
//----------------数据发送--------------------------------
void mod_send(unsigned char* str_send,char c)
{
uint8 i,len,crc16_s;
unsigned char lrc_s,lrchi,lrclow,crchi,crclow;
unsigned char* pstr=str_send;
rs485SetTx(True);
do
{
ModSendChar(2,*pstr);
pstr++;
}while(pstr==NULL);
len =pstr-str_send;
pstr =str_send;
if('a' ==c)
{
lrc_s =lrc8(pstr,len);
lrchi =(lrc_s&0xf0)>>4;
lrclow =(lrc_s&0x0f);
lrc_s =(lrclow<<4)|lrchi;
ModSendChar(2,lrc_s);
}
if('r' ==c)
{
crc16_s =crc16(pstr,len);
crchi =(crc16_s&0xf0)>>4;
crclow =(crc16_s&0x0f);
crc16_s =(crclow<<4)|crchi;
ModSendChar(2,crc16_s);
}
ModSendChar(2,0x0d);
ModSendChar(2,0x0a);
SetExtSerialDev(2);
}
//----------------------------------------------------
//-------------发送通信信息---------------------------
void ok_send(int addr,unsigned char* str,char ch)
{
if('a' ==ch)
{
str[1] =(addr&0xf0)>>4;
str[2] =addr&0x0f;
}
else if('r' ==ch)
{
str[0] =addr;
}
mod_send(str,ch);
}
//---------------------------------------------------
//------------------发送错误信息---------------------
void error_send(int addr,unsigned char* str,char ch)
{
if('a' ==ch)
{
str[1] =(addr&0xf0)>>4;
str[2] =addr&0x0f;
str[3] =str[3]|1000;
}
else if('r' ==ch)
{
str[0] =addr;
str[1] =str[1]|10000000;
}
mod_send(str,ch);
}
//---------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -