Skip to content

Commit

Permalink
added minimal c example with gcc instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
strangesast committed Apr 7, 2021
1 parent da177c8 commit e90f6a1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
[![Docker Hub](https://img.shields.io/docker/v/strangesast/fwlib?sort=date)](https://hub.docker.com/r/strangesast/fwlib)
Header and runtime files for CNC communication

Examples of its use may be found in `examples/`
# Docker
Build the base image with `docker build .`

Build an example with `docker build examples/c/Dockerfile`

# `examples/`
Link or rename appropriate `libfwlib\*.so` (based on platform) to `libfwlib32.so.1` and `libfwlib32.so`

On linux x86\_64 for example: `ln -s libfwlib32-linux-x64.so.1.0.5 libfwlib32.so`

More instructions in each example folder
3 changes: 3 additions & 0 deletions examples/c-minimal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Instructions

From the root of this repository: `gcc -L./ -Wl,-rpath . examples/c-minimal/main.c -lfwlib32 -lm -lpthread -o fanuc_minimal`
49 changes: 49 additions & 0 deletions examples/c-minimal/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "../../fwlib32.h"
#define MACHINE_HOST "127.0.0.1"
#define MACHINE_PORT 8193

int main(int argc, char *argv[]) {
int allocated = 0;
int ret = 0;
unsigned short libh;
char cnc_id[40] = "";
uint32_t cnc_ids[4];

#ifndef _WIN32
if (cnc_startupprocess(0, "focas.log") != EW_OK) {
fprintf(stderr, "Failed to create required log file!\n");
return 1;
}
#endif

printf("connecting to machine at %s:%d...\n", MACHINE_HOST, MACHINE_PORT);
if ((ret = cnc_allclibhndl3(MACHINE_HOST, MACHINE_PORT, 10, &libh)) != EW_OK) {
fprintf(stderr, "Failed to connect to cnc! (%d)\n", ret);
ret = 1;
goto cleanup;
}
allocated = 1;

if (cnc_rdcncid(libh, (unsigned long *)cnc_ids) != EW_OK) {
fprintf(stderr, "Failed to read cnc id!\n");
ret = 1;
goto cleanup;
}

snprintf(cnc_id, 40, "%08x-%08x-%08x-%08x", cnc_ids[0], cnc_ids[1],
cnc_ids[2], cnc_ids[3]);

cleanup:
if (allocated && cnc_freelibhndl(libh) != EW_OK)
fprintf(stderr, "Failed to free library handle!\n");
#ifndef _WIN32
cnc_exitprocess();
#endif

printf("machine id: %s\n", cnc_id);
}

0 comments on commit e90f6a1

Please sign in to comment.