public static bool LSWrite(CSerialPort serial_port, byte port, byte[] tx_data, byte rx_data_length) { byte[] message = new byte[tx_data.Length + 5]; message[0] = 0x00; message[1] = (byte)DirectCommand.LSWrite; message[2] = port; message[3] = (byte)tx_data.Length; message[4] = rx_data_length; tx_data.CopyTo(message, 5); return serial_port.Send(message); }
public static byte LSGetStatus(CSerialPort serial_port, byte port) { byte[] message = new byte[3]; message[0] = 0x00; message[1] = (byte)DirectCommand.LSGetStatus; message[2] = port; byte[] reply = new byte[4]; if (!serial_port.Send(message, ref reply)) return 0; if (reply.Length != 4) return 0; return reply[3]; }
public static bool LSRead(CSerialPort serial_port, byte port, ref byte[] rx_data) { byte[] message = new byte[3]; message[0] = 0x00; message[1] = (byte)DirectCommand.LSRead; message[2] = port; byte[] reply = new byte[20]; if (!serial_port.Send(message, ref reply)) return false; if (reply.Length != 20) return false; Array.Resize(ref rx_data, reply[3]); Array.Copy(reply, 4, rx_data, 0, reply[3]); return true; }
public bool Connect(string port_name) { serial_port = new CSerialPort(); DeviceInfo = new CDeviceInfo(serial_port); InPort1 = new InPort(serial_port, 0); InPort2 = new InPort(serial_port, 1); InPort3 = new InPort(serial_port, 2); InPort4 = new InPort(serial_port, 3); comPort = port_name; Info = new Details(serial_port); DirectCommands = new Direct_Commands(serial_port); if (!serial_port.Connect(port_name)) return false; if (!serial_port.Send(DirectCommand.KeepAlive)) { Disconnect(); return false; } connected = true; return true; }