private void cmbDriverList_SelectedIndexChanged(object sender, EventArgs e) { if (!bConnected) { driverInfo = RP121032.LoadDeviceParameters(Environment.GetEnvironmentVariable("SystemRoot") + "\\" + cmbDriverList.SelectedItem.ToString() + ".ini"); cmbDeviceList.DataSource = driverInfo.RP1210Devices; cmbDeviceList.DisplayMember = "DeviceId"; } }
public RP121032(string NameOfRP1210DLL) { log.Debug("New Object Instance."); string PathToRP1210DLL = Environment.GetEnvironmentVariable("SystemRoot") + "\\System32\\" + NameOfRP1210DLL + ".dll"; string PathToDeviceINI = Environment.GetEnvironmentVariable("SystemRoot") + "\\" + NameOfRP1210DLL + ".ini"; pDLL = Win32API.LoadLibrary(PathToRP1210DLL); if (pDLL == IntPtr.Zero) // Error Handling { log.Warn("Load of " + NameOfRP1210DLL + " DLL Failed."); } else { #region More DLL Import Junk fpRP1210_ClientConnect = Win32API.GetProcAddress(pDLL, RP1210_CLIENT_CONNECT); fpRP1210_ClientDisconnect = Win32API.GetProcAddress(pDLL, RP1210_CLIENT_DISCONNECT); fpRP1210_SendMessage = Win32API.GetProcAddress(pDLL, RP1210_SEND_MESSAGE); fpRP1210_ReadMessage = Win32API.GetProcAddress(pDLL, RP1210_READ_MESSAGE); fpRP1210_SendCommand = Win32API.GetProcAddress(pDLL, RP1210_SEND_COMMAND); fpRP1210_ReadVersion = Win32API.GetProcAddress(pDLL, RP1210_READ_VERSION); fpRP1210_ReadDetailedVersion = Win32API.GetProcAddress(pDLL, RP1210_READ_DETAILED_VERSION); fpRP1210_GetHardwareStatus = Win32API.GetProcAddress(pDLL, RP1210_GET_HARDWARE_STATUS); fpRP1210_GetErrorMsg = Win32API.GetProcAddress(pDLL, RP1210_GET_ERROR_MSG); pRP1210_ClientConnect = (RP1210ClientConnect)Marshal.GetDelegateForFunctionPointer(fpRP1210_ClientConnect, typeof(RP1210ClientConnect)); pRP1210_ClientDisconnect = (RP1210ClientDisconnect)Marshal.GetDelegateForFunctionPointer(fpRP1210_ClientDisconnect, typeof(RP1210ClientDisconnect)); pRP1210_SendMessage = (RP1210SendMessage)Marshal.GetDelegateForFunctionPointer(fpRP1210_SendMessage, typeof(RP1210SendMessage)); pRP1210_ReadMessage = (RP1210ReadMessage)Marshal.GetDelegateForFunctionPointer(fpRP1210_ReadMessage, typeof(RP1210ReadMessage)); pRP1210_SendCommand = (RP1210SendCommand)Marshal.GetDelegateForFunctionPointer(fpRP1210_SendCommand, typeof(RP1210SendCommand)); pRP1210_ReadVersion = (RP1210ReadVersion)Marshal.GetDelegateForFunctionPointer(fpRP1210_ReadVersion, typeof(RP1210ReadVersion)); pRP1210_ReadDetailedVersion = (RP1210ReadDetailedVersion)Marshal.GetDelegateForFunctionPointer(fpRP1210_ReadDetailedVersion, typeof(RP1210ReadDetailedVersion)); pRP1210_GetHardwareStatus = (RP1210GetHardwareStatus)Marshal.GetDelegateForFunctionPointer(fpRP1210_GetHardwareStatus, typeof(RP1210GetHardwareStatus)); pRP1210_GetErrorMsg = (RP1210GetErrorMsg)Marshal.GetDelegateForFunctionPointer(fpRP1210_GetErrorMsg, typeof(RP1210GetErrorMsg)); #endregion _DriverInfo = LoadDeviceParameters(PathToDeviceINI); } //Default Values //MaxBufferSize = 127; MaxBufferSize = 255; }
/// <summary> /// Loads RP12010 Device Parameters from the driver specific INI file. This file is also located in the /// %SystemRoot% Directory with the rp121032.ini file. /// </summary> /// <param name="strDeviceIniPath"></param> /// <returns></returns> public static RP1210BDriverInfo LoadDeviceParameters(string strDeviceIniPath) { RP1210BDriverInfo driverInfo = new RP1210BDriverInfo(); IniParser deviceIniParser = new IniParser(strDeviceIniPath); try { driverInfo.DriverVersion = deviceIniParser.GetSetting("VendorInformation", "Version"); } catch { driverInfo.DriverVersion = "Unknown"; } try { driverInfo.VendorName = deviceIniParser.GetSetting("VendorInformation", "Name"); } catch { driverInfo.VendorName = "Unknown"; } try { //Should return A or B. We want B. driverInfo.RP1210Version = deviceIniParser.GetSetting("VendorInformation", "RP1210"); } catch { //Default to B and hope for the best. driverInfo.RP1210Version = "B"; } try { //Sets up the common timebase for the device driverInfo.TimestampWeight = Convert.ToInt16(deviceIniParser.GetSetting("VendorInformation", "TimestampWeight")); } catch { //Assume a normal resolution if it is not specified driverInfo.TimestampWeight = 1000; } try { string strTemp = deviceIniParser.GetSetting("VendorInformation", "CANFormatsSupported"); driverInfo.CANFormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x))); } catch { // RP1210A Defaults driverInfo.CANFormatsSupported = new List <short>(new short[] { 4 }); } try { // RP1210A Defaults string strTemp = deviceIniParser.GetSetting("VendorInformation", "J1939FormatsSupported"); driverInfo.J1939FormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x))); } catch { // RP1210A Defaults driverInfo.J1939FormatsSupported = new List <short>(new short[] { 2 }); } try { string strTemp = deviceIniParser.GetSetting("VendorInformation", "J1708FormatsSupported"); driverInfo.J1708FormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x))); } catch { // RP1210A Defaults driverInfo.J1708FormatsSupported = new List <short>(new short[] { 2 }); } try { string strTemp = deviceIniParser.GetSetting("VendorInformation", "ISO15765FormatsSupported"); driverInfo.CANFormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x))); } catch { // RP1210A Defaults driverInfo.ISO15765FormatsSupported = new List <short>(new short[] { 2 }); } //Comma delimited list of device numbers string strDevices = deviceIniParser.GetSetting("VendorInformation", "Devices"); List <string> listDevices = new List <string>(strDevices.Split(new char[] { ',' })); foreach (string temp in listDevices) { DeviceInfo devTemp = new DeviceInfo(); devTemp.DeviceId = Convert.ToInt16(deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceId")); devTemp.DeviceDescription = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceDescription"); devTemp.DeviceName = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceName"); devTemp.DeviceParams = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceParams"); driverInfo.RP1210Devices.Add(devTemp); } //Comma delimited list of supported protocols string strProtocols = deviceIniParser.GetSetting("VendorInformation", "Protocols"); List <string> listProtocols = new List <string>(strProtocols.Split(new char[] { ',' })); foreach (string temp in listProtocols) { ProtocolInfo protoTemp = new ProtocolInfo(); protoTemp.ProtocolString = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolString"); protoTemp.ProtocolDescription = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolDescription"); protoTemp.ProtocolParams = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolParams"); try //Protocol speed isn't always defined { string strProtoSpeeds = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolSpeed"); protoTemp.ProtocolSpeed = new List <string>(strProtoSpeeds.Split(new char[] { ',' })); } catch { } string strProtoDevs = deviceIniParser.GetSetting("ProtocolInformation" + temp, "Devices"); List <string> devlistTemp = new List <string>(strProtoDevs.Split(new char[] { ',' })); foreach (string devTemp in devlistTemp) { driverInfo.RP1210Devices.Find(x => x.DeviceId == Convert.ToInt16(devTemp)).SupportedProtocols.Add(protoTemp); } } return(driverInfo); }