• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 26, 2024, 10:29:09 am

News:

SMF - Just Installed!


Reading/Writing USB Device

Started by Alycat, September 08, 2011, 09:20:21 pm

Previous topic - Next topic

Alycat

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

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

and switch on logging in pipepair as well...

Alycat

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

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

September 09, 2011, 08:47:07 pm #5 Last Edit: September 09, 2011, 09:09:22 pm by Alycat
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?

Alycat

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

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

Thanks for the reply.
Quote from: Roman Novgorodov on September 11, 2011, 01:52:16 pmYou 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)
QuoteBut 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?
QuoteAnd please note that Terminal can not show invisible chars correctly.
Yes, that's why I was concentrating on hex values.

QuoteWe 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

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

Ok, thanks a lot, I will rebuild my test program and report back.

Alycat

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

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

Quote from: Roman Novgorodov on September 19, 2011, 06:20:48 amPlease 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

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.