1. BufferQueue
1)工程文件
QT = core
CONFIG += c++17 cmdline
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SDK/Lib64/ -lA3200C64
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SDK/Lib64/ -lA3200C64
INCLUDEPATH += $$PWD/../SDK/Include
INCLUDEPATH += $$PWD/../SDK/Bin64
INCLUDEPATH += $$PWD/../SDK/Bin64/ExamplesScript
DEPENDPATH += $$PWD/../SDK/Include
2)main
#include <stdio.h>
#include <tchar.h>
// Main include file
#include "A3200.h"
#include <QDebug>
// See the pre-build event to see the System Library dlls being copied to the output directory
#define NUM_LINES 10
#define LINE_SIZE 128
// This function will print whatever the latest error was
void PrintError();
int main(int argc, char **argv)
{
bool sameline=false;
int linecurrent =0;
int lineprev =0;
// Handle to give access to A3200
A3200Handle handle = NULL;
FILE * file = NULL;
char tmp[LINE_SIZE], command[LINE_SIZE * NUM_LINES];
int i;
// Number of lines left in the queue to execute
DOUBLE queueLineCount;
printf("Connecting to A3200. Initializing if necessary.\n");
if(!A3200Connect(&handle)) { PrintError(); goto cleanup; }
printf("Putting task into Queue mode.\n");
if(!A3200ProgramInitializeQueue(handle, TASKID_01)) { PrintError(); goto cleanup; }
file = fopen("file.txt", "r");
if(NULL == file)
{
printf("Failed to open file\n");
goto cleanup;
}
printf("Loading Queue with commands.\n");
qDebug() << "loading queue with commands";
while (!feof(file)) {
command[0] = '\0';
for(i = 0; i < NUM_LINES; i++) {
if(NULL == fgets(tmp, sizeof(tmp), file)) {
break;
}
strcat(command, tmp);
}
qDebug() << "command = " << command;
qDebug() << "before execute commands";
while(!A3200CommandExecute(handle, TASKID_01, command, NULL)) {
if (A3200GetLastError().Code == ErrorCode_QueueBufferFull) {
printf("\tBuffer is full, waiting for it to empty.\n");
qDebug() << "\tBuffer is full, waiting for it to empty.\n";
Sleep(1000);
} else { PrintError(); goto cleanup; }
}
qDebug() << "end execute commands";
}
printf("Sleeping while remaining commands execute.\n");
qDebug() << "Sleeping while remaining commands execute.\n";
if(!A3200StatusGetItem(handle, TASKID_01, STATUSITEM_QueueLineCount, 0, &queueLineCount)) { PrintError(); goto cleanup; }
while(0 != (int)queueLineCount ) {
Sleep(10);
if(!A3200StatusGetItem(handle, TASKID_01, STATUSITEM_QueueLineCount, 0, &queueLineCount)) { PrintError(); }
qDebug() << "queueLineCount" << queueLineCount;
}
cleanup:
if(NULL != file)
{
fclose(file);
}
if(NULL != handle) {
printf("Stopping using Queue mode.\n");
qDebug() << "Stopping using Queue mode.\n";
if(!A3200ProgramStop(handle, TASKID_01)) { PrintError(); }
if(!A3200MotionDisable(handle, TASKID_01, AXISMASK_00)) { PrintError(); }
if(!A3200Disconnect(handle)) { PrintError(); }
}
#ifdef _DEBUG
printf("Press ENTER to exit...\n");
qDebug() << "Press ENTER to exit...\n";
getchar();
#endif
return 0;
}
void PrintError() {
CHAR data[1024];
A3200GetLastErrorString(data, 1024);
printf("Error : %s\n", data);
qDebug() << data;
}
2.MessageCallback
1)工程文件
QT = core
CONFIG += c++17 cmdline
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SDK/Lib64/ -lA3200C64
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SDK/Lib64/ -lA3200C64
INCLUDEPATH += $$PWD/../SDK/Include
INCLUDEPATH += $$PWD/../SDK/Bin64
INCLUDEPATH += $$PWD/../SDK/Bin64/ExamplesScript
DEPENDPATH += $$PWD/../SDK/Include
2)主程序
#include <stdio.h>
#include <tchar.h>
// Main include file
#include "A3200.h"
// See the pre-build event to see the System Library dlls being copied to the output directory
// This function will print whatever the latest error was
void PrintError();
// This function will handle the MSGDISPLAY callback
ErrorData myMessageDisplay(A3200Handle, TASKID, MessageDisplayData*);
int main(int argc, char **argv)
{
// Handle to give access to A3200
A3200Handle handle = NULL;
// Structure with function pointers
MessageCallbackHandlers handlers;
printf("Connecting to A3200. Initializing if necessary.\n");
if(!A3200Connect(&handle)) { PrintError(); goto cleanup; }
printf("Initialing the structure, and registering only for MSGDISPLAY handling\n");
if(!A3200CallbackInitializeMessageHandlers(&handlers, sizeof(MessageCallbackHandlers))) { PrintError(); goto cleanup; }
handlers.messageDisplay = myMessageDisplay;
// multiple different handlers can be added here, messageDisplay is just an example
printf("Waiting for MSGDISPLAY on Task #1\n");
// This call is blocking
if(!A3200CallbackHandleMessageCallbacks(handle, TASKID_01, &handlers)) { PrintError(); goto cleanup; }
cleanup:
if(handle != NULL) {
if(!A3200Disconnect(handle)) { PrintError(); }
}
#ifdef _DEBUG
printf("Press ENTER to exit...\n");
getchar();
#endif
return 0;
}
ErrorData myMessageDisplay(A3200Handle handle, TASKID taskId, MessageDisplayData* data) {
// Print what we recieved
printf("MSGDISPLAY from task %d with priority %d : %s\n", taskId, data->priority, data->text);
// Release the main thread that is waiting for callbacks since we do not want to handle any more MSGDISPLAYs
if(!A3200CallbackWaitCancel(handle)) { PrintError(); }
// Any error we return from here will result in a task error
return A3200GetLastError();
}
void PrintError() {
CHAR data[1024];
A3200GetLastErrorString(data, 1024);
printf("Error : %s\n", data);
}
如果,Motion Compser打开,就会测试出报错信息:
Connecting to A3200. Initializing if necessary.
Initialing the structure, and registering only for MSGDISPLAY handling
Waiting for MSGDISPLAY on Task #1
Error : A callback error occurred: The callback was already registered, and only single registration is supported.
Press ENTER to exit...