Author Topic: Reading/Writing USB Device  (Read 7128 times)

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Reading/Writing USB Device
« on: September 09, 2011, 12:20:21 am »
I am looking for a component to read/write a USB device, to replace a very old component that is no longer supported and thus not available for Delphi XE.

I downloaded nrcomm_pro.zip, and installed it. I built the usbpipedemo program, copied it to the computer with the usb device, and can read some records. However, after 10 or so records (each of 100 or so char's), the program just stops. Sometimes restarting the program helps, but usually the usb device has to be rebooted.

I rebuilt the program with the TnrLogFile component and reran it, but cannot find a log file.

Any help appreciated.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #1 on: September 09, 2011, 12:40:23 am »
I have added an OnLogEntry event, and it does not seem to get triggered - is there something I am missing to get logging to work?

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #2 on: September 09, 2011, 01:15:15 am »
and switch on logging in pipepair as well...

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #3 on: September 09, 2011, 02:01:39 am »
OK, log file sent, not sure if it will help.

PipeDemo program, I found it confusing, with Win 7 and your anchors a lot of components go off the right of the screen, I had this problem as well when porting Delphi code to Win 7. Also, the memos did not have vertical scrollbars, which made it hard to tell how much data had been received.

It seems to go along for a bit, then drop some characters, thus losing records, then completely stop. I then have to reboot the computer (remotely), then the driver for the usb port gets lost, so have to put that back, then run PipeDemo, and usually it starts up again ok.

I have added reset and restart buttons for the usb, without any effect.

I also played with priority for the pipepair with any change as well.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #4 on: September 09, 2011, 09:56:56 am »
And I am having problems with the "Terminal (type here output data)" and "HEX codes of input data" - are these equivalent or is one actually being transmitted?
The "output" seems to be what is coming into to the program from the USB.
The HEX, sort of looks like hex equivalent but isn't?
Puzzled...
 

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #5 on: September 09, 2011, 11:47:07 pm »
I have been through the hex code displayed at the bottom of the screen, it looks like "part" of the string data above (which looks reasonably good) but which chunks missing - I am confused, the top display seems to say you can enter ("type") data, the bottom says "input", are they meant to be the same data?
Added: Think I have figured it out, the HEX code seems to be every second character, was this demo written pre-Unicode and not adjusted?
 
« Last Edit: September 10, 2011, 12:09:22 am by Alycat »

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #6 on: September 10, 2011, 07:44:09 am »
It looks the hex display is supposed to be data coming FROM the USB device but it is wrong. I patched the code and it looks much better.
As mentioned, a status record is sent about every 5 or 6 seconds from the device What seems to be happening with usbpipedemo is that sometimes 4 or 5 records come at once, then maybe one, then another block... then eventually it just stops receiving any data and you have to reboot.
The application is time dependant and a minute or more delay in retrieving data is not acceptable.
Any help?
 

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Reading/Writing USB Device
« Reply #7 on: September 11, 2011, 04:52:16 pm »
Hello

You can handle all incoming data in OnAfterReceive event of TnrUSBPipePair.
But remember that yo need set correct integer values for PipeIn and PipeOut properties before open device.
And please note that Terminal can not show invisible chars correctly.
Yes, your log file is very poor. We do not see driver installation process or device opening in it.

Sorry for my late answers.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #8 on: September 11, 2011, 10:52:10 pm »
Thanks for the reply.
You can handle all incoming data in OnAfterReceive event of TnrUSBPipePair.
I am running your usbpipedemo program. Data is being received via your TnrUSBPipePair event OnAfterReceive (patched as above because HEX values were not displayed correctly)
Quote
But remember that yo need set correct integer values for PipeIn and PipeOut properties before open device.
I am getting confused here, I am selecting the device in usbpipedemo (top line) then selecting pipein then selecting pipeout, then switcging on Active - is that wrong?
Quote
And please note that Terminal can not show invisible chars correctly.
Yes, that's why I was concentrating on hex values.

Quote
We do not see driver installation process or device opening in it.
I did not think usbpipedemo installed the driver??? I seem to need to run usbdrvdemo and select install WinUSB, but then control panel shows the nr driver is installed?? Do I need to build usbdrvdemo with log info in it?
But... the data that is being received is ok, the problem is it comes in blocks of 4 or 5 records rather than one record at a time, and then just stops completely. That is what I am trying to fix - what can I do about that?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Reading/Writing USB Device
« Reply #9 on: September 16, 2011, 04:17:14 pm »
Hello

I have visited your test machine and ran USBBrowser for see some detail of connected USB device.
After that we have modified OSRKit demo for your device.
The TnrUsbPipePair has following new values:

PipIn := 0;
Pipout := 1;
ReadBufferSize := 8;

Now OSRKitDemo shows incoming data from device.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #10 on: September 16, 2011, 11:25:55 pm »
Ok, thanks a lot, I will rebuild my test program and report back.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #11 on: September 19, 2011, 12:26:52 am »
I have downloaded your new library, rebuilt your demo program I was using and it now works ok.
To make sure I understand what to do I have written a small test program from scratch, the initial setup is:
dev:=USB1.DeviceIndexOf(vendor,product);
to get a device ID, then
nrUSB1.SetDeviceIndex(dev) to set it.
To activate reading:
    nrUSB1.Active := true;
    nrUSBPipePair1.Active := true;
To pause reading:
    nrUSB1.Active := false;
    nrUSBPipePair1.Active := false;
This seems to be working ok, does the above look ok?
When the program no longer requires the USB device, how do I close it down? - the program may keep running at this point.
 

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Reading/Writing USB Device
« Reply #12 on: September 19, 2011, 09:20:48 am »
Hello

Yes, your code is correct.
Please note that USB device can provides more than two I/O pipes and you need open pair that you need after open usb device.

You can setActive in False for stop monitoring incoming data and close device.
If you do not need USB at all, you can destroy instance of TnrUsb and TnrUsbPipePair.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Alycat

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Reading/Writing USB Device
« Reply #13 on: September 19, 2011, 10:19:48 am »
Please note that USB device can provides more than two I/O pipes and you need open pair that you need after open usb device.
I was not aware of that. What do I need to do to open the pair, at present I have PipeIn and PipeOut set at design time?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Reading/Writing USB Device
« Reply #14 on: September 19, 2011, 08:05:49 pm »
Hello

Before open pipes you need select correct usb device (SetDeviceIndex method) at runtime.
After that you can open device and pipes (Active properties) at runtime too.

PipeIn and PipeOout you can set at design time.

Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.