Jump to content
OMRON Forums

How to create Microscan Links for input datums in perl scripts?


Recommended Posts

use perlutil;
use IntDm;
use DoubleDm;
use StringDm;
use StatusDm;
use Composite;

########################################################################################################################
########################################################################################################################
########################################################################################################################
###                                                                                                                  ###
###                                           Micrscan Link Example                                                  ###
###                                                                                                                  ###
###                                                Version 1.0                                                       ###
###                                                                                                                  ###
###                                               May 1st, 2015                                                      ###
###                                                                                                                  ###
########################################################################################################################
########################################################################################################################
########################################################################################################################
###
### MSLink:  This perl script demonstrates how you can configure various data types as Microscan Link inputs
###               
###
### 
###                 
###   Inputs:  
###    integer
###     float              
###     string            
###    boolean
###
###   Outputs:
###    integer
###     float              
###     string            
###    boolean
###
###


package MSLink;

#
# REGISTER this package so that perl steps know this package is available
#
perlutil::register("MSLink");

##################################################################################
BEGIN {
#
# STATUS FLAGS.   Used with Composite::SetStatusFlags() call.
#
    *ST_TRAINABLE            = \0x00000001;    # step or datum is trainable
    *ST_TRAINED            = \0x00000002;    # step or datum has been trained
    *ST_PARTCREATE            = \0x00000004;    # step creates a part
    *ST_STOP_ON_TRAIN        = \0x00000008;    # step needs to be set up (or moved) before training
    *ST_IS_EMBEDDED            = \0x00000010;    # composite is embedded in parent
    *ST_THREADED            = \0x00000020;    # step is threaded
    *ST_NEED_STAT_TRAIN        = \0x00000040;
    *ST_CAN_TUNE_PARAMS        = \0x00000080;
    *ST_DIRTY            = \0x00000100;    # composite is "dirty"
    *ST_ENABLED            = \0x00000200;    # composite is enabled
    *ST_INCLUDED_IN_RESULTS        = \0x00000400;    # composite is included in results uploaded from target
    #*ST_USES_MONSTER        = \0x00000800;    # uses monster resource.
    *ST_VIRGIN            = \0x00001000;    # composite has never been run
    *ST_FIELD            = \0x00002000;    # composite is a field
    *ST_DISABLE_PRECHECK        = \0x00004000;    # disable prechecking on this step/datum
    *ST_INCLUDED_IN_STREAM        = \0x00008000;    # do not stream this composite to disk/network
    *ST_SKIP_REGEN            = \0x00010000;  # do not attempt to follow references when building regen list
    *ST_HIDDEN            = \0x00020000;    # hide this object in the tree view (but show children)
    *ST_TIMING_ENABLE        = \0x00040000;    # this step contains timing diagnostics

# editability mask bits. Used with Composite::SetEditability() call.
    *EM_DATUM            = \0x01;    # editable as a datum
    *EM_REFDATUM            = \0x02;    # editable as a reference to a datum
    *EM_CANROTATE            = \0x04;    # valid for steps and shapes
    *EM_CANMOVE            = \0x08;    # valid for shapes
    *EM_CANSIZE            = \0x10;    # valid for shapes
    *EM_CANMASK            = \0x20;    # valid for steps
    *EM_RESULT            = \0x40;    # valid for output datums
    *EM_ENABLEREFEDIT        = \0x80;    # if ref editable, enable the reference editing
    *EM_NOUSERUPLOAD        = \0x100;    # if no user upload, the user can't select the
                                            #   datum as a result to upload, but it's automatically
                                            #   included in the uploaded results.
    *EM_VOLDATUM            = \0x200;    # datum is volatile, can be changed at runtime
    *EM_ALWAYSUPLOAD        = \0x400;    # always upload datum @ results upload time, even if step or datum has an error
    *EM_CANSCALE            = \0x800;    # can shape be scaled
    *EM_CANSTRETCH            = \0x1000;    # can shape be stretched linearly (rhombus)
    *EM_CAN_MODIFY_AT_RUNTIME    = \0x2000;    # can be modified by the user at runtime - no questions asked
    *EM_ASK_MODIFY_AT_RUNTIME    = \0x4000;    # ask parent step if datum can be modified at runtime
    *EM_ARRAYDATUM            = \0x8000;    # this datum is part of an array record

# Useful defines for IOListDm Types
    *IO_INPUT             = \1;
    *IO_OUTPUT             = \2;
    *IO_BOTH             = \3;
    *AVPIOTYPE_ALL            = \0; 
    *AVPIOTYPE_PHYSICAL        = \1; 
    *AVPIOTYPE_VIRTUAL        = \2; 
    *AVPIOTYPE_SENSOR        = \3; 
    *AVPIOTYPE_STROBE        = \4;
    *AVPIOTYPE_ANALOGOUT        = \5;
    *AVPIOTYPE_SLAVESENSOR        = \6;
    *AVPIOTYPE_TTLINPUT        = \7;
    *AVPIOTYPE_TTLOUTPUT        = \8;
    *AVPIOTYPE_RS422INPUT        = \9;
    *AVPIOTYPE_RS422OUTPUT        = \10;

# Useful defines for Datum list Types
    *INPUT_DATUM            = \0; 
    *OUTPUT_DATUM            = \1; 
    *RESOURCE_DATUM            = \2; 
    *INPUT_DATUMLIST        = \0;
    *OUTPUT_DATUMLIST        = \1;

# Useful defines for Debug Info Types
    *DWM_INFO            = \1;
    *DWM_WARNING            = \2;
    *DWM_SERIOUS            = \4;
    *DWM_LEVEL            = \15;
    *DWM_SHOWMSG            = \0x00010000;
    
#smart camera sensor resolutions
    *WVGA_WIDTH            = \752;
    *WVGA_HEIGHT            = \480;
    *SXGA_WIDTH            = \1280;
    *SXGA_HEIGHT            = \960;
    *WUXGA_WIDTH            = \2048;
    *WUXGA_HEIGHT            = \1088;
    
# Datum List references
    *RES_INT            = \0;
    *RES_FLOAT            = \1;
    *RES_STRING            = \2;
    *RES_BOOL            = \3;
    
    *OUT_INT            = \0;
    *OUT_FLOAT            = \1;
    *OUT_STRING            = \2;
    *OUT_BOOL            = \3;
}


########################################################################################################################
########################################################################################################################

sub FilterStepType
{
 ##use this sub if you want your script to only be listed for Custom Vision Tools or only for Custom Steps
 return 2;  # returning 0 means you want it listed for both types of steps
            # return 1 if your script should only be listed for Custom Vision Tools (has an input buffer and an ROI)
            # return 2 if your script should only be listed for Custom Steps (used for logic scripts only, has no ROI and no connection to the buffer)
}

########################################################################################################################
########################################################################################################################

sub Init
{     #one time initialization routine.  Similar to PreRun, but will only be called once, regardless of whether you're in setup or runtime mode
}

########################################################################################################################
########################################################################################################################

sub Cleanup
{    #complement to Init
}    

########################################################################################################################
########################################################################################################################

sub Apply
{    #called when ever your script is selected in the Custom Step or Custom Vision Tool's "Avail Package Scripts" list
    #it is here where you will create all of your input and output datums

    perlutil::clear_datum_lists;
    ################################################################################
    # add input datums
    
    perlutil::add_datum_int ($RESOURCE_DATUM,1, "intIn\nInteger", 0);            # 0        
    perlutil::add_datum_double ($RESOURCE_DATUM,1, "floatIn\nFloat", 0);        # 1
    perlutil::add_datum_string ($RESOURCE_DATUM,1, "stringIn\nString", 0);        # 2
    perlutil::add_datum_status ($RESOURCE_DATUM,1, "boolIn\nBoolean", 0);        # 3
            
    # add limits to input coordinate datums
    # These will need to be double-checked as they are going to be linked
    # to an external controller
    #######################################################
    #SET MIN/MAX LIMITS ON THOSE DATUMS THAT NEED IT
    my $datum = perlutil::get_datum(0,$RES_INT); 
    IntDm::SetMinValue($datum, -1000000000);     
    IntDm::SetMaxValue($datum, 1000000000);
    
    $datum = perlutil::get_datum(0,$RES_FLOAT); 
    DoubleDm::SetMinValue($datum, -1000000000.0);     
    DoubleDm::SetMaxValue($datum, 1000000000.0);

    #########################################################
    # OUTPUT DATUMS
    perlutil::add_datum_int ($OUTPUT_DATUM,1, "intOut\nInteger", 0);            # 0        
    perlutil::add_datum_double ($OUTPUT_DATUM,1, "floatOut\nFloat", 0);        # 1
    perlutil::add_datum_string ($OUTPUT_DATUM,1, "stringOut\nString", 0);        # 2
    perlutil::add_datum_status ($OUTPUT_DATUM,1, "boolOut\nBoolean", 0);        # 3
    
    #######################################################
    #SET MIN/MAX LIMITS ON THOSE DATUMS THAT NEED IT
    $datum = perlutil::get_datum(1,$OUT_INT); 
    IntDm::SetMinValue($datum, -1000000000);     
    IntDm::SetMaxValue($datum, 1000000000);
    
    $datum = perlutil::get_datum(1,$OUT_FLOAT); 
    DoubleDm::SetMinValue($datum, -1000000000.0);     
    DoubleDm::SetMaxValue($datum, 1000000000.0);
}

########################################################################################################################
########################################################################################################################

sub UIAction
{
    #make a note of all datums if you want to use them again after returning 1 from here
    
   return 0;
}

########################################################################################################################
########################################################################################################################

sub PreRun
{
    # make sure that all input datums can be linked
    my $i = 0;
    my $thisDm = 0;
    for ($i =0;$i< $RES_BOOL + 1;$i++)
    {
        $thisDm = perlutil::get_datum(0, $i);
        $currentFlags = Composite::GetEditability($thisDm);
        Composite::SetEditability( $thisDm , $currentFlags | $EM_CAN_MODIFY_AT_RUNTIME );
    }
    return 0;                        
}

########################################################################################################################
########################################################################################################################

sub Run
{
    my $passFlag = 0;
    my $int = perlutil::get_datum_int(0, $RES_INT);
    my $float = perlutil::get_datum_double(0,$RES_FLOAT);
    my $string = perlutil::get_datum_string(0,$RES_STRING);
    my $bool = perlutil::get_datum_status(0,$RES_BOOL);
    
    perlutil::set_datum_int($OUTPUT_DATUM, $OUT_INT, $int);
     perlutil::set_datum_double($OUTPUT_DATUM, $OUT_FLOAT, $float);
     perlutil::set_datum_string($OUTPUT_DATUM, $OUT_STRING, $string);
     perlutil::set_datum_status($OUTPUT_DATUM, $OUT_BOOL, $bool);
     
     perlutil::SetPassed($passFlag);
     return 0;
}

sub Draw
{
}

sub PostRun 
{
}

sub Update    

}

sub Start
{
}

sub Stop
{
}
                
return 1;
 

Software Version

2.0 & above

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...