完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
大家好。我有ApIC32 MX575 F512L,它使用了Modbus TCP在从配置(它完美地工作)。现在,我需要实现另一个软件(也就是FPIC32 MX575 F512L),使主板工作在主模式中,这样我就可以在它们之间通信两个板。我知道通过简单的UART进行通信会更好地进行那种一对一的通信,但我想把它作为对未来项目的测试。这个想法是控制通过Modbus TCP与我的板通信的一组电池。但是我很难找到关于如何做的任何文档(或代码示例)。似乎每个人都在编程他们的图片是奴隶:(任何帮助或提示都会非常感激。PS:我有两个文件(MbMask.c和MbMask.h),包括所需的功能,但我真的迷失了如何使用它们。我知道Modbus是如何工作的,但是我一直在努力把我的固件从奴隶模式转变成主模式。如果需要更多的信息,请询问。
以上来自于百度翻译 以下为原文 Hello everybody. I have a PIC32MX575F512L which uses modbus TCP in a slave configuration (it works perfectly). Now, I need to implement another software (also for PIC32MX575F512L) that makes the board to work in Master mode so I can communicate two boards between them. I know that communicating through a simple UART will be better for that kind of one to one communication but I want to do this as a test for a future proyect. The idea is to control an array of batteries that will communicate with my board through modbus TCP (there's no choice of doing it another way) but I'm having serious difficulties to find any documentation about how to do it (or code examples). It seems that everybody are programming their PICs to be slaves :( Any help or tip would be greatly appreciated. PS: I have two files (mbmaster.c and mbmaster.h) that include the functions needed but I'm really lost about how to using them. I know how Modbus works but I'm stuck trying to change my firmware from slave mode to master mode. If more info is needed, pls, ask for it. |
|
相关推荐
2个回答
|
|
我猜我属于只为Modbus TCP实现了一个从端口的组。不过,我认为这很简单。使用伯克利套接字,你的奴隶实际上是服务器,而你的主人是客户端。如果你知道你的奴隶的IP地址-使用这个实现的静态地址使测试变得更容易——那么你只需遵循下面的逻辑:C:Microchip HyralV2O04AppTCPIPBelkelyTCPPlie固件 SRCApp.c来处理它的TCP客户端部分。从这里,您关心的是以下内容:打包消息发送、拆封收到的消息和处理任何错误。
以上来自于百度翻译 以下为原文 I guess I fall into that group that has only implemented a slave port for modbus TCP. However, I would think that it's pretty straightforward. Using Berkeley sockets, your slaves are actually the servers while your master is a client. If you know the IP addresses of your slaves - use static addresses for this implementation to make testing easier - then you would simply follow the logic here: C:microchipharmonyv2_04appstcpipberkeley_tcp_clientfirmwaresrcapp.c. That handles the TCP client part of it. From there, all you're concerned with is the following: packaging the message to send, unpackaging the message received, and handling any errors. |
|
|
|
谢谢你的回复。我正在使用FrimoDeBUS库,此时,我可以从我的客户端设备打开一个TCP套接字。我有问题包装框架发送。我正在尝试使用函数:EMBRRORCORE EMBTCPSENT(UCHAR未使用,const uCHAR**pUcFrand,UsStudio UnStand){EnMRrOrgEntoStudio=MbEnEnOrr;UCHAR * PUCBMTCPFrase=(UCHAR *)PUCSTRAMP -MPU-TCPPFUNC;USTCpPLONTHONS长度+MUBTCPUFUNC;PUCBMTCPFrime[MbTCPPLLEN ] =(US长度+1)和G(1):(XMbTCPtPrError响应(PUCBMTCPFrror,USTCPLSLIN)=FALSE){ESTATAS= MBEIIO;}返回ESTATUS;}这意味着:BoOL XMbTCPtPosisEdTrror(const UCHAR *PUCBMTCPFrimeS,UsSuthUSTCPLS长度){BoOL BFrAMESeNET= FALSE;//FReal-de TrAM-EnviaaBooBabordt=false;Word Res;/QueSe PayeDeEnsibr Enel缓冲区int iBythEnter=0;//字节EnviaDOS int iTimeOUT=MbO-TCPpRead TimeUlt;//TimePo TimeOutdo{Res=TCPIsPutReady(XististOnCKET);IF(REST;(USTCpLime- iByTeStEnter)){RES=TCPPtRead(XistelSokes)Et,and PUBMTCPFrime[ iByTeStEnt],USTCPLSITION-iByTestEnter;}开关(RES){案例0:PRVVBPORTRAXASECIENT();BabORT=真;中断;默认:iBytEthTe++Res;Burt;}((iBythess)!= USTC长度)& & &!BabReSt= = iBytheSt= = USTC长度?真的:false;返回bFrAMEST;}任何人都可以帮助这些FrimoDeBUS库吗?有什么建议吗?
以上来自于百度翻译 以下为原文 Thanks for your reply. I'm using FreeModbus libraries and, by this time, I can open a TCP socket from my client device. I'm having problems packaging frames to send. I'm trying to use the function: eMBErrorCode eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame, USHORT usLength ) { eMBErrorCode eStatus = MB_ENOERR; UCHAR *pucMBTCPFrame = ( UCHAR * ) pucFrame - MB_TCP_FUNC; USHORT usTCPLength = usLength + MB_TCP_FUNC; pucMBTCPFrame[MB_TCP_LEN] = ( usLength + 1 ) >> 8U; pucMBTCPFrame[MB_TCP_LEN + 1] = ( usLength + 1 ) & 0xFF; if( xMBTCPPortSendResponse( pucMBTCPFrame, usTCPLength ) == FALSE ) { eStatus = MB_EIO; } return eStatus; } Which implies: BOOL xMBTCPPortSendResponse( const UCHAR * pucMBTCPFrame, USHORT usTCPLength ) { BOOL bFrameSent = FALSE;//Flag de trama enviada BOOL bAbort = FALSE; WORD res;//Bytes que se pueden escribir en el buffer int iBytesSent = 0;//Bytes enviados int iTimeOut = MB_TCP_READ_TIMEOUT;//Tiempo para timeout do { res = TCPIsPutReady( xListenSocket ); if(res > (usTCPLength - iBytesSent)){ res = TCPPutArray(xListenSocket,&pucMBTCPFrame[iBytesSent], usTCPLength - iBytesSent); } switch ( res ) { case 0: prvvMBPortReleaseClient( ); bAbort = TRUE; break; default: iBytesSent += res; break; } } while( ( iBytesSent != usTCPLength ) && !bAbort ); bFrameSent = iBytesSent == usTCPLength ? TRUE : FALSE; return bFrameSent; } Anyone can help with these freemodbus libraries? Any suggestion? |
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2036 浏览 8 评论
1956 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3217 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2264 浏览 5 评论
786浏览 1评论
677浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
602浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
684浏览 0评论
581浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 23:48 , Processed in 1.384625 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号