private void InitComPort(int port) { com_port = new SerialPort(); com_port.Encoding = System.Text.Encoding.ASCII; com_port.RtsEnable = false; // kd5tfd hack for soft rock ptt com_port.DtrEnable = false; // set dtr off com_port.ErrorEvent += new SerialPorts.SerialEventHandler(this.SerialPort_Error); com_port.ReceivedEvent += new SerialPorts.SerialEventHandler(this.SerialPort_ReceivedData); com_port.PinChangedEvent += new SerialPorts.SerialEventHandler(this.SerialPort_PinChanged); com_port.PortName = "COM" + port.ToString(); com_port.Parity = SerialPorts.Parity.None; com_port.StopBits = SerialPorts.StopBits.One; com_port.DataBits = 8; com_port.BaudRate = 38400; com_port.ReadTimeout = 5000; com_port.WriteTimeout = 500; com_port.ReceivedBytesThreshold = 1; com_port.Open(); out_buffer = new byte[7]; out_buffer[0] = 0x02; Encoding.ASCII.GetBytes("D3", 0, 2, out_buffer, 1); out_buffer[3] = 0x03; byte crc = CRC(out_buffer); out_buffer[4] = ByteToAscii((byte)(crc>>4)); out_buffer[5] = ByteToAscii((byte)(crc&0x0F)); out_buffer[6] = 0x0D; }
public SDRSerialPort(int portidx) { commPort = new SerialPort(); commPort.Encoding = System.Text.Encoding.ASCII; commPort.RtsEnable = false; // kd5tfd hack for soft rock ptt commPort.DtrEnable = false; // set dtr off commPort.ErrorEvent += new SerialPorts.SerialEventHandler(this.SerialPortErrorEvent); commPort.ReceivedEvent += new SerialPorts.SerialEventHandler(this.SerialPortReceivedEvent); commPort.PinChangedEvent += new SerialPorts.SerialEventHandler(this.SerialPortPinChangedEvent); commPort.PortName = "COM" + portidx.ToString(); commPort.Parity = SerialPorts.Parity.None; commPort.StopBits = SerialPorts.StopBits.One; commPort.DataBits = 8; commPort.BaudRate = 9600; commPort.ReadTimeout = 5000; commPort.WriteTimeout = 500; commPort.ReceivedBytesThreshold = 1; }
public void Close() { try { if(com_port != null && com_port.IsOpen) com_port.Close(); } catch(Exception) { } com_port = null; }