namespace WindowsFormsApplication1{ public class ptpcam { [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern int CreateConsole(int show, int bus, int dev); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern int CloseConsole(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern int IsCamConnected(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern int IsConsoleReady(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern string GetDllVersion(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern string GetStdErr(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern string GetStdOut(); [DllImport("ptpcam.dll", CharSet = CharSet.Ansi)] public static extern int SendCommand(string stdin); } static class Program { ...
private void button1_Click(object sender, EventArgs e) { bool err = false; if (ptpcam.CreateConsole(0, 0, 0) == 1) { richTextBox1.AppendText("> ptpcam open\n"); int timeout = 30; //equal ~3 seconds while (ptpcam.IsCamConnected() != 1 && timeout > 0) { timeout--; Thread.Sleep(100); } err = (timeout == 0); if (!err) { while (ptpcam.IsConsoleReady() != 1) { Thread.Sleep(100); } string cmd = "luar get_buildinfo()"; int r_send = ptpcam.SendCommand(cmd); richTextBox1.AppendText(string.Format("send '{0}'; result = {1}\n", cmd, r_send)); if (r_send == 1) { richTextBox1.AppendText("--- receive begin ---\n"); while (ptpcam.IsConsoleReady() != 1) { Thread.Sleep(100); } string r_dll = ptpcam.GetStdOut(); richTextBox1.AppendText(r_dll + '\n'); richTextBox1.AppendText("--- receive end ---\n"); } else richTextBox1.AppendText("!!! ptpcam: send error\n"); } else richTextBox1.AppendText("!!! ptpcam: camera connection timeout\n"); ptpcam.CloseConsole(); richTextBox1.AppendText("> ptpcam closed\n"); } else richTextBox1.AppendText("!!! ptpcam: open error\n"); }
Started by zeno « 1 2 » Script Writing
Started by mattkime LUA Scripting
Started by bartek158 General Help and Assistance on using CHDK stable releases
Started by crzyn8 General Discussion and Assistance
Started by artem78 LUA Scripting