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

PCDK Read numeric register in C#

  • AxelZ
  • July 8, 2022 at 9:41 AM
  • Thread is Unresolved
  • AxelZ
    Trophies
    1
    Posts
    3
    • July 8, 2022 at 9:41 AM
    • #1

    Hello all,


    I am trying to read the numeric registers of a robot via C#. The whole thing works as long as it is an integer. As soon as the register contains a floating point number an exception is thrown.

    Code excerpt:

    var numRegister = (myRobot.RegNumerics[1].Value.RegLong);


    If register 1 is an integer (e.g. 100) it works. If not then the following message appears: System.Runtime.InteropServices.COMException: "Register value is not of Integer type.

    Makes sense because the value is not an integer. Now my question.


    Does anyone know how I can read floating point numbers ? Or is that not possible ?


    Kind regards

  • Erik Olsen
    Reactions Received
    54
    Trophies
    5
    Posts
    177
    • July 9, 2022 at 5:55 PM
    • Best Answer
    • #2

    Unless I'm reading it wrong, I think it's because you are getting the register value using the "RegLong Property". Long data type is for integers only.

    The Fanuc PCDK documentation has a description for the property stating this:

    Quote

    FRCRegNumeric.RegLong Property

    Description:

    Returns/sets the long value for the numeric register.

    Syntax:

    [lngRegInt = ] objNumReg.RegLong

    Parts:

    objNumReg as FRCRegNumeric lngRegInt as Long

    Remarks:

    This property will raise an error if it is read when the type is not INTEGER (Type property is not frIntegerType). When this property is set the register type is automatically converted to INTEGER (Type property is set to frIntegerType).

    Display More

    To get the floating-point value of a numeric register, you will want to use the standard RegNumerics Property here:

    Quote

    FRCRobot.RegNumerics Property

    Description:

    Returns the robot numeric registers.

    Syntax:

    [objNumRegs = ]objRobot.RegNumerics

    Parts:

    objRobot as FRCRobot objNumRegs as FRCVars

    Remarks:

    This property provides access to the numeric registers of the controller. These registers are typically accessed from TP programs.

    See Also:

    FRCRobot Object Overview FRCVars Object Overview FRCVar Object Overview FRCRegNumeric Object Overview

    Code
    Example of getting the numeric registers 
    
    Dim objRobot as FRCRobot 
    Dim objNumRegs as FRCVars 
    Dim objNumReg as FRCVar 
    Dim objRegValue as FRCRegNumeric 
    Dim lngValue as Long 
    
    Set objRobot = New FRCRobot objRobot.Connect "robot1" 
    Set objNumRegs = objRobot.RegNumerics 
    Set objNumReg = objNumRegs(1) 
    Set objRegValue = objNumReg.Value 
    lngValue = objRegValue.RegLong
    Display More

    `Example of getting the numeric registers Dim objRobot as FRCRobot Dim objNumRegs as FRCVars Dim objNumReg as FRCVar Dim objRegValue as FRCRegNumeric Dim lngValue as Long Set objRobot = New FRCRobot objRobot.Connect "robot1" Set objNumRegs = objRobot.RegNumerics Set objNumReg = objNumRegs(1) Set objRegValue = objNumReg.Value lngValue = objRegValue.RegLong

    Display More

    All of this and more is available in the PCDK documentation that came with the dev kit download btw :winking_face: .

  • AxelZ
    Trophies
    1
    Posts
    3
    • July 13, 2022 at 9:05 AM
    • #3

    Hey Erik, thanks for the help. The solution is quite simple :face_with_tongue:

    var numRegister = myRobot.RegNumerics[1].Value.RegLong; --> returns the long value

    var numRegister = myRobot.RegNumerics[1].Value.RegFloat; --> returns the float value

    Thank you.

  • HawkME
    Reactions Received
    568
    Trophies
    11
    Posts
    3,268
    • July 13, 2022 at 1:54 PM
    • #4

    Registers can dynamically change from long to float based on usage. I would recommend putting it in a try/catch block and it fails then test for the other type.

  • AxelZ
    Trophies
    1
    Posts
    3
    • July 13, 2022 at 2:29 PM
    • #5

    Hey HawkME,

    thanks for the advice. I did excaly what you mentioned because i got that error. First i try to get the integer Value of a Register and if its not possible have a catch where i get the float value.

    Cheers

  • rankingofficer
    Reactions Received
    2
    Trophies
    3
    Posts
    8
    • September 20, 2022 at 9:17 AM
    • #6

    Use this: objRegValue.Type = FRETypeCodeConstants.frIntegerType

    If objRegValue.Type = FRETypeCodeConstants.frIntegerType Then

    numberList.Add(objRegValue.RegLong)

    Else

    numberList.Add(objRegValue.RegFloat)

    End If

  • superbei30
    Reactions Received
    1
    Trophies
    3
    Posts
    50
    • January 8, 2023 at 11:01 PM
    • #7

    Hi everyone,

    Does anyone know the syntax of c# code reading and writing values from and to the IOs?

    Thank you.

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

Similar Threads

  • PCDK, Linux, .NET Core, and RoboGuide

    • SkyeFire
    • January 11, 2018 at 2:43 PM
    • Fanuc Robot Forum
  • Read and change register value from c# app using pcdk.

    • Limburger
    • April 9, 2019 at 6:37 PM
    • Fanuc Robot Forum

Tags

  • PDCK C#
  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