Write and Read from Ttyusb0, Can't Get Response

Read from ttyUSB0 in own thread

You have two bugs.

First, this code:

    result = read(conHandler, &buffer, size);

You read into the place where the address of buffer is stored rather than the buffer itself.

Second, you throw the results of read away, so you have no idea how many bytes you read. If the code is intended to read exactly size bytes, you need to do something like this:

    int total_read = 0;
do
{
result = read(conHandle, buffer + total_read, size - total_read);
if (result <= 0) return result;
total_read += result;
}
while (total_read < result);

Why my CGI Script can't access to ttyUSB0?

The command below solved my problem :

sudo adduser www-data dialout

Kill process that raises Device or resource busy: '/dev/ttyUSB0'?

You can use

$ fuser /dev/ttyUSB0

to list the PIDs of the processes using the file. Alternatively, if your fuser command supports it you can use the -k option to kill them.



Related Topics



Leave a reply



Submit