Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Delphi10 is not able to send 128 to port

Kincza
2011-07-22
2013-04-30
  • Kincza
    Kincza
    2011-07-22

    Hi,

    there is a sample to show the problem. When I send 128 to the port it works as 127.  This is font downloat to a printer defined by 7x3 bytes. 7 coloumn x 24 dot (in 3 x8 bit). In the last coloumn there is a value 128 but it switches on different dots then should be. It happens at every case of value 128.

    It (the same code) works well under Delphi7. Can someone help with this problem?

    inside a case of

          'C': Begin //C
             C:=7; C:=255; C:=252;
             C:=12; C:=0; C:=14;
             C:=24; C:=0; C:=7;
             C:=24; C:=0; C:=3;
             C:=24; C:=0; C:=7;
             C:=14; C:=0; C:=14;
             C:=7; C:=128; C:=124;
          End;

    Procedure TfrmSerial.DL(f : integer); //download font to printer
      Var
        C : TCT; // a type of array  of bytes
        i, j : integer;
        k, s, e : char;
      Begin
        s:= 'C'; //normaly from A to Z
        e:= 'C'; //normaly from A to Z
        With S16 do Begin // the COM port
          WriteStr(#27#38); // dowload char
          WriteStr(#3+s+e);// define dimension verticaly + start char + end char  => 3x8 dot, from C to C will be overdefined
          For k := s to e do Begin // from C to C
            B(k,C);             // gives back the array of character 'C'
            WriteStr(#7); // define horizontaly dots need to be send before every char
            For i := 2 to 8 do
              For j := 1 to 3 do
                writeStr(CHR(C));
          End; //for k
        End; // with
    End;

    Here is the data sent:

    7 - wide of char
    255
    252
    12
    0
    14
    24 
    0
    7
    24
    0
    3
    24
    0
    7
    14
    0
    14
    7
    128
    124

     
  • Kincza
    Kincza
    2011-07-22

    correction
        C : TCT; // a type of array  of bytes

     
  • You are mixing bytes, characters and strings improperly;
    In delphi 7 a string is an array of char which = a byte;
    In Delphi versions 2009 and above; a string is Unicode; which is most like a string based on word size not byte sized characters.

    The WriteStr converts the UnicodeString passed to it to AnsiStrings internally before sending;
    But with you sending WriteStr(Chr(#xx)); I'm not sure what that is going to end up sending.

    I would suggest you construct the string of characters you want to send
    then send the string once
    instead of many 1 character sends.

    It may help to think of it as
    Delphi 7             string = byte
    Delphi 2009      string = word

    I'm sure you're getting many compiler warnings too

     
  • Ian C
    Ian C
    2011-11-15

    Delphi 2010 cannot RECEIVE 128 from port either.

    I'm replying with this because I think it is the same problem.  If the received data packet contains a 128 ($80) then that byte is translated to $AC for some reason.  You never get to see 128s in the input data stream.  NOTE: This only happens if reading a 'string'. 

    comport.read(… ) works OK because buff is untyped.
    comport.readstr(…) translates $80 to $AC.

    Sadly, DataPacket events all use string type parameters.

    Either way, the 128s in the input data stream shouldn't get messed with.

     
  • Use 8 databits instead of 7 databits