В связи с необходимость осваивания модбаза решил начать уже с готовой либы FreeModBus.
Предварительно почитав теорию по работе протокола. Решился все таки скомпилировать демку FreeModBuss, но не тут то было ) она начала меня осыпать разного рода ошибками. Избавился почти от всех остались вот эти:
Код построения:
Код:
------ Построение начато: проект: ProjectFreeModBusSlave, Конфигурация: Debug AVR ------
Построение начато.
Проект "ProjectFreeModBusSlave.cproj" (целевые объекты по умолчанию):
Построение с инструментами версии "2.0".
Целевой объект "PreBuildEvent" пропущен из-за невыполненного условия; выражение ('$(PreBuildEvent)'!='') равно (''!='').
Целевой объект "CoreBuild" в файле "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" из проекта "C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\ProjectFreeModBusSlave.cproj" (целевой объект "Build" зависит от него):
Задача "RunCompilerTask"
Shell Utils Path C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils
C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils\make.exe all
Building file: .././ProjectFreeModBusSlave.c
Invoking: AVR/GNU C Compiler : 4.8.1
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe" -x c -funsigned-char -funsigned-bitfields -DDEBUG -I"../../modbus/include" -I"../../modbus/rtu" -I"../port" -I"../../modbus/functions" -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega16 -c -std=gnu99 -MD -MP -MF "ProjectFreeModBusSlave.d" -MT"ProjectFreeModBusSlave.d" -MT"ProjectFreeModBusSlave.o" -o "ProjectFreeModBusSlave.o" ".././ProjectFreeModBusSlave.c"
.././ProjectFreeModBusSlave.c: In function 'main':
C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\ProjectFreeModBusSlave.c(43,21): warning: variable 'eStatus' set but not used [-Wunused-but-set-variable]
eMBErrorCode eStatus;
^
Finished building: .././ProjectFreeModBusSlave.c
Building target: ProjectFreeModBusSlave.elf
Invoking: AVR/GNU Linker : 4.8.1
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe" -o ProjectFreeModBusSlave.elf ProjectFreeModBusSlave.o -Wl,-Map="ProjectFreeModBusSlave.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega16
ProjectFreeModBusSlave.o: In function `main':
C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\Debug/.././ProjectFreeModBusSlave.c(45,1): error: undefined reference to `eMBInit'
C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\Debug/.././ProjectFreeModBusSlave.c(47,1): error: undefined reference to `eMBSetSlaveID'
C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\Debug/.././ProjectFreeModBusSlave.c(51,1): error: undefined reference to `eMBEnable'
C:\_ATmel\ModBUS\ProjectFreeModBusSlave\ProjectFreeModBusSlave\Debug/.././ProjectFreeModBusSlave.c(55,1): error: undefined reference to `eMBPoll'
collect2.exe(0,0): error: ld returned 1 exit status
make: *** [ProjectFreeModBusSlave.elf] Error 1
Выход из команды с кодом "2".
Выполнение задачи "RunCompilerTask" завершено с ошибкой.
Построение целевого объекта "CoreBuild" в проекте "ProjectFreeModBusSlave.cproj" завершено с ошибкой.
Построение проекта "ProjectFreeModBusSlave.cproj" завершено с ошибкой.
СБОЙ построения.
========== Построение: успешно и без изменений: 0, с ошибками: 1, пропущено: 0 ==========
Инклуды все подключены, и про линкованы.
Небольшой анализ гуугла дал результат что такие ошибки встречаются у людей при компиляции на AtmelStudio, при переходе на WinAvr.
Может кто подскажет в какую сторону копать ?
НА всякий пожарный код под спойлером:
Спойлер
Код:
/*
* FreeModbus Libary: AVR Demo Application
* Copyright (C) 2006 Christian Walter <wolti@sil.at>
*
* 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: demo.c,v 1.7 2006/06/15 15:38:02 wolti Exp $
*/
/* ---------- AVR includes ----------*/
#include "avr/io.h"
#include "avr/interrupt.h"
/* ---------- Modbus includes ----------*/
#include "mb.h"
#include "mbport.h"
/* ---------- Defines ----------*/
#define REG_INPUT_START 1000
#define REG_INPUT_NREGS 4
/* ---------- Static variables ----------*/
static USHORT usRegInputStart = REG_INPUT_START;
static USHORT usRegInputBuf[REG_INPUT_NREGS];
/* ---------- Start implementation ----------*/
int
main( void )
{
const UCHAR ucSlaveID[] = { 0xAA, 0xBB, 0xCC };
eMBErrorCode eStatus;
eStatus = eMBInit( MB_RTU, 0x0A, 0, 38400, MB_PAR_EVEN );
eStatus = eMBSetSlaveID( 0x34, TRUE, ucSlaveID, 3 );
sei( );
/* Enable the Modbus Protocol Stack. */
eStatus = eMBEnable( );
for( ;; )
{
( void )eMBPoll( );
/* Here we simply count the number of poll cycles. */
usRegInputBuf[0]++;
}
}
eMBErrorCode
eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
if( ( usAddress >= REG_INPUT_START )
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
{
iRegIndex = ( int )( usAddress - usRegInputStart );
while( usNRegs > 0 )
{
*pucRegBuffer++ =
( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
*pucRegBuffer++ =
( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs,
eMBRegisterMode eMode )
{
return MB_ENOREG;
}
eMBErrorCode
eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils,
eMBRegisterMode eMode )
{
return MB_ENOREG;
}
eMBErrorCode
eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
{
return MB_ENOREG;
}