I'm hoping someone can share some light to what I'm doing wrong or rather, the proper way to do serial communication on the KRC2 (software version 5.2).
On the KUKA side, this is the code I have:
; Serial variables.
OFFSET = 0 ; Data offset.
TIMEOUT = 3.0 ; [s].
MR_T = #ABS ; Initialise active reading.
; -----------------------------------
; Main.
; -----------------------------------
; Open serial port.
COPEN(:SER_3, HANDLE)
IF (HANDLE == 0) THEN
HALT
ENDIF
; Read data.
; Start point.
OFFSET = 0
CREAD(HANDLE, SR_T, MR_T, TIMEOUT, OFFSET, "%F%F%F%F%F%F", P_x, P_y, P_z, P_a, P_b, P_c) ;
P_points[1].x = P_x ;
P_points[1].y = P_y ;
P_points[1].z = P_z ;
P_points[1].a = P_a ;
P_points[1].b = P_b ;
P_points[1].c = P_c ;
; End point.
OFFSET = 0
CREAD(HANDLE, SR_T, MR_T, TIMEOUT, OFFSET, "%F%F%F%F%F%F", P_x, P_y, P_z, P_a, P_b, P_c) ;
P_points[2].x = P_x ;
P_points[2].y = P_y ;
P_points[2].z = P_z ;
P_points[2].a = P_a ;
P_points[2].b = P_b ;
P_points[2].c = P_c ;
Display More
And I'm sending data via RS232 from MATLAB on another computer. The code is:
point = [0, 100, 200, 0, 90, 0];
% Serial parameters.
s = serial(COM, 'BaudRate', 9600, 'DataBits', 8, 'StopBits', 1, ...
'Parity', 'Even', 'FlowControl', 'Software');
% Open COM port.
fopen(s);
% Send data to KUKA.
str = sprintf('%f %f %f %f %f %f', ...
point(1), point(2), point(3), ...
point(4), point(5), point(6));
fprintf(s, '%s', str);
% Close COM Port.
fclose(s);
delete(s);
point = [0, 200, 200, 0, 90, 0];
% Serial parameters.
s = serial(COM, 'BaudRate', 9600, 'DataBits', 8, 'StopBits', 1, ...
'Parity', 'Even', 'FlowControl', 'Software');
% Open COM port.
fopen(s);
% Send data to KUKA.
str = sprintf('%f %f %f %f %f %f', ...
point(1), point(2), point(3), ...
point(4), point(5), point(6));
fprintf(s, '%s', str);
% Close COM Port.
fclose(s);
delete(s);
Display More
The reason I open/close the serial port on the MATLAB side for each send command is because if I don't, the data received on the KUKA side appears as one long string (from telnet), and the second read command on the KUKA side complains that there is no data available. My guess is I'm probably not applying the right terminator from the MATLAB side, but I'm not sure what to do. I've tried \r, \n, \r\n but with no luck.
The flow control is set to XONXOFF, and I've double checked all the serial settings and they match up. Sorry I am not at work right now so can't provide much more information, but if something is not clear please advise and I'll see what I can do tonight, otherwise I'll get the required information first thing tomorrow morning.
Many thanks.