pkg load "instrument-control" printf("scanning for possible arduinos\n"); ports = instrhwinfo ('serial') for i = 1:numel (ports) try s = {}; unwind_protect if isunix portname = ["/dev/" ports{i}]; else portname = ports{i}; endif printf("* trying comport %s\n", portname); s = serial (portname, 9600, 1); pause(2); hdr = uint8 ([ hex2dec("A5") 0 1 0]); len = srl_write (s, hdr); [tmpdataOut, tmpdataSize] = srl_read (s, 4) if tmpdataSize == 4 && tmpdataOut(1) == hex2dec("A5") && tmpdataOut(3) == 1 expectlen = tmpdataOut(4); [dataout, datasize] = srl_read (s, expectlen) board = dataout(4); printf(" ** found board %d\n", board); endif unwind_protect_cleanup if !isempty (s) srl_close (s); endif end_unwind_protect catch err # do nothing printf(" ** caught err: %s\n", err.message) end_try_catch endfor