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#
函数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#
解决方案 »
- 关于Decorator设计模式的Demo,欢迎来喷和来分享下你实用的Decorator模式
- 本人不会C语言,求高手帮我写个操作Execl的程序,达到要求后付款
- VC#2008支持隐藏事件吗
- 请教 Crystal Reports 套打的问题
- random类应该使用哪个命名空间啊?
- 新手提问:怎样把数据绑定到DataGrid上(在线等)
- AxWindowsMediaPlayer控件中如何隐藏控制栏?
- 把整个数据库(spl)导出到别人的机子里面去,就是说要把存储过程也一并导出去,应该如何操作啊
- WebClient:用DownloadFile和用OpenRead的结果怎么不同?顺请荐书:)
- 菜鸟提问:SqlDateReader怎么读取多行记录?
- C#同一个工程的cs文件里,如何根据.Net的版本设定不同的代码
- 两个List进行比较..修改值
delphi那边有高人说delphi5的CHR()是ACSIICODE,C#是unicode,应该怎么转换啊?
0~255 acsii与unicode都是一样的。