public bool Connect(int address) { if (fds.rfd <= 0) return false; di = new libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoPPI, libnodave.daveSpeed187k); libnodave.daveSetDebug(libnodave.daveDebugAll); dc = new libnodave.daveConnection(di, address, 0, 0); return 0 == dc.connectPLC(); }
static void UploadProgramBlock(string port, string baud, char parity, int address, out byte[] dest) { dest = null; try { fds.rfd = libnodave.setPort(port, baud, parity); fds.wfd = fds.rfd; if (fds.rfd > 0) { di = new libnodave.daveInterface(fds, "IF1", localPPI, libnodave.daveProtoPPI, libnodave.daveSpeed9k); //libnodave.daveSetDebug(libnodave.daveDebugAll); dc = new libnodave.daveConnection(di, address, 0, 0); if (0 == dc.connectPLC()) { int length = 65536; dest = new byte[length]; dc.getProgramBlock(libnodave.daveBlockType_OB, 1, dest, ref length); dest = dest.Take(length).ToArray(); } dc.disconnectPLC(); libnodave.closePort(fds.rfd); } else { Console.WriteLine("Couldn't open serial port "); } } catch (COMException e) { Console.Write(e.Message); } }
static void DownloadProgramBlock(string port, string baud, char parity, int address, byte[] dest) { try{ fds.rfd = libnodave.setPort(port, baud, parity); fds.wfd = fds.rfd; if (fds.rfd > 0) { di = new libnodave.daveInterface(fds, "IF1", localPPI, libnodave.daveProtoPPI, libnodave.daveSpeed187k); di.setTimeout(1000000); libnodave.daveSetDebug(libnodave.daveDebugAll); dc = new libnodave.daveConnection(di, address, 0, 0); if (0 == dc.connectPLC()) { dc.putProgramBlock(libnodave.daveBlockType_OB, 1, dest, dest.Count()); } dc.disconnectPLC(); libnodave.closePort(fds.rfd); } else { Console.WriteLine("Couldn't open serial port "); } } catch(COMException e) { Console.Write(e.Message); } }