public byte[] bpDisconn(ref BPLibApi.BPContext bPContext) { byte[] ret = null; try { IntPtr intPtrPack = BPLibApi.BP_PackDisconn(ref bPContext); BPLibApi.PackBuf packBufSend = (BPLibApi.PackBuf)Marshal.PtrToStructure(intPtrPack, typeof(BPLibApi.PackBuf)); ret = Tools.packBuf2Bytes(ref packBufSend); } catch (Exception e) { Console.Write(e.Message); ret = null; } return(ret); }
public static byte[] packBuf2Bytes(ref BPLibApi.PackBuf packBuf) { byte[] ret = null; try { ret = new byte[packBuf.MsgSize]; Marshal.Copy(packBuf.PackStart, ret, 0, ret.Length); } catch (Exception e) { Console.Write(e.Message); ret = null; } return(ret); }
public byte[] bpConnect(ref BPLibApi.BPContext bPContext, string sn, string passwd, ref string err) { byte[] ret = null; if (String.IsNullOrWhiteSpace(sn)) { err = "bpConnect: String.IsNullOrWhiteSpace(sn)"; return(ret); } if (null == passwd) { err = "bpConnect: null == passwd"; return(ret); } IntPtr snPtr = IntPtr.Zero; IntPtr passwordPtr = IntPtr.Zero; try { snPtr = Tools.mallocIntPtr(sn); passwordPtr = Tools.mallocIntPtr(passwd); IntPtr intPtrPack = BPLibApi.BP_PackConnect(ref bPContext, snPtr, passwordPtr); BPLibApi.PackBuf packBufSend = (BPLibApi.PackBuf)Marshal.PtrToStructure(intPtrPack, typeof(BPLibApi.PackBuf)); ret = Tools.packBuf2Bytes(ref packBufSend); } catch (Exception e) { Console.Write(e.Message); ret = null; } finally { Tools.freeIntPtr(snPtr); Tools.freeIntPtr(passwordPtr); } return(ret); }