利用mscomm向硬件传送数据。
      type
          Tbyterec=record
          Lo,Hi:Byte;
      end;
       tempbyte[0]:=Tbyterec(systemtime.wSecond).Lo ;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wMinute ).Lo;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wHour).Lo;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wDay).Lo;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wMonth).Lo;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wDayOfWeek).Lo;
       mscomm1.Output:=tempbyte;
       tempbyte[0]:=Tbyterec(systemtime.wYear).Lo;
我用上面的方法,传送数据。告诉我错误“Access violation at address 004E1BA0 in module "***.exe". write of address 00000000”?
请问我应该怎么样写才能把秒、分、时、天、月、星期、年写到硬件中?

解决方案 »

  1.   

    Dim Sendtemp(0) As Byte Sendtemp(0) = 0
       MSComm1.Output = Sendtemp
     Sendtemp(0) = Minute(Time)
       MSComm1.Output = Sendtemp
    Sendtemp(0) = Hour(Time)
       MSComm1.Output = Sendtemp
    Sendtemp(0) = Day(Date)
       MSComm1.Output = Sendtemp
    Sendtemp(0) = Month(Date)
       MSComm1.Output = Sendtemp
    Sendtemp(0) = 4
       MSComm1.Output = Sendtemp
    Sendtemp(0) = Year(Date) - 2000
       MSComm1.Output = Sendtemp
    这是在vb下的向硬件中写时间的程序。难道delphi就不行吗?
      

  2.   

    是的在,mscomm1.Output:=tempbyte;出错。如果必须用这个怎么办?
      

  3.   

    tempbyte是什么类型,为什么一会用tempbyte[0],tempbyte,有什么区别?
      

  4.   

    和控件无关吧,是不是systemtime无创建
      

  5.   

    var
     temp:array[0..6] of byte
     outt:variant;
    begin
      temp[i]:=.....// 或是copymemory(@temp,@systemp,sizeof(byte)*6)
      outt:=temp;
      mscomm1.Output:=outt;