8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/artoo/commands/socket.rb', line 8
def connect(name, port, retries = nil, baudrate = nil)
retries |= (1 + options[:retries].to_i)
baudrate |= options[:baudrate].to_i
system("socat -V &> /dev/null")
unless $?.success?
say "Socat not installed. Cannot bind serial to TCP."
say "Please install with 'artoo install socat' and try again."
return
end
case os
when :linux
run("sudo chmod a+rw /dev/#{name}")
while(retries > 0) do
run("socat -d -d FILE:/dev/#{name},nonblock,raw,b#{ baudrate },echo=0 TCP-LISTEN:#{port},fork")
break unless $? == 1
retries -= 1
end
when :macosx
while(retries > 0) do
run("socat -d -d -b#{ baudrate } FILE:/dev/#{name},nonblock,raw,echo=0 TCP-LISTEN:#{port},fork")
break unless $? == 1
retries -= 1
end
else
say "OS not yet supported..."
end
end
|