• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

DataProcessor and OnTimer

Started by Arne, October 18, 2010, 10:15:25 am

Previous topic - Next topic

Arne

October 18, 2010, 10:15:25 am Last Edit: October 18, 2010, 11:06:15 am by Arne
Hello Roman,

I have used the nrDataProcessor component a couple of times, but now - in a new project - it is not triggered at all. (Delphi 2007)
I am using this code to init the data processor:

nrDataProcessorUSB.OnDataPacket := nrDataProcessorUSBDataPacket;
nrDataProcessorUSB.DataPackets.Items[0].PacketBegin  := #$FD;
nrDataProcessorUSB.DataPackets.Items[0].PacketEnd    := #$FE;
nrDataProcessorUSB.DataPackets.Items[0].Active       := True;
nrDataProcessorUSB.Reset;
nrDataProcessorUSB.Active := True;


I send commands to a device 4 times a second using the standard Delphi Timer component.
The responses from the device are framed with $FD and $FE.

OnTimer procedure does this:
Send datagram to device
-wait 50ms and debug code receives a command with nrComm.ReadAll(..) that contains all the bytes sent by the device correctly framed with $FD and $FE.
evaluate datagram received by data-processor (does not happen as data processing procedure is not triggered)

Now my question is: is ist possible that the OnTimer procedure blocks the DataProcessor from receiving the incoming datagram?

Thanx, Arne

Roman Novgorodov

Hello

Sorry but I don't understand.

Do you read incoming bytes (call ReadAll() method) in same application that has the nrDataProcessorUSB object?

In this case your read operation clears incoming buffer and bytes do not arrive nrDataProcessorUSB component and is can not detect necessary packet.

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

Arne

A bit misleading I confess.

I tried to read via data-processor. It is not triggered. So I have to prove that the device sends the correct byte-stream. To verify that I used some debug code that uses nrComm.ReadAll(..). I checked the content of the buffer where ReadAll puts the bytes and I can see that the datagram is correct. Now I removed the debug code and still don't know why the data-processor is not triggered.

  • nrComm.DataProcessor := nrDataProcessor; { done in the object-inspector }

  • nrDataProcessor.OnDataPacket                      := nrDataProcessorUSBDataPacket; { procedure for packet handler }
    nrDataProcessor.DataPackets.Items[0].PacketBegin  := #$FD; { all datagrams start with $FD }
    nrDataProcessor.DataPackets.Items[0].PacketEnd    := #$FE; { all datagrams end with $FD }
    nrDataProcessor.DataPackets.Items[0].Active       := True; {other values are default i.e. PacketEndByTimeout := False; PacketLength := 0; }
    nrDataProcessor.Active := True;

  • nrComm.Active := True;



Thanx, Arne

Roman Novgorodov

Hello

Thank you for information.
Unfortunately, We can not reproduce your problem.

We modified DataProc demo for your conditions.
We tested it under Delphi7 (ansi) and under Delphi XE (unicode).
All works good. We used null-modem connection.
See our sources in attachment.

Please upload the simple project that demonstrates problem.

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

Arne

Hello Roman,

I downsized my program as much as possible - the data-processor is still not triggered. You are right that your program works. I have downsized your demo, too.
Please do the following:
- connect two Serial ports via Nullmodemcable
- Start the attached downsized demo (slave device) and open a COM Port with it (one of the nullmodem ports)
- Start my program, select the other COM Port of the Nullmodemcable and press connect.

Now you should see that your program receives the command sent by my program and immediately sends a response.
You can set a breakpoint in my program on line 126 (start of data-processor).
In line 398 you see a line reading from the opened COM-Port via ReadAll(..). Right now it is not in use - just to verify that the slave-device sends the right command.
The Timer is removed completely.

Thanks for your patience.

Good luck,
Arne

Roman Novgorodov

Hello

It seems we found your problem.
You set UseMainThread property in True. But you block main thread in waiting loop:

  { wait for the response }
  for myIndex := 1 to 10 do begin
    if mDataPacketComplete = True then begin
      break;
    end;
    Sleep(kUSBTimeout div 10);
  end;


Please try to set nrComm.UseMainThread := False;
or find another way for wait timeout and do not block main thread.

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

Arne

Hello Roman,

that's it. I always thought that Sleep() does not block any background threads (like data-processor). I'm using this solution now:
http://www.delphipraxis.net/6620-delay-revisited.html and it works, too.

Best regards,
Arne