Raspberry, bottom, and camera, top.底部是覆盆子,頂部是相機。 https://en.wikipedia.org/wiki/Raspberry_Pi是一台 35 美元的電腦;相機另加 25 美元。 新增電源和網路連接,即可遠端存取。 JMP 如何存取它?
在這個例子中,普林克(的一部分油灰suite)和 RunProgram(JMP 的一部分),將 JMP 連接到 Raspberry Pi 中的 Linux 命令列介面。 JMP 發送拉斯皮斯蒂爾命令,其參數告訴 Raspberry Pi 如何拍攝照片以及將其放置在何處,然後 JMP 關閉連接並從網路上的位置顯示圖片。
看https://community.jmp.com/t5/Uncharted/Can-JSL-talk-to-Linux/ba-p/33689使用非 Raspberry Linux 機器的類似想法。 問題之一是透過創建公鑰/私鑰對來避免密碼提示;我使用 puttygen(PuTTY 套件)來製作我的公鑰/私鑰對(未顯示),並且透過在 putty 中保存一個名為的配置文件,使我的 JSL 變得更加簡單相機;設定檔具有連接資訊:
PuTTY dialog high lighting load/save sessions and AuthPuTTY 對話框高照明負載/保存會話和身份驗證
PuTTY dialog showing private key in AuthPuTTY 對話方塊在 Auth 中顯示私鑰
Login using the public/private key使用公鑰/私鑰登錄
現在該設定檔也可用於普林克作為相機。 因此,這裡有一些用於登入的 JSL:
rp = RunProgram(
executable( "plink" ), // plink is part of the PuTTY toolset, a bit like SSH
options( "camerapi" ), // this is a saved session in PuTTY
ReadFunction(
Function( {this},
While( this << canread,
Write( this << read ); // stream output to JMP log window
Wait( .01 );
)
)
)
);此 JSL 離開RP持有一個在背景運行的 RunProgram 對象,等待 Raspberry 上的 shell 程式產生一些輸出...它將其複製到 JMP 日誌視窗:
The first yellow is a message from JMP; the last yellow is a prompt from the Raspberry第一個黃色是來自 JMP 的訊息;最後一個黃色是樹莓派的提示
白色日誌視窗包含與黑色外殼視窗相同的登入結果。 ESC 的東西會對輸出進行顏色編碼,所以我得到青色提示。 RunProgram 物件仍在等待將一些指令傳遞給 Raspberry Pi。 構造一個命令並發送它:
// filename builds a path known to the linux (raspberry pi) computer; it is
// actually a nfs mount from yet another computer. This filename is where the
// picture will be stored. The windows computer running JMP can access the
// NFS mount via the H: drive, which is being supplied through VirtualBox.
filename = "capture/picNoOptions.jpg";
// raspistill is a raspberry pi-specific linux command to take a picture
// using the camera attached to the raspberry pi. Because this is a
// command line interface the command must end with a newline, as if
// it was typed at the keyboard and ENTER was pressed.
command = "raspistill --timeout 1000 --nopreview --output " ||"/mnt/nfsc/upscale/"|| filename;
rp << Write( command || "\!n" ); // send the raspistill command, via the linux command line
這會在日誌視窗中產生更多輸出:
The command is in yellow, it runs silently, and prompts for another command該命令呈黃色,靜默運行,並提示輸入另一個命令
此時可關閉RunProgram連線;向正在運行的 shell 發送 exit 命令是徹底斷開連線的最佳方法:
// for RunProgram to end cleanly, the shell it is running must terminate
rp << Write( "exit\!n" ); // end the Linux shell session
同樣,有一些日誌視窗輸出:
The shell is now closed外殼現已關閉
JSL 的其餘部分將根據需要等待,然後進行清理:
// every thing above happened very quickly, but the raspistill and exit
// commands have not finished yet. ask the rp object, over and over, if
// the pipe of data from the shell back to JSL has been closed yet. Until
// the ReadEOF happens, RunProgram will not terminate nicely.
While( !(rp << isReadEOF), write("."); Wait( .25 ) ); // wait patiently while shell output goes to log
If( !(rp << canread) & !(rp << canwrite) & rp << isReadEOF,
rp = 0; // this will really make RunProgram go away
Write( "\!nDone" );
,
// possibly need to restart JMP, and possibly need to restart raspberry
Write( "\!nFailed to release rp" )
);因為我已經在等待輸出,所以它只是說“完成”。 您可能需要在之前新增 wait(0.1) if( 可以讀/可以寫/isReadEOF )每次都測試完成。
現在從網路上抓取圖片並展示一下:
img=newimage("h:/"||filename);
img<<SCALE></SCALE>
1/8 actual size, attic work space1/8實際尺寸,閣樓工作空間
這款相機非常基本,最大解析度為 2592x1944(我認為這是原始的 5M 相機,還有 8M 版本),但確實允許控制曝光時間和類比增益,並且可以從感測器檢索原始像素。