Getting States


A command get is for getting states of a stepper motor.

Getting operation states

A command state is for getting an operation state of a stepper motor.

"get state"

Return values of this command are as follows:

value state
0 stopped
1 control locked
otherwise running
<?php
include_once "/lib/sd_spc.php";

spc_reset();
spc_sync_baud(115200);

$sid = 1;
spc_request_dev($sid, "set mode 4");
spc_request_dev($sid, "set vref stop 2");
spc_request_dev($sid, "set vref drive 8");
spc_request_dev($sid, "set speed 400");
spc_request_dev($sid, "set accel 800");
spc_request_dev($sid, "set rsnc 120 250");

$state = 0;
spc_request_dev($sid, "move 400");
while($state = (int)spc_request_dev($sid, "get state"))
{
  echo "state: $state\r\n";
  usleep(200000);
}
echo "state: $state\r\n";
?>
state: 2
state: 2
state: 2
state: 2
state: 2
state: 2
state: 2
state: 0

Getting a counter position

A command pos is for getting a current counter position of a stepper motor.

"get pos"

<?php
include_once "/lib/sd_spc.php";

spc_reset();
spc_sync_baud(115200);

$pos = -400;
$sid = 1;
spc_request_dev($sid, "set mode 4");
spc_request_dev($sid, "set vref stop 2");
spc_request_dev($sid, "set vref drive 8");
spc_request_dev($sid, "set speed 400");
spc_request_dev($sid, "set accel 800");
spc_request_dev($sid, "set rsnc 120 250");
spc_request_dev($sid, "set pos $pos");

spc_request_dev($sid, "goto 400");
while((int)spc_request_dev($sid, "get state"))
{
    $pos = (int)spc_request_dev($sid, "get pos");
  echo "position: $pos\r\n";
  usleep(200000);
}
?>
position: -400
position: -376
position: -317
position: -235
position: -153
position: -70
position: 12
position: 94
position: 175
position: 258
position: 336
position: 391

Getting a state of digital input ports

A command eio get is for getting a state of digital input ports.

"eio get (p) input"

The argument p means an ID(0 ~ 3) of digital input ports. Return values of this command are as follows:

value state
0 LOW
1 HIGH (default)
<?php
include_once "/lib/sd_spc.php";

spc_reset();
spc_sync_baud(115200);

$sid = 1;
while(1)
{
    echo spc_request_dev($sid, "eio get 0 input");
    echo spc_request_dev($sid, "eio get 1 input");
    echo spc_request_dev($sid, "eio get 2 input");
    echo spc_request_dev($sid, "eio get 3 input");

    echo "\r\n";
    sleep(1);
}
?>
1111  
0110  
...omitted...