在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PC機(jī)與變頻器的串行通信

            PC機(jī)與變頻器的串行通信

            作者: 時(shí)間:2016-12-16 來源:網(wǎng)絡(luò) 收藏

            本文引用地址:http://www.biyoush.com/article/201612/330996.htm

              例1:變頻起運(yùn)行參數(shù)設(shè)定
              1#變頻器在運(yùn)行狀態(tài)下改變它的“設(shè)定頻率”為35.00hz
              方法如下:
              35.00去掉小數(shù)為3500d=0dach
              a=1=01h (變頻器地址為“01h”)
              k=04h (運(yùn)行參數(shù)設(shè)定為“04h”)
              p1p0=0001h (運(yùn)行時(shí)設(shè)定頻率為“0001h”)
              d3=00h (數(shù)據(jù)高字節(jié)為“00h”)
              d2=00h (數(shù)據(jù)次高字節(jié)為“00h”)
              d1=0dh (數(shù)據(jù)次字節(jié)為“0dh”)
              d0=ach (數(shù)據(jù)低字節(jié)為“ach”)
              s=c9h (和校驗(yàn)字節(jié)為“c9h”)
             ?。╯=0bh+04h+00h+01h+00h+00h+00h+0dh+ach=c9h)
              主機(jī)先后依次發(fā)送字節(jié)如下的數(shù)據(jù)包ascii:
              3ah,30h,42h,30h,34h,30h,30h,30h,31h,30h,30h,30h,30h,30h,44h,41h,43h,43h,39h,0dh,0ah
              變頻器回復(fù)主機(jī)相同數(shù)據(jù)。
              部分通信代碼如下:
              打開通訊端口代碼
              char *comno;
              dcb dcb;
              string temp;
              temp=“com”+inttostr(rdcom-》itemindex+1);
              comno=temp.c_str() ;
              hcomm=createfile(comno,generic_
              read|generic_write,0,null,open_existing,0,0);
              if(hcomm==invalid_handle_value)
              {
              statusbar1-》simpletext=“打開通信端口錯(cuò)誤!”;
              return;
              }
              else
              statusbar1-》simpletext=“端口已打開!”;
              sleep(100);
              getcommstate(hcomm,&dcb);
              dcb.baudrate=cbr_9600;
              dcb.bytesize =8;
              dcb.parity =noparity;
              dcb.stopbits =onestopbit;
              setcommstate(hcomm,&dcb);
              if(!setcommstate(hcomm,&dcb))
              {
              statusbar1-》simpletext=“通信端口設(shè)置錯(cuò)誤!”;
              closehandle(hcomm);
              return;
              }
              發(fā)送數(shù)據(jù)代碼
              int i=0;
              unsigned char sends[21];
              unsigned long lrc,bs;
              sends[0]=3ah; //header
              sends[1]=30h; //a
              sends[2]=31h;
              sends[3]=30h;//k
              sends[4]=34h;
              sends[5]=30h; //p1
              sends[6]=30h;
              sends[7]=30h; //p0
              sends[8]=31h;
              sends[9]=30h; //d3
              sends[10]=30h;
              sends[11]=30h;//d2
              sends[12]=30h;
              sends[13]=30h; //d1
              sends[14]=44h;
              sends[15]=41h; //d0
              sends[16]=43h;
              sends[17]=43h; //s
              sends[18]=39h;
              sends[19]=0dh; //delimiter
              sends[20]=0ah;
              for(i=0;i++;i《21)
              {
              if(hcomm==0)
              return;
              writefile(hcomm,sends,1,&lrc,null);
              }
              接收數(shù)據(jù)代碼
              int ln;
              unsigned long lrc,bs;
              char inbuff[1024];
              dword nbytesread,dwevent,dwerror;
              comstat cs;
              if(hcomm==0)
              {
              mreceive-》text=“讀取過程有問題,已跳出!”;
              return;
              }
              if(hcomm==invalid_handle_value)
              {
              mreceive-》text=“讀取過程有問題,已跳出!”;
              return;
              }
              clearcommerror(hcomm,&dwerror,&cs);
              if(cs.cbinque)
              {
              readfile(hcomm,inbuff,cs.cbinque,&nbytesread,null);
              inbuff[cs.cbinque]=`