Re: Converting C# to VB.net
Code:
usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB)
AddHandler usbDevices.DeviceAttached, New EventHandler(AddressOf usbDevices_DeviceAttached)
AddHandler usbDevices.DeviceRemoved, New EventHandler(AddressOf usbDevices_DeviceRemoved)
Re: Converting C# to VB.net
I Receive an error with the above code indicating that usbDevices_DeviceAttached and usbDevices_DeviceRemoved are undeclared. These two names are supposed to be the names of the handlers that are being created. They do not have any values.
Re: Converting C# to VB.net
There must be something like
Code:
private void usbDevices_DeviceAttached(...
{
...
}
in the c# code you're converting. That's the event handler for the DeviceAttached event.
You should add this sub to your code in order for this to work:
Code:
Private Sub usbDevices_DeviceAttached(...
End Sub
Re: Converting C# to VB.net
I tried this instead
<code> AddHandler usbDevices_DeviceAttached, AddressOf usbDevices.DeviceAttached
AddHandler usbDevices_DeviceRemoved, AddressOf usbDevices.DeviceRemoved
</Code>
but I receive the error: "AddressOf operand must be the name of a method(without parenthesis)"
usbDevices.DeviceAttached() and usbDevices.DeviceRemoved() have the following signature:
(sender as object, e as system.eventargs)
These are functions that are being invoked from a dll:
imports CyUSB
Dim usbDevices As USBDeviceList 'USB device list
Dim myDevice As CyUSBDevice
Re: Converting C# to VB.net
Actually, I think you may be right. The function needs to be defined. here is an example:
Code:
void usbDevices_DeviceAttached(object sender, EventArgs e)
{
USBEventArgs usbEvent = e as USBEventArgs;
// Take some action
}
I can define this function but I don't know what USBEventArgs is. It is not defined in the dll.
Re: Converting C# to VB.net
Load the working C# application in the VS IDE, press F2 to bring up the object browser and use that to search for USBEventArgs. You would be able to trace it from there to the namespace and even the assembly it belongs to.
Re: Converting C# to VB.net
The USBeventArgs class should be defined in the same dll that your USBDeviceList class.
Just browse through this dll using the object browser.
Re: Converting C# to VB.net
Thanks for the assistance. What is the VB equivalent of these lines:
Code:
USBDeviceList usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
CyUSBDevice StreamDevice = usbDevices["Cy Stream Device"] as CyUSBDevice;
The first line I am able to convert just fine: (usbDevices is already declared)
Code:
usbDevices = New USBDeviceList(CyConst.DEVICES_CYUSB)
I am not certain of how to create a new instance of streamDevice as a CyUSBDevice: (I already declared StreamDevice as a CyUSBDevice)
Code:
StreamDevice = usbDevices("Cy Stream Device") (as CyUSBDevice)
Re: Converting C# to VB.net
csharp Code:
CyUSBDevice StreamDevice = usbDevices["Cy Stream Device"] as CyUSBDevice;
vb.net Code:
Dim StreamDevice As CyUSBDevice = TryCast(usbDevices("Cy Stream Device"), CyUSBDevice)