Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem writing serial data to ASI stage

49 views
Skip to first unread message

Francesco Kut

unread,
Oct 25, 2010, 4:06:05 AM10/25/10
to
Hello,
I am having problems writing serial data to an ASI stage.
Code is simple:

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

Trent Jarvi

unread,
Oct 25, 2010, 9:41:10 AM10/25/10
to

"Francesco Kut" <heo...@gmail.com> wrote in message
news:ia3dpd$kep$1...@fred.mathworks.com...

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?


Francesco Kut

unread,
Oct 25, 2010, 10:53:04 AM10/25/10
to
Thank you Travis,
it is not the pause time the problem. I tried sending 5 steps and all the steps are completed on time.
My guess is I have a terminator problem, the instruction says:

"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

Trent Jarvi

unread,
Oct 25, 2010, 2:29:43 PM10/25/10
to

"Francesco Kut" <heo...@gmail.com> wrote in message
news:ia45kg$ais$1...@fred.mathworks.com...

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.


Francesco Kut

unread,
Oct 25, 2010, 7:05:06 PM10/25/10
to
Thank you for your advice,
I tried and checked also if the command through serial port was correct and it was.
But it does not work.
Thus I switched to high level with all the consequent problems.
Long story short:
for some reason the <CR> command at the end of line written with fprintf(serial,'CMD') does not go on the serial.
But: if you write fwrite(serial,['CMD',13]) where 13 is the ascii for <CR> (the terminator needed for high level commands).
and finally it works.
Without 13 the command does not send <CR>, using \r does not work.
Thank you for your help, hope somebody will find this useful.
0 new messages