delphi代码:
函数1
Dispenser Triggle(int myDecAddr,int myChannel,int myVacuumONDelay,int myVacuumOFFDelay,int myDisTime)
{
         txStr := CHR($AA)+CHR(1+128)+CHR($AA+1+128) + CHR($41+myChannel) +
                  CHR(GetByteN(Round(myVacOffDly),0))+
                  CHR(GetByteN(Round(myVacOffDly),1))+
                  CHR(GetByteN(Round(myDispTime),0))+
                  CHR(GetByteN(Round(myDispTime),1))+
                  CHR(GetByteN(Round(myVacOnDly),0))+
                  CHR(GetByteN(Round(myVacOnDly),1));
         Serialport.Write(txStr);
}
函数2
function GetByteN(val:integer;n:integer):Byte;
begin
   if (n>=0) and (n<=3) then
      result := val SHR SCID_IntByteShift[n]
   else
      result := val;
end;SCID_IntByteShift : array[0..3] of integer = (0,8,16,24);函数3
procedure SerialPort.Write( myTxBytes : string );
begin
  if Open then
  begin
    if (commStd=1) then
       SetDTR(true);
    ComThread.WriteComm( myTxBytes[1], Length( myTxBytes ) );
    sleep(1);
    if (commStd=1) then
       SetDTR(false);
  end;
end;
函数4
function TCommThread.WriteComm( var buf; ByteCount: integer ): DWORD;
begin
  FillChar( TXOverLap, SizeOf( TXOverLap ), 0 );
  WriteFile( hCom, Buf, ByteCount, Result, @TXOverLap );
end;我的C#代码:
 private string Header= Convert.ToChar(0xAA).ToString() + Convert.ToChar(1+128) 
                        +Convert.ToChar(0xAA + 1 + 128).ToString();
 string Tx = Header + Convert.ToChar(0x41 + 1) 
             + Convert.ToChar((int)vaoffdly) 
             + Convert.ToChar((int)vaoffdly >> 8) 
             + Convert.ToChar((int)dispense) 
             + Convert.ToChar((int)dispense >> 8) 
             + Convert.ToChar((int)vaondly) 
             + Convert.ToChar((int)vaondly >> 8);
 Port.Write(Tx);
运行后向com口写入,但没有回馈,也没有任何动作。Port已经设置好且已经Open。
(主要功能是用串口控制一块控制板来控制两个电磁阀的开关时间,已经确认串口连接的控制板有电、连接良好,且厂商提供的delphi写的程序能够实现功能)。
请各路高手帮忙看看,我写的C#代码是否正确,最好帮忙按上面的delphi代码写出对应的C#语句。谢谢DelphiC#