找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1316|回复: 0
打印 上一主题 下一主题
收起左侧

8266modbus接收nonos

[复制链接]
跳转到指定楼层
楼主
ID:405603 发表于 2022-11-5 23:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
看了小宋老师的课尝试着写的,抛砖引玉。

#if UART_SELFTEST&UART_BUFF_EN
os_timer_t buff_timer_t;
void ICACHE_FLASH_ATTR
uart_test_rx()
{
    uint8 uart_buf[128]={0};
    uint16 len = 0;
    len = rx_buff_deq(uart_buf, 128 );
    tx_buff_enq(uart_buf,len);
        crc = GetCRC16(uart_buf, len-2);
        crch = crc >> 8;
        crcl = crc & 0xFF;
    char *PA;
    CHAR *PB;

    if(uart_buf[0]=='0' && uart_buf[1]=='1' && uart_buf[2]=='0' && uart_buf[3]=='3')
    { char buf[0]=0x01;
           buf[1]=0x03;
           int cnt;
               memset(CCC,0,sizeof(CCC));
               memset(DDD,0,sizeof(DDD));
               memset(CRCL,0,sizeof(CRCL));
               memset(CRCH,0,sizeof(CRCH));

        uart0_sendStr("modbus读本机状态模式");
            PA=uart_buf;
            PA=PA+4;
            PB=PA+4;
                memcpy(CCC,PA,strlen(PA)-strlen(PB));
                buf[3]=CCC;
                PA=PB;
                PB=PA+4;
                memcpy(DDD,PA,strlen(PA)-strlen(PB));
                buf[4]=DDD;
                cnt=atoi(DDD);
                PA=PB;
                PB=PA=2;
                memcpy(CRCH,PA,strlen(PA)-strlen(PB));
                PA=PB;
                PB=PA=2;
                memcpy(CRCL,PA,strlen(PA)-strlen(PB));
            if ((CRCH!=crch) || (CRCL!=crcl))
            {
                return;

           os_sprintf(buf[2],cnt*2);
           buf[5]=0;//或1,表示某个设备的状态
                   buf=buf[0]+buf[1]+buf[2]+buf[5]+crch+crcl;
                   uart0_sendStr(buf);


    }
    else if(uart_buf[0]=='0' && uart_buf[1]=='1' && uart_buf[2]=='0' && uart_buf[3]=='6')
    {
            uart0_sendStr("modbus写本机状态模式");
    }
}
#endif

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表