Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341803
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:22

我用c++builder做一个电机控制界面,按钮有好几个如正转。反转。增速。减速,还有数据发送,要求是按9600,8,1发送。数据格式由浮点,定点
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Timer1 ->Enabled =! Timer1->Enabled ;
if (Timer1->Enabled)
{
BitBtn1->Caption="正转!";
String Buf;
DynamicArray ByteBuf;
Comm1->InputLen = 0;
Buf = Comm1->Input;
ByteBuf.Length =1;
ByteBuf[0]=15;
Comm1->OutputByte(ByteBuf);
}
else          BitBtn1->Caption= "错误!";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
Timer2->Enabled=! Timer2->Enabled ;
if (Timer1->Enabled){
BitBtn2->Caption="反转!";
String Buf;
DynamicArray ByteBuf;
Comm1->InputLen = 0;
Buf = Comm1->Input;
ByteBuf.Length =1;
ByteBuf[0]=14;
Comm1->OutputByte(ByteBuf);
}
else               BitBtn2->Caption="错误!";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
Timer3->Enabled =! Timer3->Enabled;
if (Timer1->Enabled){
float x;
x = StrToFloat(speed0->Text);
x =x+1;
speed0->Text=FloatToStr(x);
}
else           BitBtn3->Caption="错误!";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
 Timer4->Enabled =! Timer4->Enabled;
if (Timer1->Enabled){
float x;
x=StrToFloat(speed0->Text);
x-=1;
speed0->Text=FloatToStr(x);
}
else           BitBtn4->Caption="错误!";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
Timer5->Enabled=! Timer5->Enabled ;
if (Timer1->Enabled){
BitBtn5->Caption="停机!";
String Buf;
DynamicArray ByteBuf;
Comm1->InputLen = 0;
Buf = Comm1->Input;
ByteBuf.Length =1;
ByteBuf[0]=12;
Comm1->OutputByte(ByteBuf);
}
else               BitBtn5->Caption="错误!";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{
DWORD lrc;
int i;
byte ch;
for (i=0;i<=20;i++)
{
ch = StrToFloat(InputBuffer[i]);
WriteFile(hComm,&ch,20,&lrc,NULL);
}
CloseHandle(hComm);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::current0Change(TObject *Sender)
{
DynamicArray ByteSend3;
long i;
String InputStr;
InputStr=current0->Text ;
ByteSend3.Length= InputStr.Length();
for (i=0;i< ByteSend3.Length;i++)
 ByteSend3[i]= StrToInt( InputBuffer[i]);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::voltageChange(TObject *Sender)
{
DynamicArray ByteSend4;
long i;
String InputStr;
InputStr=voltage->Text ;
ByteSend4.Length= InputStr.Length();
for (i=2;i< ByteSend4.Length+2;i++)
ByteSend4[i]= StrToInt( InputBuffer[i]);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::current1Change(TObject *Sender)
{
DynamicArray ByteSend1;
long i;
String InputStr;
InputStr=current1->Text ;
ByteSend1.Length= InputStr.Length();
for (i=4;i< ByteSend1.Length+4;i++)
{
ByteSend1[i]= StrToInt( InputBuffer[i]);
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::current2Change(TObject *Sender)
{
DynamicArray ByteSend2;
long i;
String InputStr;
InputStr=current2->Text ;
ByteSend2.Length= InputStr.Length();
for (i=6;i< ByteSend2.Length+6;i++)
ByteSend2[i]= StrToInt( InputBuffer[i]);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PChange(TObject *Sender)
{
DynamicArray ByteSend5;
long i;
String InputStr;
InputStr=P->Text ;
ByteSend5.Length= InputStr.Length();
for (i=8;i< ByteSend5.Length+8;i++)
ByteSend5[i]= StrToInt( InputBuffer[i]);
}
//---------------------------------------------------------------------------


--------------------next---------------------

阅读(948) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~