On Mon, 1 Mar 2021 18:30:04 -0800 (PST), in
gmane.comp.hardware.beagleboard.user Piyush Raj ae19m009
<ae19m009-p/[email protected]> wrote:
>
> bytes_written = write(file, &transmit,6);
You are writing 6 bytes even though "HIGH\n" is only 5 characters (and
"LOW\n" is only 4!). That means you have 1 or 2 bytes of "garbage"
(whatever was in memory -- and since it appears the buffers are being
allocated on the stack that could mean anything). I'm also not sure of that
&transmit -- I thought char arrays automatically pass as the address of the
array.
> sleep(1);
> read_code= read(file,receive,10);
Here you are asking to read 10 bytes, even though you are only writing
4 or 5.
> if(bytes_written>0 && read_code>0 )
Here you only check that at least 1 byte was written and received...
And a 1 byte receive IS possible (I haven't found any documentation that
indicates how read() handles a serial port that does not have data in it...
It's possible that the outgoing port may still be sending [the
"bytes_written" may only indicate that the kernel buffered that many for
the sending device]).
I'd probably change the write() to specify strlen(transmit) AND confirm
that bytes_written = strlen(transmit). Similar for the read() operation --
check how many bytes were received.
--
Dennis L Bieber
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/8vgs3gp74f45g0iuccs01thu57kh5b2jir%404ax.com.