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

Connect, send questions

Started by Mike, May 16, 2011, 10:16:06 am

Previous topic - Next topic

Mike

Roman,
I'm evaluating your component, and having a couple of problems. I need to connect to a device and send and receive ASCII data(strings). I use a loop to vary the baud rate to match the device settings. How can I determine when I actually get connected(question1)?

With another component, I send a command and read the response. SendString doesn't seem to work, as I get no response(question2).

for I := low(FBaudRate) to high(FBaudRate) do
begin
    ComPort.Active := false;
    ComPort.BaudRate := FBaudRate;
    try
      ComPort.Active := true;
      ComPort.SendString('AI2;');
      sleep(200);
     ComPort.SendString('IF;');
     if ComPort.TotalReceived > 0 then  <== always zero
     begin
         

The codes demo receives from the device, but doesn't respond when I use sendstring.  Help doesn't say if it'
s an ansistring or unicode string, I have tried both, no joy

Thanks, Mike

Roman Novgorodov

Hello

Please replace

if ComPort.TotalReceived > 0

by

if ComPort.ReadyForRead > 0

and try again.

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.

Mike

Sorry, no change. I think for some reason the write is failing.

Roman Novgorodov

Hello

I don't see your full code.

Possible nrComm works in asynchronous mode and all incoming data is available in OnAfterReceive event, therefore ReadyForRead is zero.

You need set to null following properties before begin your process:

ComPort.OnAfterReceive := nil;
ComPort.Terminal := nil;
ComPort.DataProcessor := nil;


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.

Mike

I tried your suggestions, but still no joy. Perhaps I put them in the wrong place. Doesn't setting ComPort.OnAfterReceive := nil; disable it? I'll need it to work.

I've attached my .pas unit.

Roman Novgorodov

Hello

Thank you for information.

I see in your source code that you still use OnAfterReceive event.
In this case, better if you will send initial commands and start timer for detect timeout, If during timeout you will get reply in OnAfterReceive event device is detected.

Also there is another strange thing.
You are trying repeat commands with different baud rate. Why? I don't understand your logic.

Do you understand that remote device will receive data anyway?
If you use wrong baud rate, device will receive wrong data but it can reply something or hung ups.

Can you describe device protocol? Possible I will find time and create more correct sample for detect device connection.

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.

Mike

Yes, I need the onAfterReceive event. I don't understand why I need a timer.

As I said earlier, I loop through the baud rates to find the one the device is set for. It works very well with other components, some commercial, some home made. It's one less thing the user has to set.

If the device receives the wrong data, it simply ignores it.

The device sends data to the PC under two conditions. One is if a control on the device is changed, it automatically sends data. I can receive this OK in the onAfterReceive event.

The other method is to have the PC query the radio. The exchange is text strings and there are over 100 different query parameters.

A couple of examples:

The PC sends 'AI2;' to the radio, the radio responds with 'AI2;' (without the parens of course).

The PC sends 'IF;' to the radio, the radio responds 'IF00018150000     -000000 0006000001 ;'

Again I believe the problem is querying the radio, but I have no proof  :D

except nothing is returned.  I tried it without the baud rate loop in my program, and in the codes_demo example, and after sending, the onAfterReceive event does not fire.

Roman Novgorodov

Hello

Please try compiled demo from attachment.
Select correct serial port, click "Connect" and see messages in log memo.

Does demo work correctly?

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.

Mike

The demo does not work. I select the port, and click connect.

The log says

"Start device detection ...
Attepmt 1 Trying baud rate 4800 ..."

with an error message dialog

"Device Com7 open error!!!
Access is denied."



Roman Novgorodov

Hello

This error means that your serial port is busy.
It is already opened by someone.
Please select free serial port with connected your radio device.

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.

Mike

My apologies Roman. There was another program using the port.

Now I get:

Start device detection ...
Attepmt 1 Trying baud rate 4800 ...
TIMEOUT!!! No reply from device.
Attepmt 2 Trying baud rate 9600 ...
TIMEOUT!!! No reply from device.
Attepmt 3 Trying baud rate 19200 ...
TIMEOUT!!! No reply from device.
Attepmt 4 Trying baud rate 38400 ...
TIMEOUT!!! No reply from device.
Device is NOT FOUND!

It should connect at 9600 baud.

Roman Novgorodov

Hello

Possible something wrong in your description of device commands.
Or something wrong in serial port settings like parity, bit size etc.
Please open standard Windows tool Hyperterminal and connect to your COM7 with correct params and 9600 speed.
Enter 'AI2;'
Does device reply ?
Show me terminal screen.

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.

Mike

I do not believe there is anything wrong with my description of device commands, or in serial port settings like parity, bit size etc.

My program works fine with other serial  components, as well as several other programs, 1 of which I have seen the source code for.

Hyperterminal returns data (just like our tests here) when a button on the radio is pressed. It does nothing when I type in AI2; or IF; Possibly because each character is sent individually, not as a string? Turning on local echo, I can see a 3-5 delay between being able to type the next character.

Roman Novgorodov

Hello

Thank you for your information.

QuoteThe PC sends 'AI2;' to the radio, the radio responds with 'AI2;' (without the parens of course).
The PC sends 'IF;' to the radio, the radio responds 'IF00018150000     -000000 0006000001 ;'


QuoteHyperterminal returns data (just like our tests here) when a button on the radio is pressed. It does nothing when I type in AI2; or IF;


QuoteI do not believe there is anything wrong with my description of device commands,


Your confidence is very good. :-)

It seems like you don not know complete specification of command interface of your device.

OK

There are many various situations:

Possible command should be terminated by #13,
Possible you typing too slowly in terminal,
Possible your device does not expect any commands at all and returns data on time intervals or button clicks.
Possible device expects initialization over RTS CTS signal changing.
... and etc.

You can try new version of demo from attachment.

If it does not work again, we need to know real data transmission between PC and device.

QuoteMy program works fine with other serial  components, as well as several other programs,


You can download and run portmon tool.
After that please start your "workable solution".
portmon shows all data between your good APP and device.
Send to me log info of portmon

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.

Mike

Roman -
Thanks for your efforts, sadly the new demo failed exactly like the other one.
QuoteYour confidence is very good. :-)


It's based on experience, not blind assumptions.

QuoteIt seems like you don not know complete specification of command interface of your device.


I believe I do, again based on experience. The official specs may be found here. www.elecraft.com click on Manuals and Downloads, scroll down to K3 Programmer's Reference (pdf). See the section "Command Format".

Attached is the portmon log. See line 36 re: IF;.