⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendata.txt

📁 C++Builde上位机测试程序
💻 TXT
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "sendData.h"
#include "PComm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    int Ret;
    if (RadioButton1->Checked==true)
 {
 Port = 1;}
 if (RadioButton2->Checked==true)
  {
 Port = 2;}
    Ret = sio_open(Port);
    if (Ret!=SIO_OK)
    {
        ShowMessage("打开通信端口错误");
        sio_close(Port);
        return;
    }
    if (!PortSet())
    {
        sio_close(Port);
        ShowMessage("通信端口参数设置发生错误");
        return;
    }
  //  if(!InitIrq())
    //{
      //  sio_close(Port);
        //ShowMessage("通信端口事件设置发生错误");
       // return;
   // }
     Timer1->Interval=StrToInt(Edit1->Text.Trim());
     Timer1->Enabled=true;
}
//---------------------------------------------------------------------------


bool _fastcall TForm1::PortSet()
{
    long mode,Hw,Sw,ret,tout;
    mode = P_NONE|BIT_8|STOP_1;
    Hw = 0;
    Sw = 0;
    ret = sio_ioctl(Port,B9600,mode);
    if (ret != SIO_OK)
    {
        ShowMessage("设置时发生错误");
        return (false);
    }
    ret = sio_flowctrl(Port,Hw|Sw);
    if (ret != SIO_OK)
    {
        ShowMessage("流量设置时发生错误");
        return (false);
    }
    return (true);

}


void __fastcall TForm1::FormCreate(TObject *Sender)
{
 if (RadioButton1->Checked==true)
 {
 Port = 1;}
 if (RadioButton2->Checked==true)
  {
 Port = 2;}
  Timer1->Interval=StrToInt(Edit1->Text.Trim());
  Timer1->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TDateTime *DT = new TDateTime();
*DT = Now();
//String time;
String time=DateTimeToStr(*DT);
//FormatDateTime("yyyymmddhhnnss",time);
String head("@");
String end("*");
String towLong;
    String towLat;
    String seaDeep;
    String towDeep;
    String fromBottomDeep;
    String towX;
    String towY;
    String towVoltage;
    String towCurrent;
    String Fe;
    String Mn;
    String PH,salinity,H2,H2S,muddyDegree,temperature,S2,shipCourse,shipSpeed;
//String txtStr= head+time;
    signed int x= random(5)-random(5);
    signed int y= random(5)-random(5);
           // seaDeep=FloatToStr(4000+random(1000)+0.01*random(100));
           // towDeep=FloatToStr(random(4000)+0.01*random(100));
           // fromBottomDeep=FloatToStr(seaDeep-fromBottomDeep+0.1);
            if (x>=0)
            {
            towX="+"+IntToStr(20+x)+IntToStr(10+random(50));
            }else
            {
             towX="-"+IntToStr(20+x)+IntToStr(10+random(50));
            }
            if (y>=0)
            {
            towY="+"+IntToStr(20+y)+IntToStr(10+random(50));
            }else
            {
             towY="-"+IntToStr(20+y)+IntToStr(10+random(50));
            }
            seaDeep= IntToStr(2000+random(1000))+IntToStr(10+random(50));
            towDeep = IntToStr(200+random(300))+IntToStr(10+random(50));
            towVoltage=IntToStr(10+random(20))+IntToStr(1+random(8));
            towCurrent=IntToStr(20+random(10))+IntToStr(1+random(8));
            temperature=IntToStr(20+random(10))+IntToStr(1000+random(1000));
            salinity= IntToStr(20+random(20))+IntToStr(1000+random(1000));
            muddyDegree=IntToStr(1000+random(200))+IntToStr(10+random(50));
            PH=IntToStr(20+random(10))+IntToStr(100+random(500));
            H2S=IntToStr(1000+random(1000))+IntToStr(1+random(8));
            H2= IntToStr(1000+random(1000))+IntToStr(1+random(8));
            Fe=IntToStr(1000+random(1000))+IntToStr(10+random(60));
            Mn=IntToStr(1000+random(1000))+IntToStr(10+random(60));
            S2=IntToStr(1000+random(1000))+IntToStr(10+random(60));

//String txtStr= head+','+FormatDateTime("yyyymmddhhnnss",time)+','+seaDeep+','+towDeep+','+towX+','+towY+','+towVoltage+','+towCurrent+','+temperature+','+salinity+','+muddyDegree+','+PH+','+H2S+','+H2+','+Fe+','+Mn+','+S2+','+end;
String txtStr= head+FormatDateTime("yyyymmddhhnnss",time)+seaDeep+towDeep+towX+towY+towVoltage+towCurrent+temperature+salinity+muddyDegree+PH+H2S+H2+Fe+Mn+S2+end+'\r'+'\n';
//String txtStr= head+','+DateTimeToStr(time)+','+towX+','+towY+','+towVoltage+','+towCurrent+','+temperature+','+salinity+','+muddyDegree+','+PH+','+H2S+','+H2+','+Fe+','+Mn+','+S2+','+end;
Memo1->Text=Memo1->Text+txtStr+"长度:"+IntToStr(txtStr.Length())+'\r'+'\n';
sio_write(1,txtStr.c_str(),txtStr.Length());

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

void __fastcall TForm1::Button2Click(TObject *Sender)
{
sio_close(Port);
Timer1->Enabled=false;
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Memo1->Text="";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
sio_close(Port);
 Timer1->Enabled=false;       
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -