A command get is for getting states of a stepper motor.
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 full");
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: 3
state: 2
state: 2
state: 2
state: 2
state: 2
state: 2
state: 0
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 full");
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: -315
position: -233
position: -151
position: -68
position: 14
position: 96
position: 178
position: 260
position: 338
position: 392
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...