Hello! I've been struggling to control a stepper motor from a webpage. The example program that does this 08.pes_2405_touch_rotate works well but I was trying to adapt it so I could just use html buttons to rotate the motor. My code in index.php is the same as the example with the following being different.
Added this function
And this html button
My task0.php looks like this:
My code doesn't seem to turn the stepper (it seems to do nothing) but I'm struggling to figure out what I'm doing wrong.
Thank you for your help!
Added this function
Code:
function raise_focus() { if(ws != null) if(ws.readyState == 1) ws.send(0, "-100\r\n"); //-100 sent just to test. Eventually it will be a variable }
Code:
<button id="raise" type="button" onclick="raise_focus();">Raise</button>
My task0.php looks like this:
Code:
<?php if(_SERVER("REQUEST_METHOD")) exit; // avoid php execution via http request include "/lib/sd_340.php"; include "/lib/sd_spc.php"; include "/lib/sn_tcp_ws.php"; define("STEPPER_SID", 1); define("STEPS_PER_REV", 200); // 200 steps per revolution (1.8 degree each step) define("SPEED_LOWER_LIMIT", 32); define("SPEED_UPPER_LIMIT", 100000); spc_reset(); spc_sync_baud(115200); spc_request_dev(STEPPER_SID, "set vref drive 12"); spc_request_dev(STEPPER_SID, "set mode 32"); ws_setup(0, "pes_2405_touch_rotate", "csv.phpoc"); while(1) { $rbuf = ""; if(ws_state(0) == TCP_CONNECTED) { $rlen = ws_read_line(0, $rbuf); $pos = (int)spc_request_dev(STEPPER_SID, "get pos"); if($rlen) { $pos += (int)$rbuf; spc_request_dev(STEPPER_SID, "goto $pos 2000 1000k"); } } } ?>
Thank you for your help!
Comment