DaveBarnett Posted May 10, 2023 Posted May 10, 2023 I need to support comm over multiple (2-3?) old school RS232 serial ports on CK3M processor. I see a 10-year old app note "Serial comm on PowerPmac" but, nothing up to date. Has anyone successfully implemented this lately ? I am considering both USB hub with multiple serial/usb adapters or perhaps a network type adapter like those made by Lantronix and others. Any advice or comments ? This application only needs modest bandwidth, communicating with some peripherals. C- libraries seem able to do the job...but, today maybe PYSerial or ??? -thanks in advance Quote
1220801328 Posted March 8 Posted March 8 (edited) You can try using Omron NX-ECC plus NX-CIF module, I have used this and communication was successful. But this method is difficult to write, so I chose to use Omron's NX1P2 PLC for communication, and then send the data to PMAC through EtherNet/IP, and finally got good results. Edited March 9 by 1220801328 1 Quote
MoMo Posted March 10 Posted March 10 I use the following RS232 to Ethernet module. About $30 /*For more information see notes.txt in the Documentation folder */ #include <gplib.h> #define _PPScriptMode_ // for enum mode, replace this with #define _EnumMode_ #include "../../Include/pp_proj.h" #include <gplib.h> #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <netinet/in.h> #define PORT_NUM 9739 //端口号 int main(void) { InitLibrary(); // Required for accessing Power PMAC library int server_sockfd = -1; int server_len = 0; int client_len = 0; char Cmd[256],Recv[256]; int result = 0; int i,length_of_Cmd_Recv; struct sockaddr_in server_addr; struct sockaddr_in client_addr; // 创建数据报套接字 server_sockfd = socket(AF_INET, SOCK_DGRAM, 0); // 设置监听的端口、IP server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(PORT_NUM); server_len = sizeof(server_addr); client_addr.sin_addr.s_addr = htonl(INADDR_ANY); client_addr.sin_port = htons(0); client_len = sizeof(client_addr); // 绑定(命名)套接字 bind(server_sockfd, (struct sockaddr *)&server_addr, server_len); length_of_Cmd_Recv=sizeof(Cmd); for(i=0;i<256;i++) { Cmd[i]=0; Recv[i]=0; } while (1) { // 接收数据,用 client_addr 来储存数据来源程序的IP端口 result = recvfrom(server_sockfd, &Cmd, length_of_Cmd_Recv, 0,(struct sockaddr *)&client_addr, &client_len); result = GetResponse(&Cmd,&Recv,length_of_Cmd_Recv,0); //发送处理后的数据 sendto(server_sockfd, &Recv, length_of_Cmd_Recv, 0, (struct sockaddr *)&client_addr, client_len); //清空缓存 for(i=0;i<256;i++) { Cmd[i]=0; Recv[i]=0; } } // 关闭套接字 close(server_sockfd); CloseLibrary(); return 0; } The above is the Socket communication code of PPMAC. I recommend using UDP communication because UDP communication is closer to the serial port and is carried out in the form of messages. 1 1 Quote
DaveBarnett Posted March 12 Author Posted March 12 MoMo....Thank you for your thorough explanation and documentation of the approach you took! I wish all the forum posts were so complete! Code included, even! I ended up with a very similar solution to yours, using a four-port model from Moxa corp. It was very handy to use TeraTerm terminal emulation software to operate (over ethernet) any of the four ports for debugging... before having to write any code at all. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.