armink / FreeModbus_Slave-Master-RTT-STM32

Add master mode to FreeModbus. | 在 FreeModbus 中添加主机模式
Other
1.6k stars 820 forks source link

How to read from slave? #51

Open emrelio opened 4 years ago

emrelio commented 4 years ago

I'm trying to read registers from the slave. But I can't read anything. With the ReqWrite function or FuncWrite function.

How can I read registers from the slave?

Thank You!

armink commented 4 years ago

You can ues this API

eMBMasterReqErrCode eMBMasterReqReadHoldingRegister( UCHAR ucSndAddr, 
                                                     USHORT usRegAddr,
                                                     USHORT usNRegs,
                                                     LONG lTimeOut );
emrelio commented 4 years ago

I'm trying with this function but I did write the wrong function name in the first message. Sorry.

But I couldn't find the variable to read the data. I mean which variable is for reading the data.

armink commented 4 years ago

You can find the read data on the usMRegHoldBuf in FreeModbus\port\user_mb_app_m.c

emrelio commented 4 years ago

Thank you! I did try to read but then I realized in every request the error code is always "TimeOut". Even in the reqWrite. I'm using f407 with 168MHz clock.

armink commented 4 years ago

May be uart driver has some problem. You can check the uart ISR for data receive.

miskin-lee commented 2 years ago

Thank you! I did try to read but then I realized in every request the error code is always "TimeOut". Even in the reqWrite. I'm using f407 with 168MHz clock.

me too!Have you solved the problem yet