Einzelnen Beitrag anzeigen

ljmarkus

Registriert seit: 14. Apr 2007
Ort: Göttingen
46 Beiträge
 
Delphi 7 Personal
 
#8

Re: in Byte umrechnen und per string senden

  Alt 2. Mai 2009, 11:19
hier mal der Code
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);

var timebuffer: String;

    MyTime: TDateTime;

    Data: string;

    Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7: byte;



begin

SetLength(Data, 2);





  if PaintBox1.Canvas.Pixels[0,0] = clBlack then bit0 := 1 else bit0 := 0;

  if PaintBox1.Canvas.Pixels[1,0] = clBlack then bit1 := 1 else bit1 := 0;

  if PaintBox1.Canvas.Pixels[2,0] = clBlack then bit2 := 1 else bit2 := 0;

  if PaintBox1.Canvas.Pixels[3,0] = clBlack then bit3 := 1 else bit3 := 0;

  if PaintBox1.Canvas.Pixels[4,0] = clBlack then bit4 := 1 else bit4 := 0;

  if PaintBox1.Canvas.Pixels[5,0] = clBlack then bit5 := 1 else bit5 := 0;

  if PaintBox1.Canvas.Pixels[6,0] = clBlack then bit6 := 1 else bit6 := 0;

  if PaintBox1.Canvas.Pixels[7,0] = clBlack then bit7 := 1 else bit7 := 0;

  if bit0 = 1 then Byte(Data[1]) := Byte(Data[1]) + $80;//128;

  if bit1 = 1 then Byte(Data[1]) := Byte(Data[1]) + $40;//64;

  if bit2 = 1 then Byte(Data[1]) := Byte(Data[1]) + $20;//32;

  if bit3 = 1 then Byte(Data[1]) := Byte(Data[1]) + $10;//16;

  if bit4 = 1 then Byte(Data[1]) := Byte(Data[1]) + $8;//8;

  if bit5 = 1 then Byte(Data[1]) := Byte(Data[1]) + $4;//4;

  if bit6 = 1 then Byte(Data[1]) := Byte(Data[1]) + $2;

  if bit7 = 1 then Byte(Data[1]) := Byte(Data[1]) + $1;



  if PaintBox1.Canvas.Pixels[8,0] = clBlack then bit0 := 1 else bit0 := 0;

  if PaintBox1.Canvas.Pixels[9,0] = clBlack then bit1 := 1 else bit1 := 0;

  if PaintBox1.Canvas.Pixels[10,0] = clBlack then bit2 := 1 else bit2 := 0;

  if PaintBox1.Canvas.Pixels[11,0] = clBlack then bit3 := 1 else bit3 := 0;

  if PaintBox1.Canvas.Pixels[12,0] = clBlack then bit4 := 1 else bit4 := 0;

  if PaintBox1.Canvas.Pixels[13,0] = clBlack then bit5 := 1 else bit5 := 0;

  if PaintBox1.Canvas.Pixels[14,0] = clBlack then bit6 := 1 else bit6 := 0;

  if PaintBox1.Canvas.Pixels[15,0] = clBlack then bit7 := 1 else bit7 := 0;

  if bit0 = 1 then Byte(Data[2]) := Byte(Data[2]) + $80;//128;

  if bit1 = 1 then Byte(Data[2]) := Byte(Data[2]) + $40;//64;

  if bit2 = 1 then Byte(Data[2]) := Byte(Data[2]) + $20;//32;

  if bit3 = 1 then Byte(Data[2]) := Byte(Data[2]) + $10;//16;

  if bit4 = 1 then Byte(Data[2]) := Byte(Data[2]) + $8;//8;

  if bit5 = 1 then Byte(Data[2]) := Byte(Data[2]) + $4;//4;

  if bit6 = 1 then Byte(Data[2]) := Byte(Data[2]) + $2;

  if bit7 = 1 then Byte(Data[2]) := Byte(Data[2]) + $1;



ComPort1.WriteStr(Data);



end;
für jede 8bit muss ein byte erzeugt werden. Byte1 ist für die ersten 8bit, Byte2 für die nächsten 8bit usw.....
  Mit Zitat antworten Zitat