0% found this document useful (0 votes)
5 views8 pages

Socket Messaging with Basic IO Map (2020-03-24)

This document outlines the configuration process for a Coherix sensor to communicate with a Robot, PLC, or PC via TCP/IP Socket Messaging using a custom protocol called 'P3D Link'. It includes step-by-step instructions for setting up the sensor and example C code for a Windows PC to facilitate communication. Additionally, it provides guidance on testing the communication through the i-Cite™ software.

Uploaded by

coreymurphy613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Socket Messaging with Basic IO Map (2020-03-24)

This document outlines the configuration process for a Coherix sensor to communicate with a Robot, PLC, or PC via TCP/IP Socket Messaging using a custom protocol called 'P3D Link'. It includes step-by-step instructions for setting up the sensor and example C code for a Windows PC to facilitate communication. Additionally, it provides guidance on testing the communication through the i-Cite™ software.

Uploaded by

coreymurphy613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction

This document describes how to configure a Coherix sensor to communicate with a Robot, PLC, or PC
using TCP/IP Socket Messaging. The Coherix sensor is configured as a TCP/IP server and the Robot, PLC,
or PC is configured as a TCP/IP client. The communication takes place using a custom protocol called
“P3D Link”.

This document also provides an example C program which demonstrates how to program a Windows PC
to communicate with the Coherix sensor.

Configure Coherix sensor to use TCP/IP Socket Messaging


(P3D Link)
Log into the Coherix sensor and open the i-Cite™ software.
Go to File  Configuration  Digital I/O Map. Then perform the following actions:

Click Add
Select P3D Link

IP Address of Robot, PLC, or PC

Select “Predator3D Standard Control”


and click “Auto Config”
Next, go to File  Digital I/O  Special. Then set the “Heart Beat” values as shown below.

Use these
Heart Beat
settings

Configure Robot, PLC, or PC


Every 10 to 20 milliseconds, the Robot, PLC, or PC should send a sequence of 20 bytes to port 12345 of
the Coherix sensor. These bytes will be interpreted by the Coherix sensor as shown in the example
below. Note that in the table a number that begins with “0x” represents a hexadecimal number and a
number that begins with “0b” represents a binary number. A number with no prefix (e.g. 22) represents
a decimal number.
Every 10 to 20 milliseconds, the Robot, PLC, or PC should receive a sequence of 12 bytes from port
12345 of the Coherix sensor. These bytes should be interpreted by the Robot, PLC, or PC as shown in the
example below.

For more information on the values shown in the above tables, see the document titled “General Setup
Instructions for Predator3D and Robot Communication.xlsx”. The file can be found by going to
filetransfer.coherix.com and clicking “Communication Setup”.

Example C Program
This section presents an example C program that runs on a Windows PC. This example program will
communicate with the Coherix sensor using TCP/IP socket messaging. This example was successfully
compiled with Microsoft Visual Studio 2017.

#include <stdio.h>
#include <stdbool.h>
#include <Windows.h>

#pragma comment(lib,"ws2_32.lib")

int main() {

char server_reply[64];
int recv_size;
u_short status_bits = 0;
bool status_pass = false;
bool status_fail = false;
bool status_results_valid = false;
bool status_automatic_mode = false;
bool status_heartbeat = false;
bool status_repairable = false;
bool status_repair_gun = false;
u_short failure_code = 0;
// Startup Winsock2
WSADATA wsa;
// "MAKEWORD(2,2)" represents a minimum Winsock version number.
// "wsa" will contain info on Winsock, but it is not used in the example below.
WSAStartup(MAKEWORD(2,2), &wsa);

// Create a TCP socket


// "AF_INET" indicates the socket will use Internet Protocol version 4 (IPv4).
// "SOCK_STEAM" indicates the socket will use Transmission Control Protocol
(TCP).
SOCKET s = socket(AF_INET, SOCK_STREAM, 0);

// Connect to Server
// IP address of the Coherix sensor
char server_address[] = "192.168.10.140";
// Port used for P3DLink
u_short server_port = 12345;
struct sockaddr_in server;
// "AF_INET" indicates the server will use Internet Protocol version 4 (IPv4).
server.sin_family = AF_INET;
// "inet_addr" converts ip address from string to long.
server.sin_addr.s_addr = inet_addr(server_address);
// "htons" sets correct endianness.
server.sin_port = htons(server_port);

printf("Connecting to Predator3D(TM) P3D Link at %s:%d", server_address,


server_port);
while (connect(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
{
// Failed to connect, show error message.
int error_code = WSAGetLastError();
wchar_t *error_message = NULL;
FormatMessageW(
(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS),
NULL,
error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&error_message,
0,
NULL
);
printf("\n\n%S(Windows Socket Error Code %d)\n", error_message, error_code);
LocalFree(error_message);
Sleep(1000); // sleep 1000 milliseconds
}

// Define output_message
#define OUTPUT_MESSAGE_WORD_COUNT 10 // number of 16-bit words
#define OUTPUT_MESSAGE_BYTE_COUNT (2*OUTPUT_MESSAGE_WORD_COUNT)
u_short output_message[OUTPUT_MESSAGE_WORD_COUNT];
// Loop forever
while(true) {

printf("\nSending P3D Link Message to Coherix sensor");

output_message[0] = 0x74; // Set command to 0x74 (Write


Registers)
output_message[1] = 0x51; // Set response code to 0x51
(Success)
output_message[2] = 0; // Location to start writing
registers
output_message[3] = 6; // Number of 16-bit registers to
write
output_message[4] = 0b0000000000000110; // Turn on Run and Gun
output_message[5] = 11; // Set Zone = 11
output_message[6] = 22; // Set Speed = 22
output_message[7] = 33; // Set Part Style = 33
output_message[8] = 44; // Set Feature = 44
output_message[9] = 55; // Set Control Timestamp = 55

if ( send(s, (const char *)output_message, OUTPUT_MESSAGE_BYTE_COUNT, 0)


== SOCKET_ERROR ) {
// Failed to send message, show error message
int error_code = WSAGetLastError();
wchar_t *error_message = NULL;
FormatMessageW(
(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS),
NULL,
error_code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&error_message,
0,
NULL
);
printf("\n\n%S(Windows Socket Error Code %d)\n", error_message,
error_code);
LocalFree(error_message);
}

printf("\nReceiving P3D Link Message from Coherix sensor");

recv_size = recv(s, server_reply, 64, 0);


printf("\nrecv_size = %d", recv_size);

if (recv_size >= 12) {

status_bits = *(u_short *)(& server_reply[8]);


status_pass = (status_bits >> 1) & 1;
status_fail = (status_bits >> 2) & 1;
status_results_valid = (status_bits >> 3) & 1;
status_automatic_mode = (status_bits >> 4) & 1;
status_heartbeat = (status_bits >> 5) & 1;
status_repairable = (status_bits >> 7) & 1;
status_repair_gun = (status_bits >> 8) & 1;
failure_code = *(u_short *)(& server_reply[10]);
printf("\nReply from Coherix sensor:");
printf("\n status_pass = %d", status_pass);
printf("\n status_fail = %d", status_fail);
printf("\n status_results_valid = %d", status_results_valid);
printf("\n status_automatic_mode = %d", status_automatic_mode);
printf("\n status_heartbeat = %d", status_heartbeat);
printf("\n status_repairable = %d", status_repairable);
printf("\n status_repair_gun = %d", status_repair_gun);
printf("\n failure_code = %d", failure_code);
}

} // End of loop
closesocket(s);
WSACleanup();
}

When you run the program, you should see an output like the following:
Testing
To test the communication, go to File  Digital I/O. Use the dialog boxes shown below to view Coherix
input data and send Coherix output data.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy