Hello Mark,

Monday, July 28, 2008, 8:58:36 AM, you wrote:

MR> How are you closing the port and reopening it? Are you closing the
MR> port before it's removed?

Not exactly.

I'll explain briefly what I need to do.

I have an external device, it is used to do some timing at car
races...this device is connected to a photocell, when a car crosses
the finish line it reads the date and hour of the event and then it
stores that data into an internal buffer.

That device has also a serial port, I connect to that port and read
the data stored in the internal buffer.

To do this I have placed a timer event and periodically do the readout
inside this event.

MR> Reduce your code to the bare minimum needed to reproduce the problem,
MR> and either doing that will give you the answer (it often does for me!)
MR> or else post it here.

Here is the relevant part of the code, it is partly in italian
language so I'll try to place some comments in english:



// this is the timer event
procedure TMainform.Timer_cronometroTimer(Sender: TObject);

var
  comport:string;
  baud:integer;
  bit:integer;
  parita:char;
  stop:integer;
  s,t:string;

begin
// this is to prevent the timer event code being executed while
// I am still running the previous occurrance

if (not timer_cronometro_busy) then
 begin

 timer_cronometro_busy:=true;

    // this occur if I found that the serial is no more readable
    if (reconnect_serial) then
      begin
        ser:=tblockserial.create;
        try
          comport:=config.Seriale.Items.Strings[config.Seriale.itemindex];
          ser.Connect(comport);
          
baud:=strtointdef(config.Velocita.Items.Strings[config.velocita.itemindex],9600);
          bit:=strtointdef(config.Bit.Items.Strings[config.bit.itemindex],8);
          s:=config.parita.Items.Strings[config.parita.itemindex];
          parita:=s[1];
          
stop:=strtointdef(config.Bitstop.Items.Strings[config.bitstop.itemindex],2);
          ser.config(baud,bit,parita,stop,false,true);

          if (config.Modello.ItemIndex=0) then
            begin
            // this is what I do to check if the device is still
            // connected, issuing a '+V' I will get the version of
            // the device so I am sure it is still readable
              s:='+V';
              s:=ser.ATCommand(s);
            end;
          if (ser.ATResult=true) then
            begin
              label_cronometro.Caption:='Cronometro ONLINE';
              label_cronometro.Color:=cllime;
              reconnect_serial:=false;
            end;
        except
          ser.free;
        end;
      end;
    if (ser.InstanceActive=false) then
      begin
        ser:=tblockserial.create;
        try
          comport:=config.Seriale.Items.Strings[config.Seriale.itemindex];
          ser.Connect(comport);
          
baud:=strtointdef(config.Velocita.Items.Strings[config.velocita.itemindex],9600);
          bit:=strtointdef(config.Bit.Items.Strings[config.bit.itemindex],8);
          s:=config.parita.Items.Strings[config.parita.itemindex];
          parita:=s[1];
          
stop:=strtointdef(config.Bitstop.Items.Strings[config.bitstop.itemindex],2);
          ser.config(baud,bit,parita,stop,false,true);
          ser.AtTimeout:=100;
          ser.DeadlockTimeout:=100;
          ser.ConvertLineEnd:=true;
          application.ProcessMessages;
          if (config.Modello.ItemIndex=0) then
            begin
              s:='+V';
              s:=ser.ATCommand(s);
            end;
          if (ser.ATResult=true) then
            begin
              label_cronometro.Color:=cllime;
            end
          else
            begin
              label_cronometro.Color:=clred;
              reconnect_serial:=true;
            end;
        except
          ser.free;
        end;
      end
    else
      begin
      // the rest of the code in case the serial connection is
      // active and I can read the data from the device.

      end;
 timer_cronometro_busy:=false;
end;
end;





----------------------------
Famous Sport Quotes:

'I came to Nantes two years ago and it's much the same today,
 except that it's completely different.'
Kevin Keegan
----------------------------

Steve IK4WMH


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to