i’d like to suggest some changes to the ofSerial-code:
i think there shoudl be some value returned from the ofSerialSetup-function if the serial port was initialized correctly. i changed it to return a bool-value.
also i think there’s some bug in the OSX-version of that code. i think it should return immediately if there’s is some problem with initializing.
and i’d like a function to send a single byte via the serial port.
like this:
//----------------------------------------------------------------
int ofSerialWriteByte(unsigned char byte){
char str[2];
str[0] = byte;
str[1] = '\0';
if (!bInited){
printf("error: serial not inited\n");
return 0;
}
//---------------------------------------------
#ifdef TARGET_OSX
//---------------------------------------------
//int len = strlen(str);
int numWritten = write(fd, str, 1);
printf("numWritten %i \n", numWritten);
return numWritten;
//---------------------------------------------
#endif
//---------------------------------------------
//---------------------------------------------
#ifdef TARGET_WIN32
//---------------------------------------------
DWORD written;
//int len = (int)strlen(str);
if(!WriteFile(hComm,str,1,&written,0)){
printf("Can't write to com port");
return 0;
}
return (int)written;
//---------------------------------------------
#endif
//---------------------------------------------
}
best
joerg