Calling API Functions

All LayGO API function names and argument sequences are identical to those documented in the C language API. For instance, the code to open a CID which might be written in C as:

#include <laygo.h>

LCid cid;

cid = lgo_Open("PHYS0");

if (cid < 0)

translates directly into the following Python code:

from Laygopy import *
import Laygo

cid = lgo_Open('PHYS0')

if (cid < 0):

For functions which take C pointer types such as LDataBuffer or LCtlBuffer, substitute a buffer allocated with the LayGO memory allocation API. The C code to read data:

unsigned char buffer[1024];
LResult       result;

result = lgo_Read(cid, buffer, 1024);

if (result > 0)
    ProcessData(buffer, result);
else if (result == lgo_ERROR_EVENT_WAITING)

becomes the Python code:

buffer = lgo_BufferNew(1024)
result = lgo_Read(cid, buffer, 1024)

if (result > 0):
    ProcessData(buffer, result)
elif (result == Laygo.ERROR_EVENT_WAITING):

Where a NULL pointer would be used in C, substitute the string 'NULL':

LResult result;

result = lgo_ConnectRequest(cid, NULL, 0);

in Python becomes:

result = lgo_ConnectRequest(cid, 'NULL', 0)

Finally, where a pointer to an integral type would be used in C to return a value, the Python function returns a list of values:

unsigned char buffer[128];
LBufferSize   size;
LResult       result;

size   = sizeof(buffer);
result = lgo_Event(cid, buffer, &size);

becomes in Python:

buffer = lgo_BufferNew(128)

result, size = lgo_Event(cid, buffer, 128)