I have a CyberGlove connected to Matlab via serial port. I am trying to write a command requesting a data sample, and then reading the sample back.
I have successfully connected the glove with the following code:
s = serial('/dev/ttyS0')
set(s,'BaudRate',115200)
fopen(s)
I can then write/read to get the sensor information either in binary or ascii.
In binary I am doing:
fwrite(s,'G')
fread(s)
fread
always times out and then spits out a column vector of seemingly random length (1-100+) containing meaningless integers.
With ASCII, the commands are:
fprintf(s,'g')
fscanf(s)
This gives an empty string as the read-out value. I know that the glove is getting and at least somewhat processing the commands, though, because if I give it an invalid command, I get back the error message e?
.
Here's the part that really confuses me, though: I accidentally discovered a way to get a correct reading from the glove.
fread(s)
(which times out and gives the seemingly random output)
fprintf(s,'g')
fscanf(s)
I then get the string output 'g 1 76 93 113 89 42 20 77 98 106 117 81 62 23 52 60 34 68 57 254 92 26'
, which is correct.
My questions are:
(1) Why does that last part produce a correct response?
(2) How can I get a reading from the binary command? This is what I actually want to acquire.
cat /dev/ttyS0
for reading andprintf ... > /dev/ttyS0
for writing. printf is a bash built-in. But first thing I'd recommend is to check the documentation of the device and see whether you understand everything. – A. Donda