Hi,
I have set up a connection on my serial port with a motor controller. When I command the motor as:
echo '#1p1000' > /dev/tts/0
everything works ok: motor starts to work as expected.
On this motor controller, I have a digital sensor connected to an input port which sends either LOW or HIGH. I can also query it:
echo 'A' > /dev/tts/0
how can I read the answer in Linux?
I tried:
echo < /dev/tts/0
but a blank line appears!
I also tried:
read LINE /dev/tts/0
after which Linux won't return the control to the prompt, as if it is waiting for data to appear on the serial port (then I use ctrl+c to break it).
I am sure that the motor controller is functioning and sensor is sending data properly, because I have tested it by a different board. So the only problem I have is the lack of Linux knowledge probably!
Also, I tried to read it in a program:
Code:
result1 = write(dev_tts0_fd, "A", 1);
if(result1<0)
{
printf("can't write to serial port\n");
exit(1);
}
sleep(1);
bytes_read = read (dev_tts0_fd, next_byte, sizeof (next_byte));
if(bytes_read<=0)
{
printf("can't read from serial port\n");
exit(1);
}
which returns: can't read from serial port!
Please give a hint!
Thank you!