Problem controlling motors with COM port

1 view (last 30 days)
Christopher
Christopher on 23 Jun 2014
Hi,
I am trying to control phyMOTION controller using MATLAB but without success. They work in the controller's own program and via NI MAX. I think the issue I have is the telegram format which is HEX. In NI MAX the telegram to move a motor forward works as follows: I enter: \0203.1-1:XX\03 and displayed is: \x0203.1-1:XX\x03 where \02 is the HEX code for STX (start text) and \03 is (end text). The rest of the telegram addresses the controller and motor and command etc.
When using MATLAB (taking care to close the communication to the COM port from NI MAX) if have tried:
vs = visa('ni','ASRL3::INSTR');
fopen(vs);
fprintf(vs, '%X','\0203.1+1:XX\03')
or as alternatives for the string fprintf(vs, '%X','\x0203.1+1:XX\x03') fprintf(vs, '\0203.1+1:XX\03')
or fprintf(vs, '%X','ETX03.1+1:XXSTX')
or as altnrnative to visa I have tried
vs= instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
as I said I thought the issue is the string as:
>>
sprintf('%X','ETX03.1+1:XXSTX')
ans =
45545830332E312B313A5858535458
and
>> sprintf('%X','\0203.1+1:XX\03')
ans =
5C303230332E312B313A58585C3033
not starting and ending with 02(HEX) and 03(HEX) as expected. However writign a string give:
testt =
0230332E312B313A585803
fprintf(vs, testt);
also did not work.
I have checked the Baud rate etc and all are set as expected.
Any ideas?
Thanks for your help,
Chris

Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Instrument Control Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!