老 姚
/
modbusServer2
modbus for modular2_dio10
Revision 1:8fcbafe2ca98, committed 2019-09-28
- Comitter:
- yao6116601
- Date:
- Sat Sep 28 02:25:51 2019 +0000
- Parent:
- 0:998a68b8defc
- Commit message:
- modbus for modular2_dio10
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
modbus/modbus.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Sep 17 01:59:40 2019 +0000 +++ b/main.cpp Sat Sep 28 02:25:51 2019 +0000 @@ -1,7 +1,11 @@ +/* + * DTU for QianBang Robot Project + * Interface use Modular2_DIO10_V1.0 + * Communication use Modular2_RS485_V1.0 + * Copyright (c) 2019, Maximlab. All rights reserved. + */ #include "mbed.h" #include "modbus.h" -DigitalOut led1(PC_6); - DigitalIn DI0(PF_5); DigitalIn DI1(PF_3); DigitalIn DI2(PF_7); @@ -12,7 +16,6 @@ DigitalIn DI7(PF_4); DigitalIn DI8(PF_8); DigitalIn DI9(PF_9); - DigitalOut DO0(PE_11); DigitalOut DO1(PE_7); DigitalOut DO2(PB_0); @@ -23,10 +26,10 @@ DigitalOut DO7(PF_1); DigitalOut DO8(PC_0); DigitalOut DO9(PC_3); -// DigitalOut HF(PD_14); +DigitalOut led1(PC_6); Modbus slave(PB_6,PB_7,PD_12,9600); -uint8_t myAddress=0x01; +uint8_t myAddress=0x06;//Slave address uint16_t data[32]; uint16_t readDI(uint16_t address) { @@ -78,7 +81,7 @@ } uint16_t writeDO(uint16_t address,uint16_t value) { - uint16_t terminal=address-100; + uint16_t terminal=address-120; switch(terminal) { case 0:{ @@ -141,9 +144,10 @@ uint16_t points; int i; if(slave.waitQuery(address,function,startAddress,points)) - { + { printf("address=%d function:%d startAddress:%d Points:%d\n",address,function,startAddress,points); if ((address==myAddress)&&(function==0x03)) { //read reigster + uint16_t p=startAddress; for (i=0;i<points;i++) {
--- a/modbus/modbus.cpp Tue Sep 17 01:59:40 2019 +0000 +++ b/modbus/modbus.cpp Sat Sep 28 02:25:51 2019 +0000 @@ -177,8 +177,12 @@ resultCRC = calculateCRC16(rbuf,index); sbuf[index++]=(resultCRC>>8)&0xff; sbuf[index++]=resultCRC &0xff; + dir=1; + wait_ms(2); for (i=0;i<index;i++) rs485.putc(sbuf[i]) ; + wait_ms(2); + dir=0; return true; } unsigned int Modbus::calculateCRC16( uint8_t *puchMsg,unsigned int usDataLen)