Reply
Posts: 1
Registered: ‎05-12-2015

Problem with HidUart_SetUartConfig to set the baud rate of device.

[ Edited ]

Hi,

 

I'm using HidUart_SetUartConfig() Method to set baudrate of device through C# application. I;m getting exception of "Unhandled exception running module- object reference is not set to instance of object".

 

Here is my code:

//Open the port

public void Open()
{
if (this.isHID)
{
int index = -1;
string str = this.hidPortName.Substring(4);
uint numdevices = 0;
const ushort Vid = 0x100;
const ushort Pid = 0x003;

List<string> strSerialStrings = new List<string>();
if (SLAB_HID_TO_UART.CP2110_DLL.HID_UART_SUCCESS == SLAB_HID_TO_UART.CP2110_DLL.HidUart_GetNumDevices(ref numdevices, Vid, Pid))
{
for (uint cnt = 0; cnt < numdevices; cnt++)
{
System.Text.StringBuilder strDeviceString = new System.Text.StringBuilder(256);
if (SLAB_HID_TO_UART.CP2110_DLL.HID_UART_SUCCESS
== SLAB_HID_TO_UART.CP2110_DLL.HidUart_GetString(cnt, Vid, Pid, strDeviceString, SLAB_HID_TO_UART.CP2110_DLL.HID_UART_GET_SERIAL_STR))
{
if (str == strDeviceString.ToString())
{
index = (int)cnt;
}
}
}
}

if (index >= 0)
{
this.Device = new IntPtr();
if (SLAB_HID_TO_UART.CP2110_DLL.HID_UART_SUCCESS == SLAB_HID_TO_UART.CP2110_DLL.HidUart_Open(ref this.phidDevice, (uint)index, Vid, Pid))
{
this.isHIDOpen = true;
}
if (SLAB_HID_TO_UART.CP2110_DLL.HID_UART_SUCCESS == SLAB_HID_TO_UART.CP2110_DLL.HidUart_SetUartConfig(this.phidDevice, (uint)this.baudrate, (byte)this.DataBits, (byte)this.Parity, (byte)this.StopBits, (byte)1))
{

}
}
else
{
this.isHIDOpen = false;
}
}

 

baud rate is which I have passed in method HidUart_SetUartConfig method is coming from user selection which is in my case is 460800.

 

Please tell me how to set baudrate with this method.

Posts: 307
Registered: ‎03-03-2015

Re: Problem with HidUart_SetUartConfig to set the baud rate of device.

Do you get the same problem if you try a different baud rate such as 115200?

 

Regards,

Joe