public MainWindow() { InitializeComponent(); serialPort1 = new ReliableSerialPort("COM9", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One); serialPort1.Open(); serialPort1.DataReceived += SerialPort1_DataReceived; timerAffichage = new System.Windows.Threading.DispatcherTimer(); timerAffichage.Tick += TimerAffichage_Tick; timerAffichage.Interval = new TimeSpan(0, 0, 0, 0, 100); timerAffichage.Start(); m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker()); m_KeyboardHookManager.Enabled = true; m_KeyboardHookManager.KeyDown += HookManager_KeyDown; WorldMap.Init(3.6, 2.4, 3, 2, ""); var robotShape = new WpfSimplifiedWorldMapDisplayNS.PolygonExtended(); robotShape.polygon.Points.Add(new Point(0.2, 0)); robotShape.polygon.Points.Add(new Point(0.1, 0.1)); robotShape.polygon.Points.Add(new Point(-0.1, 0.1)); robotShape.polygon.Points.Add(new Point(-0.1, -0.1)); robotShape.polygon.Points.Add(new Point(0.1, -0.1)); robotShape.polygon.Points.Add(new Point(0.2, 0)); WorldMap.SetRobotShape(robotShape); WorldMap.UpdateRobotLocation(new WpfSimplifiedWorldMapDisplayNS.Location(robot.xpos, robot.ypos, robot.angle, 0, 0, 0)); //AsservDisplay.UpdatePolarSpeedConsigneValues(consigneX, consigneY, consigneTheta); }
public void ConnectToSerialAvailable(string COM) { serialPort = new ReliableSerialPort(COM, 115200, Parity.None, 8, StopBits.One); serialPort.OnDataReceivedEvent += SerialPort_OnDataReceived; serialPort.Open(); OnSerialConnected(COM); }
public MainWindow() { InitializeComponent(); Comport.DataReceived += Comport_DataReceived; Comport.Open(); }
//updates the port when selected private void listBox_avPorts_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { serialPort.Close(); serialPort.PortName = listBox_avPorts.SelectedItem.ToString(); serialPort.Open(); } catch (Exception) { serialPort.PortName = " "; } }
public MainWindow() { InitializeComponent(); serialPort1 = new ReliableSerialPort("COM4", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One); serialPort1.DataReceived += SerialPort1_DataReceived1; serialPort1.Open(); timerAffichage = new DispatcherTimer(); timerAffichage.Interval = new TimeSpan(0, 0, 0, 0, 100); timerAffichage.Tick += TimerAffichage_Tick; timerAffichage.Start(); }
static void Main(string[] args) { ////block logic SerialStream.DataReceived += MsgDecoder.DecodeMessage; MsgDecoder.OnDataDecodedEvent += MsgProcessor.ProcessMessage; //MsgEncoder.UartSendSpeedCommand(SerialStream, 0, 0); if (usingRobotInterface) { StartRobotInterface(); } SerialStream.Open(); ConsoleWriteColoredText("Initialized", ConsoleColor.Yellow); while (appLocked) { Console.Write(">"); userInputCommand = Console.ReadLine(); splittedCommand = ProcessUserCommand(userInputCommand); switch (splittedCommand[0]) { case "SetSpeed": robot.vitesseAngulaireConsigne = Convert.ToSByte(splittedCommand[1]); MsgEncoder.UartSendSpeedCommand(SerialStream, Convert.ToSByte(splittedCommand[1]), Convert.ToSByte(splittedCommand[2])); break; case "anglSpeed": robot.vitesseLineaireConsigne = Convert.ToSByte(splittedCommand[1]); MsgEncoder.UartSendAngularSpeedConsigne(SerialStream, Convert.ToSByte(splittedCommand[1])); break; case "linSpeed": MsgEncoder.UartSendLinearSpeedConsigne(SerialStream, Convert.ToSByte(splittedCommand[1])); break; case "st": MsgEncoder.UartSendSpeedCommand(SerialStream, 0, 0); break; default: ConsoleWriteColoredText("Unknown command : '" + splittedCommand[0] + "'", ConsoleColor.Red); break; } } //Thread.CurrentThread.Join(); }
public MainWindow() { InitializeComponent(); /*----------------------------Init du port série + évenement datareceived------------------------------------*/ serialPort1 = new ReliableSerialPort("COM8", 115200, Parity.None, 8, StopBits.One); //entrée USB à droite serialPort1.DataReceived += SerialPort1_DataReceived; serialPort1.Open(); /*-----------------------------------------------------------------------------------------------------------*/ /*-----------------------------------Init Timer-------------------------*/ timerAffichage = new DispatcherTimer(); timerAffichage.Interval = new TimeSpan(0, 0, 0, 0, 100); timerAffichage.Tick += TimerAffichage_Tick; timerAffichage.Start(); } /*-----------------------------------------------------------------------*/
public MainWindow() { InitializeComponent(); serialPort1 = new ReliableSerialPort("COM5", 115200, Parity.None, 8, StopBits.One); serialPort1.DataReceived += SerialPort1_DataReceived; serialPort1.Open(); timerAffichage = new DispatcherTimer(); timerAffichage.Interval = new TimeSpan(0, 0, 0, 0, 100); timerAffichage.Tick += TimerAffichage_Tick; timerAffichage.Start(); m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker()); m_KeyboardHookManager.Enabled = true; m_KeyboardHookManager.KeyDown += HookManager_KeyDown; }
private void buttonSerial_Click(object sender, RoutedEventArgs e) { string select = comboSerial.Text; if (select != "Null" && comboSerial.SelectedItem != null) { if (serialPort != null) { // Can't close the serial //serialPort.Close(); } else { serialPort = new ReliableSerialPort(select, 115200, Parity.None, 8, StopBits.One); serialPort.DataReceived += SerialPort_DataReceived; serialPort.Open(); } } }
public MainWindow() { InitializeComponent(); robot = new Robot(); serialPort = new ReliableSerialPort("COM19", 115200, Parity.None, 8, StopBits.One); serialPort.DataReceived += SerialPort_DataReceived; serialPort.Open(); timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 100); timer.Tick += Timer_Tick; timer.Start(); m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker()); m_KeyboardHookManager.Enabled = true; m_KeyboardHookManager.KeyDown += M_KeyboardHookManager_KeyDown; m_KeyboardHookManager.KeyUp += M_KeyboardHookManager_KeyUp; }
private void Init() { _status = STATUS.Searching; if (_stream != null) { // TODO: Remove write to logfile! Console.WriteLine("Write to file"); _bw = new BinaryWriter(_stream); } if (_settingsSerial == null) { _settingsSerial = new SettingsSerial(); } _serialPort = new ReliableSerialPort(_settingsSerial.PortName, _settingsSerial.BaudRate, _settingsSerial.Parity, _settingsSerial.DataBits); _serialPort.Open(); _stream = _serialPort.BaseStream; }
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (isPortSelected == false) { if (serialPort1 == null && comboBox.SelectedItem != null && comboBox.Text != null) { serialPort1 = new ReliableSerialPort(comboBox.SelectedItem.ToString(), 115200, Parity.None, 8, StopBits.One); //entrée USB à droite serialPort1.DataReceived += SerialPort1_DataReceived; serialPort1.Open(); //On change la fonction de la comboBox isPortSelected = true; comboBox.Items.Clear(); comboBox.Items.Add("Text"); comboBox.Items.Add("Led"); comboBox.Items.Add("Speed"); comboBox.Items.Add("State"); comboBox.Items.Add("Single byte"); comboBox.SelectedItem = comboBox.Items[0]; AutomaticMode_Click(sender, e); //UartEncodeAndSendMessage(0x0052, 1, new byte[] { (byte) 0}); } } else { } /*----------------------------Init du port série + évenement datareceived------------------------------------*/ //serialPort1 = new ReliableSerialPort("COM7", 115200, Parity.None, 8, StopBits.One); //entrée USB à droite //serialPort1.DataReceived += SerialPort1_DataReceived; //serialPort1.Open(); /*-----------------------------------------------------------------------------------------------------------*/ }
public HerkulexController(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits) { serialPort = new ReliableSerialPort(portName, baudRate, parity, dataBits, stopBits); decoder = new HerkulexDecoder(); DequeueThread = new Thread(new ThreadStart(DequeueFrames)); DequeueThread.Start(); serialPort.DataReceived += decoder.DecodePacket; decoder.OnRamReadAckEvent += Decoder_OnRamReadAckEvent; decoder.OnRamWriteAckEvent += Decoder_OnRamWriteAckEvent; decoder.OnIjogAckEvent += Decoder_OnIjogAckEvent; decoder.OnSjogAckEvent += Decoder_OnSjogAckEvent; decoder.OnStatAckEvent += Decoder_OnStatAckEvent; serialPort.Open(); Task TaskA = Task.Run(() => { while (true) { Thread.Sleep(10); } }); //starts 500ms after instanciation PollingTimer = new System.Threading.Timer((c) => { PollingTimerThreadBlock.WaitOne(); foreach (var key in Servos.Keys) { RAM_READ(key, HerkulexDescription.RAM_ADDR.Absolute_Position, 2); RamReadAckReceivedEvent.WaitOne(AckTimeout); } }, null, 500, PollingInterval); }
public MainWindow() { InitializeComponent(); SerialStream = new ReliableSerialPort("COM6", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One); FrameDecoder = new msgDecoder(); FrameProcessor = new msgProcessor(); UI_Updater = new DispatcherTimer(); UI_Updater.Interval = new TimeSpan(0, 0, 0, 0, 100); //100ms tick RobotModel = new robot(); //block logic UI_Updater.Tick += UpdateUI; SerialStream.DataReceived += FrameDecoder.DecodeMessage; FrameDecoder.OnDataDecodedEvent += FrameProcessor.ProcessMessage; FrameProcessor.OnTextMessageProcessedEvent += FrameProcessor_OnTextMessageProcessedEvent; FrameProcessor.OnCheckSumErrorOccuredEvent += FrameProcessor_OnCheckSumErrorOccuredEvent; FrameProcessor.OnIrMessageProcessedEvent += FrameProcessor_OnIrMessageProcessedEvent; FrameProcessor.OnSpeedMessageProcessedEvent += FrameProcessor_OnSpeedMessageProcessedEvent; SerialStream.Open(); UI_Updater.Start(); }
static void Main(string[] args) { HrController.port = ComPort; ComPort.DataReceived += HrDecoder.DecodePacket; HrDecoder.OnDataDecodedEvent += HrDecoder.ProcessPacket; HrDecoder.OnStatAckEvent += HrDecoder_OnStatAckEvent; HrDecoder.OnIjogAckEvent += HrDecoder_OnIjogAckEvent; HrDecoder.OnSjogAckEvent += HrDecoder_OnSjogAckEvent; HrDecoder.OnRamReadAckEvent += HrDecoder_OnRamReadAckEvent; HrDecoder.OnEepReadAckEvent += HrDecoder_OnEepReadAckEvent; ComPort.Open(); while (lockShell) { Console.Write('>'); string[] parsedCmd = ParseShellCmd(Console.ReadLine()); switch (parsedCmd[0]) { case "REBOOT": if (parsedCmd.Length == 1) { Console.WriteLine("REBOOT <pID>"); } else { HrController.REBOOT(Convert.ToByte(parsedCmd[1])); } break; case "ROOLBACK": if (parsedCmd.Length == 1) { Console.WriteLine("ROLLBACK <ID>"); } else { HrController.ROLLBACK(Convert.ToByte(parsedCmd[1])); } break; case "EEP_WRITE": if (parsedCmd.Length == 1) { Console.WriteLine("EEP_WRITE <pID> <StartAddr> <Length> <DataDecimal>"); } else { HrController.EEP_WRITE(Convert.ToByte(parsedCmd[1]), Convert.ToByte(parsedCmd[2]), Convert.ToByte(parsedCmd[3]), Convert.ToUInt16(parsedCmd[4])); } break; case "EEP_READ": if (parsedCmd.Length == 1) { Console.WriteLine("EEP_READ <pID> <StartAddr> <Length>"); } else { HrController.EEP_READ(Convert.ToByte(parsedCmd[1]), Convert.ToByte(parsedCmd[2]), Convert.ToByte(parsedCmd[3])); } break; case "STAT": if (parsedCmd.Length == 1) { Console.WriteLine("STAT <pID>"); } else { HrController.STAT(Convert.ToByte(parsedCmd[1])); } break; //for testing incredible things case "debug": if (parsedCmd.Length == 1) { Console.WriteLine("debug <JOG1> <JOG2>"); } else { Ser1Config.JOG = Convert.ToUInt16(parsedCmd[1]); Ser2Config.JOG = Convert.ToUInt16(parsedCmd[2]); ROBOT_ARM_CONFIG = new List <JOG_TAG> { Ser1Config, Ser2Config }; HrController.S_JOG(ROBOT_ARM_CONFIG, 0x3C); } break; //implemented, working case "moveto": if (parsedCmd.Length == 1) { Console.WriteLine("moveto <ID> <JOG>"); } else { floatingConfig.ID = Convert.ToByte(parsedCmd[1]); floatingConfig.JOG = Convert.ToUInt16(parsedCmd[2]); HrController.S_JOG(floatingConfig, 10); } break; case "GetPos": if (parsedCmd.Length == 1) { Console.WriteLine("GetPos <pID>"); } else { HrController.RAM_READ(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Absolute_Position, 2); } break; //implemented, working case "torqueControl": if (parsedCmd.Length == 1) { Console.WriteLine("torqueControl <ID> <TRK_ON, BRK_ON, TRK_FREE>"); } else { if (parsedCmd[2] == "TRK_ON") { HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Torque_Control, 1, 0x60); } if (parsedCmd[2] == "BRK_ON") { HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Torque_Control, 1, 0x40); } if (parsedCmd[2] == "TRK_FREE") { HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Torque_Control, 1, 0x00); } } break; case "RAM_READ": if (parsedCmd.Length == 1) { Console.WriteLine("RAM_READ <pID> <StartAddr> <Length>"); } else { HrController.RAM_READ(Convert.ToByte(parsedCmd[1]), Convert.ToByte(parsedCmd[2]), Convert.ToByte(parsedCmd[3])); } break; case "RAM_WRITE": if (parsedCmd.Length == 1) { Console.WriteLine("RAM_WRITE <pID> <StartAddr> <Length> <Value> {ADDR 48 / 49 for error status}"); } else { HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), Convert.ToByte(parsedCmd[2]), Convert.ToByte(parsedCmd[3]), Convert.ToUInt16(parsedCmd[4])); } break; case "initPos": floatingConfig.ID = 1; floatingConfig.JOG = 512; floatingConfig.playTime = 100; HrController.I_JOG(floatingConfig); floatingConfig.ID = 2; floatingConfig.JOG = 512; floatingConfig.playTime = 100; HrController.I_JOG(floatingConfig); break; case "allFree": HrController.RAM_WRITE(1, (byte)RAM_ADDR.Torque_Control, 1, 0x00); HrController.RAM_WRITE(2, (byte)RAM_ADDR.Torque_Control, 1, 0x00); break; case "allOn": HrController.RAM_WRITE(1, (byte)RAM_ADDR.Torque_Control, 1, 0x60); HrController.RAM_WRITE(2, (byte)RAM_ADDR.Torque_Control, 1, 0x60); break; case "disconnect": ComPort.Close(); break; case "connect": ComPort.Open(); break; case "list": Console.WriteLine("moveto <ID> <JOG>"); Console.WriteLine("torqueControl <ID> <TRK_ON, BRK_ON, TRK_FREE>"); Console.WriteLine("RAM_READ <pID> <StartAddr> <Length>"); Console.WriteLine("RAM_WRITE <pID> <StartAddr> <Length> <Value> {ADDR 48 / 49 for error status}"); Console.WriteLine("initPos"); Console.WriteLine("allFree"); Console.WriteLine("allOn"); Console.WriteLine("disconnect"); Console.WriteLine("connect"); break; case "ResolveErrs": if (parsedCmd.Length == 1) { Console.WriteLine("ResolveErrs <pID>"); } else { HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Status_Error, 1, 0x00); HrController.RAM_WRITE(Convert.ToByte(parsedCmd[1]), (byte)RAM_ADDR.Torque_Control, 1, 0x60); } break; case "quit": ComPort.Close(); lockShell = false; break; } } }
private void TimerAffichage_Tick(object sender, EventArgs e) { //caca //using (System.IO.StreamWriter lf = new System.IO.StreamWriter(logPath, true)) //{ // lf.WriteLine(TelemetreEG + " " + TelemetreG + " " + TelemetreC + " " + TelemetreD + " " + TelemetreD + " - " + robotState + " " + stateChanged + " @" + timestamp); //} if (autoPortSetting == 1 && isPortSelected == false) { string[] menuPortContentAS = ListAllSerialOpen(); serialPort1 = new ReliableSerialPort(menuPortContentAS[menuPortContentAS.Length - 1], 115200, Parity.None, 8, StopBits.One); //entrée USB à droite serialPort1.DataReceived += SerialPort1_DataReceived; serialPort1.Open(); isPortSelected = true; stateMachineActivated = true; UartEncodeAndSendMessage(0x0020, 2, new byte[] { 1, 1 }); } if ((stateRobot)(robotState) != (stateRobot)(stateChanged) && (stateRobot)(robotState) != (stateRobot)(stateChanged) + 1 && stateMachineActivated) { UartEncodeAndSendMessage(0x0051, 1, new byte[] { (byte)stateChanged }); } while (Messages.Count > 0) { Message CurMsg = Messages.Dequeue(); byte[] tab = new byte[4]; switch (CurMsg.msgDecodedFunction) { case 0x0080: // transmission texte textBoxReception.Text += "[Text ("; textBoxReception.Text += CurMsg.msgDecodedPayloadLength; textBoxReception.Text += ")"; if (CurMsg.isValidChecksum == true) { textBoxReception.Text += "] "; } else { textBoxReception.Text += ", invalid checksum !] "; } //textBoxReception.AppendText(Encoding.ASCII.GetString(CurMsg.msgDecodedPayload)); for (int i = 0; i < CurMsg.msgDecodedPayloadLength; i++) { textBoxReception.Text += (char)CurMsg.msgDecodedPayload[i]; } textBoxReception.Text += "\n"; break; case 0x0020: // reglage LED textBoxReception.Text += "[LED"; if (CurMsg.isValidChecksum == false) { textBoxReception.Text += " invalid checksum !] "; } else { textBoxReception.Text += "] "; } textBoxReception.Text += "LED "; textBoxReception.Text += CurMsg.msgDecodedPayload[0]; if (CurMsg.msgDecodedPayload[1] == 1) { textBoxReception.Text += " ON"; } else { textBoxReception.Text += " OFF"; } textBoxReception.Text += "\n"; break; case 0x0030: // distance télémètre IR if (CurMsg.isValidChecksum == true) { TelemetreG = CurMsg.msgDecodedPayload[0]; TelemetreC = CurMsg.msgDecodedPayload[1]; TelemetreD = CurMsg.msgDecodedPayload[2]; if (CurMsg.msgDecodedPayloadLength == 5) { TelemetreEG = CurMsg.msgDecodedPayload[3]; TelemetreED = CurMsg.msgDecodedPayload[4]; } } else { textBoxReception.Text += "[IR invalid checksum]\n"; } break; case 0x0040: // Consigne vitesse textBoxReception.Text += "[CONSIGNE"; if (CurMsg.isValidChecksum == true) { textBoxReception.Text += "] "; } else { textBoxReception.Text += ", invalid checksum !] "; } textBoxReception.Text += "G="; textBoxReception.Text += (float)CurMsg.msgDecodedPayload[0] * 100.0 / 255.0; textBoxReception.Text += "% D="; textBoxReception.Text += (float)CurMsg.msgDecodedPayload[1] * 100.0 / 255.0; textBoxReception.Text += "%\n"; break; case 0x0050: // Etape en cours receptionTimeState = (((int)CurMsg.msgDecodedPayload[1]) << 24) + (((int)CurMsg.msgDecodedPayload[2]) << 16) + (((int)CurMsg.msgDecodedPayload[3]) << 8) + (((int)CurMsg.msgDecodedPayload[4]) << 0); receptionTimeState *= 5; robotState = CurMsg.msgDecodedPayload[0]; break; case 0x0061: // odométrie // timestamp tab = CurMsg.msgDecodedPayload.GetRange(0, 4); receptionTimeConsigne = tab[0] << 24; receptionTimeConsigne += tab[0] << 16; receptionTimeConsigne += tab[0] << 8; receptionTimeConsigne += tab[0] << 0; // odo 1 tab = CurMsg.msgDecodedPayload.GetRange(4, 4); //positionXOdo = BitConverter.ToInt32(tab, 0); positionXOdo = tab.GetFloat(); // odo 2 tab = CurMsg.msgDecodedPayload.GetRange(8, 4); positionYOdo = tab.GetFloat(); // angle tab = CurMsg.msgDecodedPayload.GetRange(12, 4); angleOdo = tab.GetFloat(); // linear speed tab = CurMsg.msgDecodedPayload.GetRange(16, 4); linearSpeedOdo = tab.GetFloat(); // angular speed tab = CurMsg.msgDecodedPayload.GetRange(20, 4); angularSpeedOdo = tab.GetFloat(); break; case 0x0062: // Consigne asserv tab = new byte[4]; // timestamp tab = CurMsg.msgDecodedPayload.GetRange(0, 4); receptionTimeOdo = tab[0] << 24; receptionTimeOdo += tab[0] << 16; receptionTimeOdo += tab[0] << 8; receptionTimeOdo += tab[0] << 0; // Consigne Linéaire tab = CurMsg.msgDecodedPayload.GetRange(4, 4); LineaireConsigne = tab.GetFloat(); // Consigne Angulaire tab = CurMsg.msgDecodedPayload.GetRange(8, 4); AngulaireConsigne = tab.GetFloat(); // Consigne Gauche tab = CurMsg.msgDecodedPayload.GetRange(12, 4); GaucheConsigne = tab.GetFloat(); // Consigne Droite tab = CurMsg.msgDecodedPayload.GetRange(16, 4); DroiteConsigne = tab.GetFloat(); break; } } //textBoxReception.Text += "0x" + byteListReceived.Dequeue().ToString("X2") + " " //if (receivedtext != receivedtextAnt) //{ // textBoxReception.Text = receivedtext; // receivedtextAnt = receivedtext; //} }
public MainWindow() { serialPort1 = new ReliableSerialPort("COM5", 115200, Parity.None, 8, StopBits.One); serialPort1.Open(); serialPort1.DataReceived += SerialPort1_DataReceived1; }