Jump to content
OMRON Forums

Comm with RS232 peripherals


Recommended Posts

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

Link to comment
Share on other sites

  • 9 months later...

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 by 1220801328
  • Like 1
Link to comment
Share on other sites

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);



    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);
    // 关闭套接字
    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.


  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...