diff --git a/Applications/ndiBasicExample.cxx b/Applications/ndiBasicExample.cxx index c92c211..03a6def 100644 --- a/Applications/ndiBasicExample.cxx +++ b/Applications/ndiBasicExample.cxx @@ -11,7 +11,7 @@ #if _MSC_VER >= 1700 //---------------------------------------------------------------------------- -bool ParallelProbe(ndicapi*& outDevice) +bool ParallelProbe(ndicapi*& outDevice, bool checkDSR) { const int MAX_SERIAL_PORT_NUMBER = 20; // the serial port is almost surely less than this number std::vector deviceExists(MAX_SERIAL_PORT_NUMBER); @@ -27,7 +27,7 @@ bool ParallelProbe(ndicapi*& outDevice) std::lock_guard guard(deviceNameMutex); devName = std::string(ndiSerialDeviceName(i)); } - int errnum = ndiSerialProbe(devName.c_str()); + int errnum = ndiSerialProbe(devName.c_str(),checkDSR); if (errnum == NDI_OKAY) { deviceExists[i] = true; @@ -56,30 +56,38 @@ bool ParallelProbe(ndicapi*& outDevice) struct ndicapi; -int main() +int main(int argc, char * argv[]) { + bool checkDSR = false; ndicapi* device(nullptr); - char* name(nullptr); + const char* name(nullptr); + if(argc > 1) + name = argv[1]; + else + { #if _MSC_VER >= 1700 - ParallelProbe(device); + ParallelProbe(device,argc > 1 ? argv[1]: 0, checkDSR); #else - const int MAX_SERIAL_PORTS = 20; - for (int i = 0; i < MAX_SERIAL_PORTS; ++i) - { - name = ndiSerialDeviceName(i); - int result = ndiSerialProbe(name); - if (result == NDI_OKAY) { - break; + const int MAX_SERIAL_PORTS = 20; + for (int i = 0; i < MAX_SERIAL_PORTS; ++i) + { + name = ndiSerialDeviceName(i); + int result = ndiSerialProbe(name,checkDSR); + if (result == NDI_OKAY) + { + break; + } + } } +#endif } if (name != nullptr) { device = ndiOpenSerial(name); } -#endif if (device != nullptr) { diff --git a/ndicapi.cxx b/ndicapi.cxx index d783d41..28b7c21 100644 --- a/ndicapi.cxx +++ b/ndicapi.cxx @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGES. #include #include +#include + #include #include @@ -68,7 +70,7 @@ namespace // call the user-supplied callback function if (pol->ErrorCallback) { - pol->ErrorCallback(errnum, ndiErrorString(errnum), pol->ErrorCallbackData); + pol->ErrorCallback(errnum, (char*)ndiErrorString(errnum), pol->ErrorCallbackData); } return errnum; @@ -491,9 +493,9 @@ ndicapiExport int ndiGetSocketError(ndicapi* pol) } //---------------------------------------------------------------------------- -ndicapiExport char* ndiErrorString(int errnum) +ndicapiExport const char* ndiErrorString(int errnum) { - static char* textarray_low[] = // values from 0x01 to 0x21 + static const char* textarray_low[] = // values from 0x01 to 0x21 { "No error", "Invalid command", @@ -546,7 +548,7 @@ ndicapiExport char* ndiErrorString(int errnum) "Invalid input or output state", }; - static char* textarray_high[] = // values from 0xf6 to 0xf4 + static const char* textarray_high[] = // values from 0xf6 to 0xf4 { "Too much environmental infrared", "Unrecognized error code", @@ -556,7 +558,7 @@ ndicapiExport char* ndiErrorString(int errnum) "Unable to read Flash EPROM", }; - static char* textarray_api[] = // values specific to the API + static const char* textarray_api[] = // values specific to the API { "Bad CRC on reply from Measurement System", "Error opening serial connection", @@ -568,7 +570,7 @@ ndicapiExport char* ndiErrorString(int errnum) "Measurement System not found on specified port" }; - static char* textarray_serial[] = // values specific to serial errors + static const char* textarray_serial[] = // values specific to serial errors { "Serial DSR query failure", "Bad reply from measurement system", @@ -597,7 +599,7 @@ ndicapiExport char* ndiErrorString(int errnum) } //---------------------------------------------------------------------------- -ndicapiExport char* ndiSerialDeviceName(int i) +ndicapiExport const char* ndiSerialDeviceName(int i) { #if defined(_WIN32) @@ -649,7 +651,7 @@ ndicapiExport char* ndiSerialDeviceName(int i) { strncpy(devicenames[j], "/dev/", 5); strncpy(devicenames[j] + 5, ep->d_name, 255); - devicenames[j][255 + 5] == '\0'; + devicenames[j][255 + 5] = '\0'; closedir(dirp); return devicenames[j]; } @@ -744,7 +746,6 @@ ndicapiExport int ndiSerialProbe(const char* device, bool checkDSR) ndiSerialClose(serial_port); return NDI_BAD_COMM; } - // flush the buffers (which are unlikely to contain anything) ndiSerialFlush(serial_port, NDI_IOFLUSH); @@ -2184,7 +2185,7 @@ namespace int newspeed = 9600; int newhand = 0; - if (command[5] >= '0' && command[5] <= '7' || command[5] == 'A') + if ((command[5] >= '0' && command[5] <= '7') || command[5] == 'A') { if (command[5] != 'A') { @@ -2353,17 +2354,17 @@ ndicapiExport char* ndiCommandVA(ndicapi* api, const char* format, va_list ap) command[i++] = '\r'; // tack on carriage return command[i] = '\0'; // terminate for good luck - bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX") || - strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG") || - strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET")); + bool isBinary = (strncmp(command, "BX", commandLength) == 0 && commandLength == strlen("BX")) || + (strncmp(command, "GETLOG", commandLength) == 0 && commandLength == strlen("GETLOG")) || + (strncmp(command, "VGET", commandLength) == 0 && commandLength == strlen("VGET")); // if the command is GX, TX, or BX and thread_mode is on, we copy the reply from // the thread rather than getting it directly from the Measurement System if (api->IsThreadedMode && api->IsTracking && - commandLength == 2 && (command[0] == 'G' && command[1] == 'X' || - command[0] == 'T' && command[1] == 'X' || - command[0] == 'B' && command[1] == 'X')) + commandLength == 2 && ((command[0] == 'G' && command[1] == 'X') || + (command[0] == 'T' && command[1] == 'X') || + (command[0] == 'B' && command[1] == 'X'))) { // check that the thread is sending the GX/BX/TX command that we want if (strcmp(command, api->ThreadCommand) != 0) @@ -2559,7 +2560,7 @@ ndicapiExport char* ndiCommandVA(ndicapi* api, const char* format, va_list ap) // check for error code if (commandReply[0] == 'E' && strncmp(commandReply, "ERROR", 5) == 0) { - ndiSetError(api, ndiHexToUnsignedLong(&commandReply[5], 2)); + ndiSetError(api, (int)ndiHexToUnsignedLong(&commandReply[5], 2)); return commandReply; } @@ -3825,7 +3826,7 @@ static void* ndiThreadFunc(void* userdata) } // send the command to the Measurement System - i = strlen(command); + i = (int)strlen(command); if (errorCode == 0) { if (pol->SerialDevice != NDI_INVALID_HANDLE) diff --git a/ndicapi.h b/ndicapi.h index 2d734d3..48912f9 100644 --- a/ndicapi.h +++ b/ndicapi.h @@ -209,7 +209,7 @@ extern "C" { If \em i is too large, the return value is zero. */ -ndicapiExport char* ndiSerialDeviceName(int i); +ndicapiExport const char* ndiSerialDeviceName(int i); /*! \ingroup NDIMethods Probe for an NDI device on the specified serial port device. @@ -1859,7 +1859,7 @@ ndicapiExport int ndiGetIRCHKSourceXY(ndicapi* pol, int side, int i, double xy[2 An unrecognized error code will return "Unrecognized error code". */ -ndicapiExport char* ndiErrorString(int errnum); +ndicapiExport const char* ndiErrorString(int errnum); /*! \ingroup ConversionFunctions Convert \em n characters of a hexidecimal string into an unsigned long. diff --git a/ndicapi_serial_apple.cxx b/ndicapi_serial_apple.cxx index 7be0411..c027261 100644 --- a/ndicapi_serial_apple.cxx +++ b/ndicapi_serial_apple.cxx @@ -356,8 +356,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT } totalNumberOfBytesRead += numberOfBytesRead; - if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ - || isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r') + if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ + || (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')) { break; } diff --git a/ndicapi_serial_unix.cxx b/ndicapi_serial_unix.cxx index 06afcc2..028b384 100644 --- a/ndicapi_serial_unix.cxx +++ b/ndicapi_serial_unix.cxx @@ -433,8 +433,8 @@ ndicapiExport int ndiSerialRead(int serial_port, char* reply, int numberOfBytesT } totalNumberOfBytesRead += numberOfBytesRead; - if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ - || isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r') + if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ + || (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')) { break; } diff --git a/ndicapi_socket_unix.cxx b/ndicapi_socket_unix.cxx index e9e03ca..98fbee3 100644 --- a/ndicapi_socket_unix.cxx +++ b/ndicapi_socket_unix.cxx @@ -132,8 +132,8 @@ ndicapiExport int ndiSocketRead(NDISocketHandle socket, char* reply, int numberO } totalNumberOfBytesRead += numberOfBytesRead; - if (!isBinary && reply[totalNumberOfBytesRead - 1] == '\r' /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ - || isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r') + if ((!isBinary && reply[totalNumberOfBytesRead - 1] == '\r') /* done when carriage return received (ASCII) or when ERROR... received (binary)*/ + || (isBinary && strncmp(reply, "ERROR", 5) == 0 && reply[totalNumberOfBytesRead - 1] == '\r')) { break; } diff --git a/ndicapimodule.cxx b/ndicapimodule.cxx index 7342f86..3d18a50 100644 --- a/ndicapimodule.cxx +++ b/ndicapimodule.cxx @@ -25,6 +25,7 @@ #define PyString_Format PyUnicode_Format #define PyString_AsString PyUnicode_AsUTF8 #define PyIntObject PyLongObject + //#define PY_INT_OBJECT_OB_IVAL(ob) PyLong_AsLong((PyObject*)(ob)) #define PY_INT_OBJECT_OB_IVAL(ob) ob->ob_digit[0] #define cmpfunc PyAsyncMethods* #else @@ -150,7 +151,7 @@ bitfield_dealloc(PyIntObject* v) static int bitfield_print(PyIntObject* v, FILE* fp, int flags/* Not used but required by interface */) { - fprintf(fp, "0x%lX", PY_INT_OBJECT_OB_IVAL(v)); + fprintf(fp, "0x%lX", (unsigned long)PY_INT_OBJECT_OB_IVAL(v)); return 0; } @@ -158,7 +159,7 @@ static PyObject* bitfield_repr(PyIntObject* v) { char buf[20]; - sprintf(buf, "0x%lX", PY_INT_OBJECT_OB_IVAL(v)); + sprintf(buf, "0x%lX", (unsigned long)PY_INT_OBJECT_OB_IVAL(v)); return PyString_FromString(buf); } @@ -185,7 +186,7 @@ bitfield_invert(PyIntObject* v) static PyObject* bitfield_lshift(PyIntObject* v, PyIntObject* w) { - register unsigned long a, b; + register long a, b; a = PY_INT_OBJECT_OB_IVAL(v); b = PY_INT_OBJECT_OB_IVAL(w); if (b < 0) @@ -198,7 +199,7 @@ bitfield_lshift(PyIntObject* v, PyIntObject* w) Py_INCREF(v); return (PyObject*) v; } - if (b >= 8 * sizeof(long)) + if (b >= 8 * (long)sizeof(long)) { return PyNDIBitfield_FromUnsignedLong(0L); } @@ -209,7 +210,7 @@ bitfield_lshift(PyIntObject* v, PyIntObject* w) static PyObject* bitfield_rshift(PyIntObject* v, PyIntObject* w) { - register unsigned long a, b; + register long a, b; a = PY_INT_OBJECT_OB_IVAL(v); b = PY_INT_OBJECT_OB_IVAL(w); if (b < 0) @@ -222,7 +223,7 @@ bitfield_rshift(PyIntObject* v, PyIntObject* w) Py_INCREF(v); return (PyObject*) v; } - if (b >= 8 * sizeof(long)) + if (b >= 8 * (long)sizeof(long)) { if (a < 0) { a = -1; } @@ -546,7 +547,7 @@ static PyObject* Py_ndiGetError(PyObject* module, PyObject* args) static PyObject* Py_ndiErrorString(PyObject* module, PyObject* args) { int errnum; - char* result; + const char* result; if (PyArg_ParseTuple(args, "i:plErrorString", &errnum)) { @@ -560,7 +561,7 @@ static PyObject* Py_ndiErrorString(PyObject* module, PyObject* args) static PyObject* Py_ndiDeviceName(PyObject* module, PyObject* args) { int n; - char* result; + const char* result; if (PyArg_ParseTuple(args, "i:plDeviceName", &n)) { @@ -586,7 +587,7 @@ static PyObject* Py_ndiProbe(PyObject* module, PyObject* args) if (PyArg_ParseTuple(args, "s:plProbe", &device)) { - result = ndiSerialProbe(device); + result = ndiSerialProbe(device, false); return PyNDIBitfield_FromUnsignedLong(result); } @@ -732,7 +733,7 @@ static PyObject* Py_ndiCommand(PyObject* module, PyObject* args) return _ndiErrorHelper(ndiGetError(pol), obj); } -static PyObject* Py_ndiCommand2(PyObject* module, char* format, PyObject* args) +static PyObject* Py_ndiCommand2(PyObject* module, const char* format, PyObject* args) { int i, n; PyObject* newargs; @@ -792,6 +793,7 @@ PyCommandMacro(ndiPDIS, "PDIS:%c") PyCommandMacro(ndiTSTART, "TSTART:") PyCommandMacro(ndiTSTOP, "TSTOP:") PyCommandMacro(ndiGX, "GX:%04X") +PyCommandMacro(ndiBX, "BX:%04X") PyCommandMacro(ndiLED, "LED:%c%d%c") PyCommandMacro(ndiBEEP, "BEEP:%i") PyCommandMacro(ndiVER, "VER:%d") @@ -864,6 +866,35 @@ static PyObject* Py_ndiGetGXTransform(PyObject* module, PyObject* args) return NULL; } +static PyObject* Py_ndiGetBXTransform(PyObject* module, PyObject* args) +{ + char port; + int result; + float transform[8]; + ndicapi* pol; + + if (PyArg_ParseTuple(args, "O&c:plGetBXTransform", + &_ndiConverter, &pol, &port)) + { + result = ndiGetBXTransform(pol, port, transform); + + if (result == NDI_MISSING) + { + return PyString_FromString("MISSING"); + } + else if (result == NDI_DISABLED) + { + return PyString_FromString("DISABLED"); + } + + return Py_BuildValue("(dddddddd)", transform[0], transform[1], + transform[2], transform[3], transform[4], + transform[5], transform[6], transform[7]); + } + + return NULL; +} + static PyObject* Py_ndiGetGXPortStatus(PyObject* module, PyObject* args) { char port; @@ -880,6 +911,23 @@ static PyObject* Py_ndiGetGXPortStatus(PyObject* module, PyObject* args) return NULL; } + +static PyObject* Py_ndiGetBXPortStatus(PyObject* module, PyObject* args) +{ + char port; + int result; + ndicapi* pol; + + if (PyArg_ParseTuple(args, "O&c:plGetBXPortStatus", + &_ndiConverter, &pol, &port)) + { + result = ndiGetGXPortStatus(pol, port); + return PyNDIBitfield_FromUnsignedLong(result); + } + + return NULL; +} + static PyObject* Py_ndiGetGXSystemStatus(PyObject* module, PyObject* args) { int result; @@ -895,6 +943,23 @@ static PyObject* Py_ndiGetGXSystemStatus(PyObject* module, PyObject* args) return NULL; } + +static PyObject* Py_ndiGetBXSystemStatus(PyObject* module, PyObject* args) +{ + int result; + ndicapi* pol; + + if (PyArg_ParseTuple(args, "O&:plGetBXSystemStatus", + &_ndiConverter, &pol)) + { + result = ndiGetBXSystemStatus(pol); + return PyNDIBitfield_FromUnsignedLong(result); + } + + return NULL; +} + + static PyObject* Py_ndiGetGXToolInfo(PyObject* module, PyObject* args) { char port; @@ -971,6 +1036,22 @@ static PyObject* Py_ndiGetGXFrame(PyObject* module, PyObject* args) return NULL; } +static PyObject* Py_ndiGetBXFrame(PyObject* module, PyObject* args) +{ + char port; + unsigned long result; + ndicapi* pol; + + if (PyArg_ParseTuple(args, "O&c:plGetBXFrame", + &_ndiConverter, &pol, &port)) + { + result = ndiGetBXFrame(pol, port); + return PyLong_FromUnsignedLong(result); + } + + return NULL; +} + static PyObject* Py_ndiGetGXNumberOfPassiveStrays(PyObject* module, PyObject* args) { @@ -1398,6 +1479,18 @@ static PyMethodDef NdicapiMethods[] = Py_NDIMethodMacro(ndiGetGXNumberOfPassiveStrays), Py_NDIMethodMacro(ndiGetGXPassiveStray), + Py_NDIMethodMacro(ndiBX), + + Py_NDIMethodMacro(ndiGetBXTransform), + Py_NDIMethodMacro(ndiGetBXPortStatus), + Py_NDIMethodMacro(ndiGetBXSystemStatus), + //Py_NDIMethodMacro(ndiGetBXToolInfo), + //Py_NDIMethodMacro(ndiGetBXMarkerInfo), + //Py_NDIMethodMacro(ndiGetBXSingleStray), + Py_NDIMethodMacro(ndiGetBXFrame), + //Py_NDIMethodMacro(ndiGetBXNumberOfPassiveStrays), + //Py_NDIMethodMacro(ndiGetBXPassiveStray), + Py_NDIMethodMacro(ndiLED), Py_NDIMethodMacro(ndiBEEP), Py_NDIMethodMacro(ndiVER), @@ -1527,9 +1620,9 @@ ndicapiExport MOD_INIT(ndicapy) Py_NDIErrcodeMacro(NDI_ENVIRONMENT); - Py_NDIErrcodeMacro(NDI_EPROM_READ); - Py_NDIErrcodeMacro(NDI_EPROM_WRITE); - Py_NDIErrcodeMacro(NDI_EPROM_ERASE); + //Py_NDIErrcodeMacro(NDI_EPROM_READ); + //Py_NDIErrcodeMacro(NDI_EPROM_WRITE); + //Py_NDIErrcodeMacro(NDI_EPROM_ERASE); Py_NDIErrcodeMacro(NDI_BAD_CRC); Py_NDIErrcodeMacro(NDI_OPEN_ERROR);