• 大小: 4.4MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-19
  • 语言: 其他
  • 标签: FreeMo  RTU  Mo  ASCII  

资源简介

Read Input Register (0x04) Read Holding Registers (0x03) Write Single Register (0x06) Write Multiple Registers (0x10) Read/Write Multiple Registers (0x17) Read Coils (0x01) Write Single Coil (0x05) Write Multiple Coils (0x0F) Read Discrete Inputs (0x02) Report Slave ID (0x11)

资源截图

代码片段和文件信息

/*
 * FreeModbus Libary: ARM7 Demo Application
 * Copyright (C) 2006 Christian Walter 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not write to the Free Software
 * Foundation Inc. 51 Franklin St Fifth Floor Boston MA  02110-1301  USA
 *
 * File: $Id$
 */

/* ----------------------- System includes ----------------------------------*/
#include “assert.h“

/* ----------------------- Platform includes --------------------------------*/
#include “support/AT91SAM7X256.h“
#include “support/lib_AT91SAM7X256.h“

#include “FreeRTOS.h“
#include “task.h“
#include “queue.h“

/* ----------------------- Modbus includes ----------------------------------*/
#include “mb.h“

/* ----------------------- Defines ------------------------------------------*/
#define REG_HOLDING_START           0x1000
#define REG_HOLDING_NREGS           130
#define REG_INPUT_START             0x1000
#define REG_INPUT_NREGS             4

/* ----------------------- Static variables ---------------------------------*/
static USHORT   usRegHoldingStart = REG_HOLDING_START;
static USHORT   usRegHoldingBuf[REG_HOLDING_NREGS];
static USHORT   usRegInputStart = REG_INPUT_START;
static USHORT   usRegInputBuf[REG_INPUT_NREGS];

/* ----------------------- Static functions ---------------------------------*/
STATIC void     vModbusTask( void *pvParameters );
STATIC void     vSetupHardware( void );

/* ----------------------- Start implementation -----------------------------*/
int
main( void )
{
    vSetupHardware(  );

    ( void )xTaskCreate( vModbusTask NULL configMINIMAL_STACK_SIZE NULL
                         tskIDLE_PRIORITY NULL );

    vTaskStartScheduler(  );
    return 0;
}

static void
vModbusTask( void *pvParameters )
{
    int             i;

    /* Select either ASCII or RTU Mode. */
    ( void )eMBInit( MB_RTU 0x0A 0 38400 MB_PAR_EVEN );

    /* Initialize the holding register values before starting the
     * Modbus stack
     */
    for( i = 0; i < REG_HOLDING_NREGS; i++ )
    {
        usRegHoldingBuf[i] = ( unsigned short )i;
    }
    /* Initialize the input register values before starting the
     * Modbus stack
     */
    for( i = 0; i < REG_INPUT_NREGS; i++ )
    {
        usRegInputBuf[i] = ( unsigned short )i;
    }

    /* Enable the Modbus Protocol Stack. */
    ( void )eMBEnable(  );
    for( ;; )

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-10 15:31  freemodbus-v1.6\
     文件        1436  2018-09-14 04:03  freemodbus-v1.6\bsd.txt
     文件       14628  2018-09-14 04:03  freemodbus-v1.6\Changelog.txt
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\
     文件        5634  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\demo.c
     文件        8756  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\demo.hzp
     文件       12695  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\demo.hzs
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\
     文件       13219  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\croutine.c
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\
     文件       26826  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\croutine.h
     文件        4984  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\FreeRTOS.h
     文件       11470  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\list.h
     文件        2988  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\portable.h
     文件        2979  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\portable.h.bak
     文件        2209  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\projdefs.h
     文件       16551  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\queue.h
     文件       10062  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\semphr.h
     文件       31687  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\include\task.h
     文件        7614  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\list.c
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\GCC\
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\GCC\ARM7_AT91SAM7S\
     文件        7975  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\GCC\ARM7_AT91SAM7S\port.c
     文件        8771  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\GCC\ARM7_AT91SAM7S\portISR.c
     文件       13238  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\GCC\ARM7_AT91SAM7S\portmacro.h
     目录           0  2019-03-10 15:30  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\MemMang\
     文件        4589  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\MemMang\heap_1.c
     文件        9068  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\MemMang\heap_2.c
     文件        2547  2018-09-14 04:03  freemodbus-v1.6\demo\AT91SAM7X_ROWLEY\FreeRTOS\portable\MemMang\heap_3.c
............此处省略1301个文件信息

评论

共有 条评论