开发者

Strange problem using MVVM light toolkit and USB communication

I've made an usb hid device (pic18f2550 and DS1820 ).

I'm using Visual Studio 2010, C# , .NET 4.0 Framework, the latest version of MVVM light toolkit and an usb HID driver from Florian Leitner (facility to import functions from hid.dll [DllImport("hid.dll")], thread for reading etc... )

First, I've made very light interface using code-behi开发者_如何学运维nd for testing the communication between my device and my computer. All is fine, my device is detected and informations are read and can be displayed without problem. I've also decided, for learning using this toolkit, to implement the MVVM pattern.

I've made an model class for communitcation with my usb device, using same code as my first program. This class implement a default constructor who create the new UsbInterface (no souci) and enable the connection.

This constructor is tested with Visual Studio unit test, all fine, device is connected.

The interface have an button, RelayCommand and a Action who call the default constructor of my model when button is pressed. (View <-> ViewModel -> Model)

Using debug, the default constructor is called, the new UsbInterface is created, but the Connection always return false.

I really don't know what's append.

My usb device seems running well, USB HID class from Florent Leitner is ok using normal WPF application and my ModelClass.

But this very basic ModelClass(and Usb class) doesn't running on this pattern.

The default constructor

public TemperatureModel()
{
   usb = new USBInterface(”vid_04d8″, “pid_003f”);
   _InterfaceConnected = usb.Connect();
   if (_InterfaceConnected)
   {
      usb.enableUsbBufferEvent(new EventHandler(TraitementReception));
   } 
}

using simple WPF application with code behind, _InterfacConnected is true (if my device is connected)

using unit test in Visual Studio for MVVM solution, _InterfacConnected is true (if my device is connected)

using the MVVM solution, Click on button, calling RelayCommand and calling the default TemperatureModel constructor, _InterfaceConnected always FALSE

Does someone have an idea ?

Regards Eric


I've changed the USB class used for test and now using libus-win32 from SourceForge. I've tryed with an sample WPF application with CodeBehind. It's running well. I'll try to do the same with Mvvm tonight.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜