/// <summary> /// Writes a Generic Message, check ActiveHardware /// </summary> /// <param name="ID"></param> /// <param name="PID"></param> /// <param name="DID"></param> /// <param name="SID"></param> /// <param name="Data"></param> public void WriteMessage(uint ID, uint PID, uint DID, uint SID, Byte[] Data) { #region ValCheck if ((int)console.GetActiveHardware() == -1) { return; } #endregion TCLightMsg newMsg = new TCLightMsg(); TCLightTimestamp newTime = new TCLightTimestamp(); newMsg.ID = ID | PID | DID | SID; newMsg.MsgType = MsgTypes.MSGTYPE_EXTENDED; newMsg.Len = 8; newMsg.Data = Data; newTime.millis = 1002; console.AddOutsideMessage(newMsg, newTime); PCANLight.Write(console.GetActiveHardware(), newMsg); }
private void btnWrite_Click(object sender, System.EventArgs e) { TCLightMsg MsgToSend; TextBox CurrentTextBox; CANResult Res; // We create a TCLightMsg message structure // MsgToSend = new TCLightMsg(); // We configurate the Message. The ID (max 0x1FF), // Length of the Data, Message Type (Standard in // this example) and die data // MsgToSend.ID = Convert.ToUInt32(txtID.Text, 16); MsgToSend.Len = Convert.ToByte(nudLength.Value); MsgToSend.MsgType = (chbExtended.Checked) ? MsgTypes.MSGTYPE_EXTENDED : MsgTypes.MSGTYPE_STANDARD; // If a remote frame will be sent, the data bytes are not important. // if (chbRemote.Checked) { MsgToSend.MsgType |= MsgTypes.MSGTYPE_RTR; } else { // We get so much data as the Len of the message // CurrentTextBox = txtData0; for (int i = 0; i < MsgToSend.Len; i++) { MsgToSend.Data[i] = Convert.ToByte(CurrentTextBox.Text, 16); if (i < 7) { CurrentTextBox = (TextBox)this.GetNextControl(CurrentTextBox, true); } } } // The message is sent to the configured hardware // Res = PCANLight.Write(ActiveHardware, MsgToSend); // The Hardware was successfully sent // if (Res == CANResult.ERR_OK) { txtInfo.Text = "Message was successfully SENT.\r\n"; } // An error occurred. We show the error. // else { txtInfo.Text = "Error: " + Res.ToString(); } }
private void AlignMotorBtn_Click(object sender, EventArgs e) { TCLightMsg MsgToSend = new TCLightMsg(); MsgToSend.ID = 0x013E20E0 | 0x00000001; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; TCLightTimestamp q = new TCLightTimestamp(); q.millis = 1000; console.AddOutsideMessage(MsgToSend, q); PCANLight.Write(ActiveHardware, MsgToSend); }
public void WriteMessage(TCLightMsg msg) { #region ValCheck if ((int)console.GetActiveHardware() == -1) { return; } #endregion console.AddOutsideMessage(msg, BuildMessageTime()); PCANLight.Write(console.GetActiveHardware(), msg); }
/// <summary> /// Sends the Execute Command over the CAN Bus /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExecuteProfileBtn_Click(object sender, EventArgs e) { #region execute TCLightMsg MsgToSend = new TCLightMsg(); MsgToSend.ID = 0x013EF0E0 | 0x00000001; MsgToSend.Len = 0; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; PCANLight.Write(ActiveHardware, MsgToSend); #endregion TCLightTimestamp q = new TCLightTimestamp(); q.millis = 1000; console.AddOutsideMessage(MsgToSend, q); SendProfileBtn.Enabled = false; ExecuteProfileBtn.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { #region setup TCLightMsg MsgToSend = new TCLightMsg(); MsgToSend.ID = 0x013EE8E0 | 0x00000001; MsgToSend.Len = 1; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; MsgToSend.Data[0] = numPackets; TCLightTimestamp q = new TCLightTimestamp(); q.millis = 1000; console.AddOutsideMessage(MsgToSend, q); PCANLight.Write(ActiveHardware, MsgToSend); #endregion }
private void NPTModeBtn_Click(object sender, EventArgs e) { TCLightMsg MsgToSend = new TCLightMsg(); MsgToSend.ID = 0x01745400 | 0x00000001 | 0x000000E0; MsgToSend.Len = 8; MsgToSend.Data[0] = (byte)0x01; MsgToSend.Data[1] = (byte)0x00; MsgToSend.Data[2] = (byte)0x00; MsgToSend.Data[3] = (byte)0x00; MsgToSend.Data[4] = (byte)0x00; MsgToSend.Data[5] = (byte)0x00; MsgToSend.Data[6] = (byte)0x00; MsgToSend.Data[7] = (byte)0x00; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; TCLightTimestamp q = new TCLightTimestamp(); q.millis = 1000; console.AddOutsideMessage(MsgToSend, q); PCANLight.Write(ActiveHardware, MsgToSend); }
/// <summary> /// Sends the Command List over the CAN Bus /// </summary> /// <param name="cmds"></param> /// <param name="numPackets"></param> private void SendCommandList(List <String> cmds, byte numPackets) { #region ValCheck if (cmds == null || numPackets == 0) { return; } #endregion #region setup TCLightMsg MsgToSend = new TCLightMsg(); MsgToSend.ID = 0x013EE8E0 | 0x00000001; MsgToSend.Len = 1; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; MsgToSend.Data[0] = numPackets; TCLightTimestamp q = new TCLightTimestamp(); q.millis = 1000; console.AddOutsideMessage(MsgToSend, q); PCANLight.Write(ActiveHardware, MsgToSend); #endregion #region move MsgToSend.ID = 0x013EE0E0 | 0x00000001; MsgToSend.Len = 8; MsgToSend.MsgType = MsgTypes.MSGTYPE_EXTENDED; byte count = 0; foreach (String cmd in cmds) { String[] cmd2 = cmd.Split('~'); for (int i = 0; i < MsgToSend.Len; i++) { #region Data switch (i) { case 0: ProfileParamsTb.AppendText(cmd + "\r\n"); MsgToSend.Data[0] = count; count++; break; case 1: MsgToSend.Data[1] = numPackets; break; case 2: MsgToSend.Data[2] = BitConverter.GetBytes(Int16.Parse(cmd2[0]))[1]; break; case 3: MsgToSend.Data[3] = BitConverter.GetBytes(Int16.Parse(cmd2[0]))[0]; break; case 4: MsgToSend.Data[4] = BitConverter.GetBytes(UInt16.Parse(cmd2[1]))[1]; break; case 5: MsgToSend.Data[5] = BitConverter.GetBytes(UInt16.Parse(cmd2[1]))[0]; break; case 6: MsgToSend.Data[6] = BitConverter.GetBytes(UInt16.Parse(cmd2[2]))[1]; break; case 7: MsgToSend.Data[7] = BitConverter.GetBytes(UInt16.Parse(cmd2[2]))[0]; break; } #endregion } console.AddOutsideMessage(MsgToSend, q); PCANLight.Write(ActiveHardware, MsgToSend); } #endregion #region Delete //prevents sending repeats, consider disabling if you want such a feature cmds = null; numPackets = 0; #endregion }