主要问题是当我按下按钮时,不会调用控制器的方法。 我在MyController的索引视图中有这个:
#include <asf.h>
void initialize(void)
{
system_init();
delay_init();
ioport_init();
}
//I2c slave address
#define AM2315_ADDRESS 0xB8 //temp and humity sensor
#define DATA_LENGTH 10
#define TIMEOUT 1000 //number of time to try and send the packet before it
fails
static uint8_t write_buffer[DATA_LENGTH] = {0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09};
static uint8_t read_buffer[DATA_LENGTH];
struct i2c_master_module i2c_master_instance;
void configure_i2c_master(void)
{
/* Initialize config structure and software module. */
struct i2c_master_config config_i2c_master;
i2c_master_get_config_defaults(&config_i2c_master);
/* Change buffer timeout to something longer. */
config_i2c_master.buffer_timeout = 10000;
/* Initialize and enable device with config. */
i2c_master_init(&i2c_master_instance, SERCOM1, &config_i2c_master);
i2c_master_enable(&i2c_master_instance);
}
int main (void)
{
initialize();
configure_i2c_master();
uint8_t timeout = 0 ;
struct i2c_master_packet packet ={
.address = AM2315_ADDRESS,
.data_length = DATA_LENGTH,
.data = write_buffer,
.ten_bit_address = false,
.hs_master_code = 0x0,
};
ioport_set_pin_dir(PIN_PA27, IOPORT_DIR_OUTPUT);
while(1)
{
delay_ms(1000);
ioport_set_pin_level(PIN_PA27, true);
delay_ms(1000);
ioport_set_pin_level(PIN_PA27, false);
//write buffer to slave untill success
while(i2c_master_read_packet_wait(&i2c_master_instance, &packet) !=
STATUS_OK){
if (timeout++ ==TIMEOUT){
break;
}
}
//Read from slave until success.
packet.data = read_buffer;
while (i2c_master_read_packet_wait(&i2c_master_instance, &packet) !=
STATUS_OK){
if (timeout++ ==TIMEOUT){
break;
}
}
}
}
在MyController中我有DoSomethingAction方法。我想调用此方法,并在按下按钮时能够看到IdString:DoSomething1或DoSomething2。这是来自控制器的DoSomethingAction方法:
------ Build started: Project: GccBoardProject1, Configuration: Debug ARM --
Build started.
Project "GccBoardProject1.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition;
('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files
(x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project
"C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\GccBoardProject1.cproj"
(target "Build" depends on it):
Task "RunCompilerTask"
Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --
output-sync
C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\src\main.c(35,6): warning: no
previous prototype for 'initialize' [-Wmissing-prototypes]
void initialize(void)
^~~~~~~~~~
C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\src\main.c(58,6): warning: no
previous prototype for 'configure_i2c_master' [-Wmissing-prototypes]
void configure_i2c_master(void)
^~~~~~~~~~~~~~~~~~~~
Building file: ../src/main.c
Invoking: ARM/GNU C Compiler : 6.3.1
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-
toolchain\bin\arm-none-eabi-gcc.exe" -x c -mthumb -D__SAMD21G18A__ -DDEBUG
-DBOARD=USER_BOARD -DARM_MATH_CM0PLUS=true -DSYSTICK_MODE -
DI2C_MASTER_CALLBACK_MODE=true -I"../src/ASF/common/boards" -
I"../src/ASF/sam0/utils" -I"../src/ASF/sam0/utils/header_files" -
I"../src/ASF/sam0/utils/preprocessor" -
I"../src/ASF/thirdparty/CMSIS/Include" -
I"../src/ASF/thirdparty/CMSIS/Lib/GCC" -I"../src/ASF/common/utils" -
I"../src/ASF/sam0/utils/cmsis/samd21/include" -
I"../src/ASF/sam0/utils/cmsis/samd21/source" -
I"../src/ASF/sam0/drivers/system"
-I"../src/ASF/sam0/drivers/system/clock/clock_samd21_r21_da_ha1" -
I"../src/ASF/sam0/drivers/system/clock" -
I"../src/ASF/sam0/drivers/system/interrupt" -
I"../src/ASF/sam0/drivers/system/interrupt/system_interrupt_samd21" -
I"../src/ASF/sam0/drivers/system/pinmux" -
I"../src/ASF/sam0/drivers/system/power" -
I"../src/ASF/sam0/drivers/system/power/power_sam_d_r_h" -
I"../src/ASF/sam0/drivers/system/reset" -
I"../src/ASF/sam0/drivers/system/reset/reset_sam_d_r_h" -
I"../src/ASF/common2/boards/user_board" -I"../src" -I"../src/config" -
I"../src/ASF/common2/services/delay" -
I"../src/ASF/common2/services/delay/sam0" -
I"../src/ASF/common/services/ioport" -I"../src/ASF/sam0/drivers/sercom" -
I"../src/ASF/sam0/drivers/sercom/i2c" -O1 -fdata-sections -ffunction-
sections -mlong-calls -g3 -Wall -mcpu=cortex-m0plus -c -pipe -fno-strict-
aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-
function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-
sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -
Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -
Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-
function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-
declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-
declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -
Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -MD -MP -
MF "src/main.d" -MT"src/main.d" -MT"src/main.o" -o "src/main.o"
"../src/main.c"
Finished building: ../src/main.c
src/main.o: In function `configure_i2c_master':
C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\src\main.c(69,1): error:
undefined reference to `i2c_master_init'
src/main.o: In function `main':
C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\src\main.c(103,1): error:
undefined reference to `i2c_master_read_packet_wait'
collect2.exe(0,0): error: ld returned 1 exit status
make: *** [GccBoardProject1.elf] Error 1
Building target: GccBoardProject1.elf
Invoking: ARM/GNU Linker : 6.3.1
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-
toolchain\bin\arm-none-eabi-gcc.exe" -o GccBoardProject1.elf
src/ASF/sam0/drivers/sercom/sercom.o
src/ASF/sam0/drivers/sercom/sercom_interrupt.o
src/ASF/common2/services/delay/sam0/systick_counter.o
src/ASF/common2/boards/user_board/init.o
src/ASF/common/utils/interrupt/interrupt_sam_nvic.o
src/ASF/sam0/drivers/system/clock/clock_samd21_r21_da_ha1/clock.o
src/ASF/sam0/drivers/system/clock/clock_samd21_r21_da_ha1/gclk.o
src/ASF/sam0/drivers/system/interrupt/system_interrupt.o
src/ASF/sam0/drivers/system/pinmux/pinmux.o
src/ASF/sam0/drivers/system/system.o
src/ASF/sam0/utils/cmsis/samd21/source/gcc/startup_samd21.o
src/ASF/sam0/utils/cmsis/samd21/source/system_samd21.o
src/ASF/sam0/utils/syscalls/gcc/syscalls.o src/main.o -mthumb -Wl,-
Map="GccBoardProject1.map" --specs=nano.specs -Wl,--start-group -
larm_cortexM0l_math -lm -Wl,--end-group -
L"../src/ASF/thirdparty/CMSIS/Lib/GCC" -Wl,--gc-sections -mcpu=cortex-
m0plus -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -
T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21g18a_flash.ld
C:\Users\benvo\Documents\Atmel
Studio\7.0\GccBoardProject1\GccBoardProject1\Debug\Makefile(333,1): error:
recipe for target 'GccBoardProject1.elf' failed
The command exited with code 2.
Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "GccBoardProject1.cproj" --
FAILED.
Done building project "GccBoardProject1.cproj" -- FAILED.
Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
TAGS:
Tools, Atmel Software Framework (ASF) and Atmel Start (ASFv4), all
architectures
当我为DoSomethingAction方法设置断点时,我发现它从未被调用过。 我试图为这个方法设置[Httppost]属性,但它没有解决我的问题。
我做错了什么? 之后,如何在DoSomethingAction方法中看到按下了哪个按钮?
答案 0 :(得分:1)
HTML表单无法嵌套HTML表单。请阅读https://www.w3.org/TR/html5/forms.html#the-form-element
如果您需要多个表单,可以将它们定义为兄弟姐妹。
答案 1 :(得分:0)
使用html.BeginForm
或type="Submit"
。接下来要记住,html.BeginForm
是一个post方法,所以如果你想使用它,给Action一个属性,如果你不说明view
动作应该返回什么,他将假设该视图与操作同名,在您的案例DoSomethingAction
中,这就是您收到服务器错误的原因。在return View()
中查看或查看您要返回的视图(索引或其他视图)。