Recieving data from Cognex Dataman Camera over Ethernet

2015-06-29
2024-10-22
  • nathangreco - 2015-06-29

    For some reason I thought there would be a pretty well developed solution for this as I don't think this is an unusual request, but my searches so far have turned up nil. As I see it there's 3 ways to go about this:

    1) Data over Modbus - This should work and I would think to be the easiest, but as you can see from the other thread I'm still stuck.
    2) Data messaging through open socket - It seems the Dataman camera can be configured to open a socket on a client and send telegrams via ASCII strings. I think this would certainly work but sounds pretty labor intensive to get a robust solution going without any example to start with as a foundation.
    3) Getting the data via FTP - The dataman camera can also be setup as an FTP server and can write the result data to a text file.

    Has anybody else gone down this road before? If not, can you at least let me know which solution sounds most straightforward? I'm not familiar with the SysSockets.lib functions that would probably be necessary for #2, and would still need to find a library to make #3 happen. Input is appreciated, I'm just trying to decide how hard I want to work to make #1 function correctly.

    Thanks

     
  • nathangreco - 2015-06-29

    And option 4, would be to use RS-232. This is feasible with my hardware, but I thought it wouldn't be much different/easier than option #2.

     
  • shooter - 2015-06-30

    This is not possible in a PLC, as the PLC has cycle times > 5 ms, it will never keep up the camera.
    you will need to have a PC type, and a program to catch your camera, codesys is meant for control of contacts, and movements.

     
  • nathangreco - 2015-07-01

    Do you mean option #2 is not possible? Of course the Modbus options should be possible, its a protocol intended for PLC <-> field device communication.

    I suppose I should elaborate about my setup. There isn't any handling of triggering or anything required (all done by camera IO). All it needs to do is listen on a port to receive a 14 character string, I've tested it with a simple Java program and it works well. Is this something the SysLibSockets.lib cannot do?

     
  • shooter - 2015-07-01

    receiving a string is no problem.
    there are several types and libs for the same many types of codesys plc, so stay with manufacturer or use oscat.de lib.

     
  • nathangreco - 2015-07-01

    I'm definitely getting close, not sure I actually need SysSockAccept. Here's what I have:

    VAR
    CameraSockAddr: SOCKADDRESS;

    FirstPass:      BOOL:=FALSE;
    xSocketIsOpen:  BOOL;
    diSocketHandle: DINT;
    diErrCode:      DINT;
    diAddressFamily:    DINT:=SOCKET_AF_INET;
    diType:     DINT:=SOCKET_DGRAM;
    diProtocol:     DINT:=SOCKET_IPPROTO_UDP;
    
    diSocketListen: DINT;
    pbyBuffer:      DWORD;
    diBufferSize:   DINT:=14;
    diFlags:        DINT;
    Result:     STRING;
    SockAddress:    BYTE:=23;
    SockAccept: BYTE;
    

    END_VAR

    ( code )

    IF NOT FirstPass THEN
    CameraSockAddr.sin_family:=SOCKET_AF_INET;
    CameraSockAddr.sin_port:=23;
    CameraSockAddr.sin_addr:=STRING_TO_UDINT('10.224.68.230'); !!! This is a problem!
    diSocketHandle:= SysSockCreate(
    diAddressFamily,
    diType,
    diProtocol);
    FirstPass:=TRUE;
    END_IF
    IF diSocketHandle <> SOCKET_INVALID THEN
    xSocketIsOpen:=TRUE;
    diErrCode:= 0;
    ELSE
    xSocketIsOpen:=FALSE;
    diErrCode:=1;
    END_IF

    diSocketListen:=SysSockRecvFrom(
    diSocket:=diSocketHandle,
    pbyBuffer:=ADR(Result),
    diBufferSize:=14,
    diFlags,
    pSockAddr:=ADR(CameraSockAddr),
    diSockAddrSize:=SIZEOF(CameraSockAddr));

    END_PROGRAM

    Result is a -1 value for diSocketListen, but I'm sure it won't work because the value for the sin_addr variable of my CameraSockAddr object is '10'. I don't understand how to properly convert an IP address to a UDINT, any help here?

     
  • nathangreco - 2015-07-01

    I found the function "SysSockInetAddr", and have used that to convert the string ip address into a UDINT, so I think that obstacle is handled. But still, SysSockRecFrom function returns -1. I'm wondering what I should be setting the diFlags value to.

     
  • nathangreco - 2015-07-01

    This is still kicking my butt. Reading through the documents I have found that there is a sequence, depending on the client/server and UDP/TCP.

    For a UDP Server, I need to create the socket, bind the socket to the socket address, then receive the data. Right now, the binding function returns a false value, here's how I have my SockAddress data structure set:

    CameraSockAddr.sin_family:=SOCKET_AF_INET;
    CameraSockAddr.sin_port:=23;
    CameraSockAddr.sin_addr:=sysSockInetAddr('10.224.68.230');

    And my logic for the binding:

    IF Created AND NOT Bound THEN
    Bound:=SysSockBind(
    diSocket:=diSocketHandle, ( returned from SysSocketCreate )
    pSockAddr:=ADR(CameraSockAddr),
    diSockAddrSize:=SIZEOF(CameraSockAddr));
    END_IF

    If I go the TCP route I cannot create a socket at all, not sure why, but that would explain why I never got the TCP Modbus libraries working.

    In the one document there's an example of a "UDPServer" function block. Seems much more self explanatory, but that doesn't come in with the SysLibSockets.lib

     
  • nathangreco - 2015-07-02

    Hey Guys,

    Finally, digging harder, I found this example:

    l viewtopic.php?t=133 l

    Which worked almost out of the box. For whatever reason the UDP didn't work even though I had the camera set to UDP (it worked with TCP), and the TCPClient worked regardless of the UDP/TCP setting on the camera. Works pretty flawlessly, thanks for the feedback and hopefully this helps somebody in the future.

    -Nate

     

Log in to post a comment.