1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. KUKA Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

Serial communication terminator

  • chocobo_ff
  • July 29, 2013 at 8:11 AM
  • Thread is Resolved
  • chocobo_ff
    Trophies
    3
    Posts
    32
    • July 29, 2013 at 8:11 AM
    • #1

    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:

    Code
    ; 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:

    Code
    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.

  • Online
    SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,421
    • July 29, 2013 at 6:28 PM
    • #2

    Hm. I don't know how you go about adding ASCII control codes to strings in MatLab, but I know that in KRL, I had to do it by using hex/integer codes and a string append. The integer ASCII number for \R is 13, and the code for \N is 10. So you need a way in MatLab to insert an integer into a string "raw," without that integer undergoing ASCII string conversion. I'm sure there's a MatLab function for this.

  • chocobo_ff
    Trophies
    3
    Posts
    32
    • July 29, 2013 at 10:58 PM
    • #3

    SkyeFire, could you please elaborate more on how you would do it in KRL? The next thing I need to do is send command back to an external PC, and I've done some quick tests, in MATLAB It says "Unsuccessful read: A timeout occurred before the Terminator was reached" (default terminator in MATLAB is \n). The serial port is set for synchronous writing, and the data was sent by:

    Code
    CWRITE(HANDLE,SW_T,MW_T,”%d”,IS_VALUE) ; INT IS_VALUE, IS_VALUE = 12345

    Also, going back to the reading on the KUKA side, I've tried appending \n, \r to the string from MATLAB, please see the first image for the values read by the KRC2 (output from telnet). The string shows various <0xD>, <0xA>, which I understand are \n and \r in hex form:

    Code
    SER[3]-RX: 0.000 ... 1.000000<0xD><0xA>0.000 ... etc ; data received in one string

    What I would like the robot to see is shown in the second image, where each string is treated separately, e.g.

    Code
    SER[3]-RX: -510... etc
    SER[3]-RX: -510... etc ; data received in two separate strings

    This could be due to the way I'm sending the data in MATLAB. Is the correct terminator \r, \n or \r\n ?

    Images

    • 2013-07-30 08.10.09.jpg
      • 2.47 MB
      • 4,000 × 2,250
      • 120
    • 2013-07-30 08.10.22.jpg
      • 2.2 MB
      • 4,000 × 2,250
      • 56

    Files

    2013-07-30 08.10.09.jpg_thumb 27.18 kB – 105 Downloads 2013-07-30 08.10.22.jpg_thumb 24.68 kB – 104 Downloads

    Edited once, last by chocobo_ff (July 29, 2013 at 11:02 PM).

  • chocobo_ff
    Trophies
    3
    Posts
    32
    • July 30, 2013 at 2:06 AM
    • #4

    Just a quick update, I think I've solved the problem of receiving data on the KUKA side, will post what I've done bit later when I have some free time, now just need to figure out how to append terminators when sending data from the KUKA side...

  • Online
    SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,421
    • July 30, 2013 at 11:30 PM
    • #5

    Here's some old test code I did that involved this question:

    SRC:

    Code
    &ACCESS RVP
    &REL 237
    &PARAM TEMPLATE = C:\KRC\Roboter\Template\ExpertVorgabe
    &PARAM EDITMASK = *
    DEF serial( )
    DECL BOOL Pass
    DECL INT CR, Comma1, Comma2, Comma3
    DECL CHAR Comma, MiscString[50]
    
    
    Pass = strclear(Result[])        ; Init receiving string
    Pass = strclear (Send_Command[]) ; Init Transmission string
    Pass = StrClear (MiscString[])
    
    
    CR=13       ; INT ASCII value of "Carriage Return"
    Comma = 44  ; INT ASCII value of a comma ","
    
    
    offset=0 ; SWRITE will work from first position of string
    SWRITE(Send_Command[], CH_State, Offset, "%s", VisionRequest[]) ; write command string to tx string
    IF ch_State.RET1 <> #CMD_OK THEN ; check success of SWRITE
      halt  ; halt if error
    ENDIF
    
    
    Offset = (( StrLen (Send_Command[])) +1 ) ; find end of string
    Send_command[Offset]=CR ; add [CR] to end of string
    
    
    halt
    
    
    COPEN (:SER_3, Handle) ; open serial port COM3
    
    
    CWRITE (Handle, TX_State, Mode, "%s", Send_Command[]) ; send TX string
    
    
    Mode = #ABS ; CREAD waits for data or timeout
    
    
    WAIT FOR ($DATA_SER3 <> 0) ; wait for data in COM3 buffer
    ;wait sec 5
    
    
    offset=0 ; start from string first character
    
    
    CREAD (Handle, RX_State, Mode, Timeout, Offset, "%s", Result[]) ; read serial buffer into RX string
    
    
    CCLOSE (Handle, CH_State) ; close serial channel
    
    
    halt
    
    
    Offset = 0 ; Start SREAD from first string character
    SREAD (Result[], CH_State, Offset, "%2s,%10f,%10f", MiscString[], X_Result, Y_Result) ; extract X and Y values from string, MiscString serves to remove "T1,"
    
    
    halt
    
    
    ; ================footnotes====================
    ; SREAD,SWRITE,CREAD,CWRITE, first string position uses Offset=0
    ; STRLEN, STRFIND, others, first string position is OFFSET=1, follow the same rule as an array[] variable
    ; Adding CR to string with SWRITE using %c doesn't work, need to research
    ; X and Y are both 10chars long, but need different %f sizes in SREAD to work out properly.  Need to research.
    
    
    END
    Display More

    DAT:

    Code
    &ACCESS RVP
    &REL 237
    &PARAM TEMPLATE = C:\KRC\Roboter\Template\ExpertVorgabe
    &PARAM EDITMASK = *
    DEFDAT  SERIAL PUBLIC
    
    
    
    
    DECL INT Handle=3
    DECL INT Offset=24
    DECL REAL Timeout=5.0
    DECL STATE_T TX_State={RET1 #CMD_OK,MSG_NO 0,HITS 1,LENGTH 0}
    DECL STATE_T RX_State={RET1 #DATA_BLK,MSG_NO 0,HITS 1,LENGTH 37}
    DECL STATE_T CH_State={RET1 #DATA_BLK,MSG_NO 0,HITS 3,LENGTH 2}
    DECL MODUS_T Mode=#ABS
    DECL CHAR VisionRequest[2]
    VisionRequest[]="T1"
    DECL CHAR Result[100]
    Result[]="T1,+00205.454,+00217.879,+0000205.467"
    DECL CHAR Send_Command[10]
    Send_Command[]="T1'H0D'"
    
    
    DECL REAL X_Result=205.453995
    DECL REAL Y_Result=217.878998
    
    
    ENDDAT
    Display More
  • chocobo_ff
    Trophies
    3
    Posts
    32
    • July 31, 2013 at 4:08 AM
    • #6

    Thanks SkyeFyre, that did the trick. It does seem strange that for something so simple, the amount of work required to get it to work...

  • LEDdiablo
    Trophies
    3
    Posts
    7
    • December 11, 2013 at 12:49 PM
    • #7

    Hy everybody!

    I have a similar problem with one of my projects. I tried a lots of things, but no success. The thing is that my KRL program runs once succesfully, but when i send the same messeage in the second cycle, i get the 1550 error: No more data/variables available. I know its something so freaking simple but i just keep missing it.

    Config: KR5 arc w KRC2
    OS ver.: 5.5.2.
    Baud 9600
    data bits 8
    stop bits 1
    parity even
    i tried Xon/Xoff and pure serial with the same results.
    I communicate it with a PC via USB-serial, I handle serial comm. on the PC side with a NI Labview VI and/or Terminals

    I attached my prog., pleas if somebody could take a peak in it!

    Files

    HUBABUBA.dat 4.51 kB – 47 Downloads HUBABUBA.src 3.42 kB – 78 Downloads

    Edited once, last by LEDdiablo (December 11, 2013 at 12:59 PM).

  • Online
    SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,421
    • December 11, 2013 at 10:20 PM
    • #8

    Where exactly does it fault? During the Open, Send, Rec, or Close?

  • LEDdiablo
    Trophies
    3
    Posts
    7
    • December 12, 2013 at 8:52 AM
    • #9

    In line 34, it's waiting for the data, but when i send a telegram it immadeitely stops with the 1550 error

  • LEDdiablo
    Trophies
    3
    Posts
    7
    • December 12, 2013 at 10:48 AM
    • #10

    I made another program since, but i get the same error. I monitored the variables, all seems to be right, but in the CREAD line i get the 1550. I think it's my unlucky number...

    I use the parameters (9600 baud, 8 bits, 1 stopbit, no parity) with no serial protocoll (on the KUKA: Xon/Xoff, the values are 0), and sending data via serial terminal. The robot gets the messeage that I send (1#013 and 2#013, which translates to 1CR and 2CR), recognises the CR (monitored the $data_ser3, i get 1 and 2). But the CREAD doesn't work...

    Files

    serial_2.src 679 Byte – 76 Downloads serial_2.dat 388 Byte – 45 Downloads
  • BRIES
    Trophies
    3
    Posts
    2
    • January 6, 2016 at 4:10 PM
    • #11
    Quote from chocobo_ff

    Also, going back to the reading on the KUKA side, I've tried appending \n, \r to the string from MATLAB, please see the first image for the values read by the KRC2 (output from telnet). The string shows various <0xD>, <0xA>, which I understand are \n and \r in hex form:

    Code
    SER[3]-RX: 0.000 ... 1.000000<0xD><0xA>0.000 ... etc ; data received in one string

    What I would like the robot to see is shown in the second image, where each string is treated separately, e.g.

    Code
    SER[3]-RX: -510... etc
    SER[3]-RX: -510... etc ; data received in two separate strings

    This could be due to the way I'm sending the data in MATLAB. Is the correct terminator \r, \n or \r\n ?


    I apologize for bringing back an old thread but this is the exact same problem I'm having trying to receive data from Matlab. It's showing up just like the first image, where all the received data shows up as a single string with hex terminators separating them. I've tried \r, \n, \r\n, \n\r without success.
    Chocobo_ff, how'd you solve this?

    Thanks

  • Spl
    Reactions Received
    5
    Trophies
    3
    Posts
    178
    • January 6, 2016 at 5:00 PM
    • #12

    Read the data in as floats and two characters instead of a string.

  • BRIES
    Trophies
    3
    Posts
    2
    • January 6, 2016 at 5:15 PM
    • #13
    Quote from Spl


    Read the data in as floats and two characters instead of a string.

    You're refering to the CREAD correct? I've tried that and it works fine if I'm only receiving one set of data, but when I receive 2 or more sets telnet shows it as: SER[3]-RX: 1.000 1.000 1.000 <0xD>2.000 2.000 2.000 <0xD>.... (<0xD> can be replaced with <0xA> or a combination of the two).
    Is this the preferable way to program this: CREAD (HANDLE, SR_T, MR_T, TIMEOUT, OFFSET, "%f %f %f %1r %f %f %f %1r", x[1], y[1], z[1], CR[1], x[2], y[2], z[2], CR[2])
    It would seem to be cumbersome once more data is received

    [edited grammatical error]

  • Spl
    Reactions Received
    5
    Trophies
    3
    Posts
    178
    • January 6, 2016 at 5:31 PM
    • #14

    Yes I'm referring to the CREAD, and you should use some type of loop or interrupt to read the data in. Unfortunately I don't have an example code at me right now, since I at home, but I can post it tomorrow.

    Added example codes for the serial communication from our old research project.

    Files

    serial_interrupt.src 4.78 kB – 85 Downloads serial_interrupt.dat 1.42 kB – 49 Downloads

    Edited once, last by Spl (January 7, 2016 at 7:41 AM).

  • amila.robise
    Trophies
    3
    Posts
    1
    • March 9, 2017 at 3:13 PM
    • #15

    :justice:

    I have started a project which is a master slave robot system with KUKA KR16 L6 robot in my university. I also having problems regarding communicating with KRC2 controller since this is my 1st time. could you please tell me the software applications from external PC side and KUKA robot side you used for communication. and how to send motor position angles to KUKA controller using an external PC...?

    I also planning to use RS232 communication method.

    Thanks in advance.

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download