用SPCOMM控件开发串口通讯程序,我的串口没接数据线(我怀凝线有问题),但也应该可以发数据,但每次按发送按钮:procedure TForm1.Button1Click(Sender: TObject);
var
SendBuf : array[1..5] of Byte ;
begin
SendBuf[1] := byte($D7) ;
Comm1.StartComm;
if not Comm1.WriteCommData(@SendBuf[1],1) then
Edit1.Text := '0'
else
Edit1.Text := '1';
end;
但每次Edit1都显0,究竟哪里出问题了?????
var
SendBuf : array[1..5] of Byte ;
begin
SendBuf[1] := byte($D7) ;
Comm1.StartComm;
if not Comm1.WriteCommData(@SendBuf[1],1) then
Edit1.Text := '0'
else
Edit1.Text := '1';
end;
但每次Edit1都显0,究竟哪里出问题了?????
解决方案 »
- 根据2点屏幕坐标画线
- delphi2005中键盘与鼠标触发事件的问题
- ADODataSet 有没有从结果集查找记录的方法?
- 高分求助:在制作安装程序时,出现EDBEngineErrot错误,并报告未知的数据库
- 王寒松大侠的“中国式报表”组件ereport如何使用?
- 看看谁先说出来,c里的运算符“++”和pascal“Inc()”函数的区别~~
- 急救!!!工程文件打不开了。
- 嵌入ActiveForm的TShockwaveFlash组件触发不了FSCommand消息,查遍了CSDN的相关帖子,没有解决方案,呼唤高手!
- VS回调Delphi上位机回调函数的问题
- dll运行出错
- 怎樣將語句寫在程式出錯前,要程式不退出而繼續運行。
- 简单问题,高分相送,有关于IE的!
function SendData1(Comm:TComm) : Boolean;
var
arrByte : array [1..6] of Byte;
begin
//起始标志位
arrByte[1] := $1B; //数据长度位
arrByte[2] := $30;
arrByte[3] := $32; //命令字
arrByte[4] := $30;
arrByte[5] := $31; //参数体(无) //结束位
arrByte[6] := $0D; //发送
Result := Comm.WriteCommData(PChar(@arrByte),High(arrByte))
end;
begin
OpenComm;
end;procedure TForm1.OpenComm;
var
cc:TCOMMCONFIG;
Temp:string;
begin
Temp:='COM'+inttostr(1); //Ñ¡ÔñËùÒª´ò¿ªµÄCOM
hComm:=CreateFile(PChar(Temp), GENERIC_READ or GENERIC_WRITE,
0, nil, OPEN_EXISTING, 0, 0); //´ò¿ªCOM
if (hComm = INVALID_HANDLE_VALUE) then begin //Èç¹ûCOM δ´ò¿ª
MessageBox (0, '´ò¿ªÍ¨ÐŶ˿ڴíÎó!!','',MB_OK);
exit;
end; GetCommState(hComm,cc.dcb); // µÃ֪ĿǰCOM µÄ״̬
cc.dcb.BaudRate:=CBR_9600; // ÉèÖò¨ÌØÂÊΪ9600
cc.dcb.ByteSize:=8; // ×Ö½ÚΪ 8 bit
cc.dcb.Parity:=NOPARITY; // Parity Ϊ None
cc.dcb.StopBits:=ONESTOPBIT; // 1 ¸öStop bit if not SetCommState(hComm, cc.dcb) then begin // ÉèÖÃCOM µÄ״̬
MessageBox (0, 'ͨÐŶ˿ÚÉèÖôíÎó!!!','',MB_OK);
CloseHandle(hComm);
exit;
end;
end;procedure TForm1.fasong(str:string);
var
lrc:LongWord;
s:string;
begin
s:=str;
if (hComm=0) then exit;
WriteFile(hComm,Pointer(s)^,Length(s), lrc, nil); //ËͳöÊý¾Ý
end;先用api试试
这回真得是撞鬼了!!!tell me why???