private void button5_Click(object sender, EventArgs e) { byte[] CmdBuf = { 0xa5, 0xf0, 0x02, 0x00, 0x00, 0x57 }; if (SPLidar.IsOpen) { SPLidar.Write(CmdBuf, 0, 6); } }
private void stopScan() { byte[] CmdBuf = { 0xa5, 0x25 }; if (SPLidar.IsOpen) { SPLidar.Write(CmdBuf, 0, 2); } }
private void button2_Click(object sender, EventArgs e) { if (SPLidar.IsOpen) { SPLidar.Close(); button1.Enabled = true; button2.Enabled = false; } }
private void button1_Click(object sender, EventArgs e) { if (SPLidar.IsOpen) { return; } SPLidar.Open(); button2.Enabled = true; button1.Enabled = false; }
private void InitForm() { /*set Serial port name*/ foreach (string s in SerialPort.GetPortNames()) { comboBox1.Items.Add(s); } /*if item in comboBox is more than 1,show it*/ if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; SPLidar.PortName = comboBox1.SelectedItem.ToString(); Console.WriteLine("Serial Port is " + SPLidar.PortName); } comboBox2.Items.AddRange(new object[] { 4800, 9600, 19200, 38400, 115200, 460800 }); comboBox2.SelectedIndex = 4; /*initialize lidarSpeed */ lidarSpeed = 0; if (lidarSpeed > 1024) { lidarSpeed = 1024; } trackBar1.Value = lidarSpeed; textBox1.Text = lidarSpeed.ToString(); InitSPLidar(); /*open port, stop scan, start rotating*/ foreach (string s in SerialPort.GetPortNames()) { SPLidar.PortName = s; SPLidar.Open(); if (SPLidar.IsOpen) { stopScan(); updateSpeed(); stopScan(); SPLidar.Close(); } } /*close form1*/ Console.WriteLine("close this form automotive"); //this.Close(); }
private void updateSpeed() { byte[] CmdBuf = { 0xa5, 0xf0, 0x02, 0x58, 0x02, 0x0d }; CmdBuf[5] = (0xa5 ^ 0xf0 ^ 0x02); CmdBuf[3] = (byte)(lidarSpeed & 0xff); CmdBuf[5] ^= CmdBuf[3]; CmdBuf[4] = (byte)(lidarSpeed >> 8 & 0xff); CmdBuf[5] ^= CmdBuf[4]; if (SPLidar.IsOpen) { SPLidar.Write(CmdBuf, 0, 6); } }
private void button3_Click(object sender, EventArgs e) { byte[] CmdBuf = { 0xa5, 0xf0, 0x02, 0x58, 0x02, 0x0d }; CmdBuf[5] = (0xa5 ^ 0xf0 ^ 0x02); CmdBuf[3] = (byte)(lidarSpeed & 0xff); CmdBuf[5] ^= CmdBuf[3]; CmdBuf[4] = (byte)(lidarSpeed >> 8 & 0xff); CmdBuf[5] ^= CmdBuf[4]; if (SPLidar.IsOpen) { SPLidar.Write(CmdBuf, 0, 6); } }