public TPCANStatus Init() { TPCANStatus result; StringBuilder strMsg; result = PCANBasic.Initialize(mChannel, mBaudrate); if (result != TPCANStatus.PCAN_ERROR_OK) { strMsg = new StringBuilder(256); PCANBasic.GetErrorText(result, 0, strMsg); MessageBox.Show(strMsg.ToString()); } else { MessageBox.Show("PCAN-USB was initialized successfully!"); // Turn the power source oparationa on byte[] data = { 0x01, mDeviceId }; Write("000", data); // data = new byte[8]; data[0] = 0x02; Write("202", data); StartTimers(); } return(result); }
public void Write(string id, byte[] data) { TPCANStatus result; TPCANMsg msg; msg = new TPCANMsg(); msg.ID = Convert.ToUInt32(id, 16); msg.LEN = Convert.ToByte(data.Length); msg.DATA = new byte[8]; msg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD; for (int i = 0; i < msg.LEN; i++) { msg.DATA[i] = data[i]; } PCANBasic.Write(mChannel, ref msg); result = PCANBasic.Write(mChannel, ref msg); if (result != TPCANStatus.PCAN_ERROR_OK) { StringBuilder strMsg = new StringBuilder(256); PCANBasic.GetErrorText(result, 0, strMsg); //Console.WriteLine(strMsg.ToString()); } }
private string GetFormatedError(TPCANStatus p_error) { StringBuilder sb_error_text; sb_error_text = new StringBuilder(256); if (PCANBasic.GetErrorText(p_error, 0, sb_error_text) != TPCANStatus.PCAN_ERROR_OK) { return($"An error occurred. Error-code's text ({p_error:X}) couldn't be retrieved"); } else { return(sb_error_text.ToString()); } }
private string GetFormatedError(TPCANStatus error) { /// Help Function used to get an error as text StringBuilder strTemp; // Creates a buffer big enough for a error-text strTemp = new StringBuilder(256); // Gets the text using the GetErrorText API function // If the function success, the translated error is returned. If it fails, // a text describing the current error is returned. if (PCANBasic.GetErrorText(error, 0, strTemp) != TPCANStatus.PCAN_ERROR_OK) { return(string.Format("An error occurred. Error-code's text ({0:X}) couldn't be retrieved", error)); } else { return(strTemp.ToString()); } }
/// <summary> /// Help Function used to get an error as text /// </summary> /// <param name="error">Error code to be translated</param> /// <returns>A text with the translated error</returns> private string GetFormatedError(TPCANStatus error) { #if PROGRAM_RUNNING StringBuilder strTemp; // Creates a buffer big enough for a error-text // strTemp = new StringBuilder(256); // Gets the text using the GetErrorText API function // If the function success, the translated error is returned. If it fails, // a text describing the current error is returned. // try { try { if (PCANBasic.GetErrorText(error, 0, strTemp) != TPCANStatus.PCAN_ERROR_OK) { return(string.Format("An error occurred. Error-code's text ({0:X}) couldn't be retrieved", error)); } } catch (Exception Msg) { //MessageBox.Show(Msg.Message + "\n" + Msg.StackTrace); uMessageBox.Show(promptText: Msg.Message + "\n" + Msg.StackTrace, title: "경고"); } } finally { } return(strTemp.ToString()); #else return(""); #endif }