stagePort = serial('com1') %the only port
set(stagePort, 'baudrate', 9600, 'parity', 'none','databits', 8,'stopbits', 1,'outputbuffersize', 512,'inputbuffersize', 1024,'flowControl', 'none')
fopen(stagePort)
fwrite(stagePort, [char(255) char(66)]); %entering low level commands mode
pause(.5)
fwrite(stagePort, [char(24) char(45) char(0) char(58)]); %decrease X
pause(.5)
fwrite(stagePort, [char(24) char(43) char(0) char(58)]); %increase X
pause(.5)
fwrite(stagePort, [char(25) char(45) char(0) char(58)]); %decrease Y
pause(.5)
fwrite(stagePort, [char(25) char(43) char(0) char(58)]); %increase Y
fclose(stagePort)
delete(stagePort)
The stage moves with the first input, moves with the second input too but always in the same direction, does not move at all when I increase/decrease Y.
What am I doing wrong?
The commands are correct (from manual) but it seems like the signal out is always the same, no matter what I send.
For information I am on Vista 64bit using Matlab 2009b 32 bit.
Thank you
Hi Francesco
I just tested your code with an RS232 loopback connection to see what went
on the wire in your example. Everything looks fine:
ans =
255 66
ans =
24 45 0 58
ans =
24 43 0 58
ans =
25 45 0 58
ans =
25 43 0 58
Those are 8 bit bytes. Perhaps the stage needs more time to complete its
movement?
"Group 5: Last Byte This is a one-byte end-of-command character ':'. The MS-2000 will not recognize a command until this character is received. When the ':' is received, the MS-2000 goes to a subroutine which then pulls Groups 1-4 out of the serial port buffer, and then searches the buffer until the ':' is found. Any information between Group 4 and the ':' is ignored."
How is the terminator handled and how can I set it to be ':' in matlab?
Thank you,
Francesco
Hi Francesco,
Since you have 0's in your messages, I don't recommend using the terminator
character property of the serial object. Instead, just send the terminator
with fwrite.
fwrite(stagePort,[char(25) char(43) char(0) char(58) ';'])
I didn't understand the group 1-4 information mentioned. You will need to
decide where to send the terminator character. The example above just sends
it after a command.