// Does the system allows us to place a lock on this file descriptor
if (fcntl(sp->fd, F_SETLK, &fl) == -1) {
// A conflicting lock is held by another process
+ free(sp);
return CLAIMED_SERIAL_PORT;
}
// Flush all lingering data that may exist
tcflush(sp->fd, TCIOFLUSH);
+ // set speed, works for UBUNTU 14.04
+ bool err = uart_set_speed(sp, 460800);
+ if (!err)
+ uart_set_speed(sp, 115200);
+
return sp;
}
fl.l_start = 0;
fl.l_len = 0;
fl.l_pid = getpid();
- fcntl(spu->fd, F_SETLK, &fl);
+
+ // Does the system allows us to place a lock on this file descriptor
+ int err = fcntl(spu->fd, F_SETLK, &fl);
+ if ( err == -1) {
+ //perror("fcntl");
+ }
close(spu->fd);
free(sp);
}
if (res < 0) {
return false;
}
-
+
// Read time-out
if (res == 0) {
if (*pszRxLen == 0) {
return true;
}
}
-
+
// Retrieve the count of the incoming bytes
res = ioctl(((serial_port_unix*)sp)->fd, FIONREAD, &byteCount);
if (res < 0) return false;
-
+
// There is something available, read the data
res = read(((serial_port_unix*)sp)->fd,pbtRx+(*pszRxLen),byteCount);
-
+
// Stop if the OS has some troubles reading the data
if (res <= 0) return false;
-
+
*pszRxLen += res;
+
+ if(res==byteCount)
+ return true;
} while (byteCount);
-
+
return true;
}
// Write error
if (res < 0) {
- return false;
+ printf("write error\n");
+ return false;
}
// Write time-out
if (res == 0) {
- return false;
+ printf("write time-out\n");
+ return false;
}
// Send away the bytes
res = write(((serial_port_unix*)sp)->fd,pbtTx+szPos,szTxLen-szPos);
// Stop if the OS has some troubles sending the data
- if (res <= 0) return false;
+ if (res <= 0) {
+ printf("os troubles\n");
+ return false;
+ }
szPos += res;
}
// Prepare the device control
memset(&sp->dcb, 0, sizeof(DCB));
sp->dcb.DCBlength = sizeof(DCB);
- if(!BuildCommDCBA("baud=9600 data=8 parity=N stop=1",&sp->dcb)) {
- uart_close(sp);
- return INVALID_SERIAL_PORT;
- }
+ if(!BuildCommDCBA("baud=115200 parity=N data=8 stop=1",&sp->dcb)) {
+ uart_close(sp);
+ return INVALID_SERIAL_PORT;
+ }
// Update the active serial port
if(!SetCommState(sp->hPort,&sp->dcb)) {
uart_close(sp);
return INVALID_SERIAL_PORT;
}
-
- sp->ct.ReadIntervalTimeout = 0;
- sp->ct.ReadTotalTimeoutMultiplier = 0;
+ // all zero's configure: no timeout for read/write used.
+ sp->ct.ReadIntervalTimeout = 0;//1;
+ sp->ct.ReadTotalTimeoutMultiplier = 0;//1;
sp->ct.ReadTotalTimeoutConstant = 30;
- sp->ct.WriteTotalTimeoutMultiplier = 0;
+ sp->ct.WriteTotalTimeoutMultiplier = 0;//1;
sp->ct.WriteTotalTimeoutConstant = 30;
if(!SetCommTimeouts(sp->hPort,&sp->ct)) {
PurgeComm(sp->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
+ bool err = uart_set_speed(sp, 460800);
+ if (!err)
+ uart_set_speed(sp, 115200);
+
return sp;
}
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) {
DWORD dwTxLen = 0;
- return WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,szTxLen,&dwTxLen,NULL);
+ return WriteFile(((serial_port_windows*)sp)->hPort, pbtTx, szTxLen, &dwTxLen, NULL);
return (dwTxLen != 0);
}