久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4359|回復: 1
打印 上一主題 下一主題
收起左側(cè)

freemodbus-1.5版源碼分享

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:411025 發(fā)表于 2018-10-17 11:57 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
freemodbus-1.5版分享一下


單片機源程序如下:
  1. /*
  2. * FreeModbus Libary: MSP430 Demo Application
  3. * Copyright (C) 2006 Christian Walter <wolti@sil.at>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18. *
  19. * File: $Id: demo.c,v 1.3 2006/11/19 15:22:40 wolti Exp $
  20. */

  21. /* ----------------------- Platform includes --------------------------------*/
  22. #include "port.h"
  23. #include "dco.h"

  24. /* ----------------------- Modbus includes ----------------------------------*/
  25. #include "mb.h"
  26. #include "mbport.h"

  27. /* ----------------------- Defines ------------------------------------------*/
  28. #define REG_INPUT_START   1000
  29. #define REG_INPUT_NREGS   4
  30. #define REG_HOLDING_START 1000
  31. #define REG_HOLDING_NREGS 130

  32. /* ----------------------- Static variables ---------------------------------*/
  33. static USHORT   usRegInputStart = REG_INPUT_START;
  34. static USHORT   usRegInputBuf[REG_INPUT_NREGS];
  35. static USHORT   usRegHoldingStart = REG_HOLDING_START;
  36. static USHORT   usRegHoldingBuf[REG_HOLDING_NREGS];

  37. /* ----------------------- Start implementation -----------------------------*/
  38. int
  39. main( void )
  40. {
  41.     eMBErrorCode    eStatus;
  42.     volatile USHORT usACLKCnt;

  43.     /* Stop Watchdog Timer. */
  44.     WDTCTL = WDTPW + WDTHOLD;

  45.     /* Delay for ACLK startup. */
  46.     for( usACLKCnt = 0xFFFF; usACLKCnt != 0; usACLKCnt-- );
  47.     if( cTISetDCO( TI_DCO_4MHZ ) == TI_DCO_NO_ERROR )
  48.     {
  49.         _EINT(  );

  50.         /* Initialize Protocol Stack. */
  51.         if( ( eStatus = eMBInit( MB_RTU, 0x0A, 0, 38400, MB_PAR_EVEN ) ) != MB_ENOERR )
  52.         {
  53.         }
  54.         /* Enable the Modbus Protocol Stack. */
  55.         else if( ( eStatus = eMBEnable(  ) ) != MB_ENOERR )
  56.         {
  57.         }
  58.         else
  59.         {
  60.             for( ;; )
  61.             {
  62.                 ( void )eMBPoll(  );

  63.                 /* Here we simply count the number of poll cycles. */
  64.                 usRegInputBuf[0]++;
  65.             }
  66.         }
  67.     }
  68.     for( ;; );
  69. }

  70. eMBErrorCode
  71. eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
  72. {
  73.     eMBErrorCode    eStatus = MB_ENOERR;
  74.     int             iRegIndex;

  75.     if( ( usAddress >= REG_INPUT_START )
  76.         && ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
  77.     {
  78.         iRegIndex = ( int )( usAddress - usRegInputStart );
  79.         while( usNRegs > 0 )
  80.         {
  81.             *pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
  82.             *pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
  83.             iRegIndex++;
  84.             usNRegs--;
  85.         }
  86.     }
  87.     else
  88.     {
  89.         eStatus = MB_ENOREG;
  90.     }

  91.     return eStatus;
  92. }

  93. eMBErrorCode
  94. eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
  95. {
  96.     eMBErrorCode    eStatus = MB_ENOERR;
  97.     int             iRegIndex;

  98.     if( ( usAddress >= REG_HOLDING_START ) &&
  99.         ( usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS ) )
  100.     {
  101.         iRegIndex = ( int )( usAddress - usRegHoldingStart );
  102.         switch ( eMode )
  103.         {
  104.             /* Pass current register values to the protocol stack. */
  105.         case MB_REG_READ:
  106.             while( usNRegs > 0 )
  107.             {
  108.                 *pucRegBuffer++ = ( unsigned char )( usRegHoldingBuf[iRegIndex] >> 8 );
  109.                 *pucRegBuffer++ = ( unsigned char )( usRegHoldingBuf[iRegIndex] & 0xFF );
  110.                 iRegIndex++;
  111.                 usNRegs--;
  112.             }
  113.             break;

  114.             /* Update current register values with new values from the
  115.              * protocol stack. */
  116.         case MB_REG_WRITE:
  117.             while( usNRegs > 0 )
  118.             {
  119.                 usRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
  120.                 usRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
  121.                 iRegIndex++;
  122.                 usNRegs--;
  123.             }
  124.         }
  125. ……………………

  126. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
freemodbus-v1.5官網(wǎng)支持stm32.zip (4.16 MB, 下載次數(shù): 143)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:302850 發(fā)表于 2020-4-21 19:05 | 只看該作者
感謝分享,很棒
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产96在线 | 一级a爱片久久毛片 | 久久国产免费看 | 日韩一区中文字幕 | 亚洲天天干 | 精品国产99 | 国产精品视频网 | 国产福利在线播放 | 国产日韩中文字幕 | 日本不卡一区 | 日本黄色激情视频 | 99久久婷婷国产综合精品 | 韩日一区二区三区 | 99久久精品免费看国产四区 | 完全免费av在线 | 一区二区三区av夏目彩春 | 亚洲免费视频网址 | 久久免费看 | 中国大陆高清aⅴ毛片 | 欧美激情在线观看一区二区三区 | 成人精品视频在线观看 | 成人美女免费网站视频 | 亚洲第一区久久 | 精品国产一区久久 | 视频在线一区二区 | 狠狠爱免费视频 | 欧美日韩在线国产 | 午夜视频网站 | 涩涩视频在线观看 | 亚洲国产成人精品女人久久久 | 亚洲高清视频在线 | 久久99国产精品 | 538在线精品| 久草资源 | 成人小视频在线观看 | 在线视频 亚洲 | 久草在线免费资源 | 亚洲国产精品久久久 | 91久久久久久久久久久久久 | 亚洲精品乱码 | 成人激情免费视频 |