julia
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| julia [2022/08/19 13:22] – created brandon | julia [2023/08/15 15:44] (current) – remove html comment, use ruby since it's close to Julia syntax, make file downloadable brandon | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| You can use the [[https:// | You can use the [[https:// | ||
| - | < | + | --> Here is an example script for the MS2000 and XY stage:# |
| + | |||
| + | **Last tested on Windows 10 64-Bit and Julia 1.8.0** | ||
| + | |||
| + | < | ||
| + | using LibSerialPort | ||
| + | |||
| + | # First open the Julia REPL and enter: | ||
| + | # using Pkg | ||
| + | # Pkg.add(" | ||
| + | # => This will install the LibSerialPort package | ||
| + | |||
| + | # get a list of serial ports | ||
| + | ports = get_port_list() | ||
| + | println(" | ||
| + | |||
| + | # setup serial port | ||
| + | port_name = " | ||
| + | baud_rate = 115200 | ||
| + | |||
| + | function serial_send(serial_port:: | ||
| + | write(serial_port, | ||
| + | if report | ||
| + | println(" | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function serial_readline(serial_port:: | ||
| + | line = readline(serial_port) | ||
| + | if report | ||
| + | println(" | ||
| + | end | ||
| + | return line | ||
| + | end | ||
| + | |||
| + | function serial_send_recv(serial_port:: | ||
| + | write(serial_port, | ||
| + | sleep(wait_time_sec) # 1 ms default | ||
| + | return readline(serial_port) | ||
| + | end | ||
| + | |||
| + | function wait_for_device(serial_port:: | ||
| + | if report | ||
| + | print(" | ||
| + | end | ||
| + | while is_device_busy(serial_port) | ||
| + | sleep(wait_time_sec) # 1 ms default | ||
| + | end | ||
| + | if report | ||
| + | println(" | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function wait_for_axis(serial_port:: | ||
| + | if report | ||
| + | print(" | ||
| + | end | ||
| + | while is_axis_busy(serial_port, | ||
| + | sleep(wait_time_sec) # 1 ms default | ||
| + | end | ||
| + | if report | ||
| + | println(" | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function is_device_busy(serial_port:: | ||
| + | if serial_send_recv(serial_port, | ||
| + | true | ||
| + | else | ||
| + | false | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function is_axis_busy(serial_port:: | ||
| + | if serial_send_recv(serial_port, | ||
| + | true | ||
| + | else | ||
| + | false | ||
| + | end | ||
| + | end | ||
| + | |||
| + | function move(serial_port:: | ||
| + | serial_send(serial_port, | ||
| + | serial_readline(serial_port) | ||
| + | end | ||
| + | |||
| + | function relative_move(serial_port:: | ||
| + | serial_send(serial_port, | ||
| + | serial_readline(serial_port) | ||
| + | end | ||
| + | |||
| + | function set_max_speed(serial_port:: | ||
| + | serial_send(serial_port, | ||
| + | serial_readline(serial_port) | ||
| + | end | ||
| + | |||
| + | function main() | ||
| + | # LibSerialPort.open defaults to => | ||
| + | # 8 data bits, no parity, one stop bit | ||
| + | LibSerialPort.open(port_name, | ||
| + | # banner request | ||
| + | serial_send(ms2k, | ||
| + | serial_readline(ms2k) | ||
| + | |||
| + | # adjust speed | ||
| + | set_max_speed(ms2k, | ||
| + | set_max_speed(ms2k, | ||
| + | |||
| + | # move in a square pattern | ||
| + | relative_move(ms2k, | ||
| + | wait_for_device(ms2k) | ||
| + | relative_move(ms2k, | ||
| + | wait_for_device(ms2k) | ||
| + | relative_move(ms2k, | ||
| + | wait_for_device(ms2k) | ||
| + | relative_move(ms2k, | ||
| + | wait_for_device(ms2k) | ||
| + | end | ||
| + | end | ||
| + | |||
| + | main() | ||
| </ | </ | ||
| + | <-- | ||
| + | |||
Address: 29391 W Enid Rd. Eugene, OR 97402, USA | Phone: +1 (541) 461-8181
julia.1660929725.txt.gz · Last modified: by brandon
