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

📄 0511.c

📁 串口通讯
💻 C
字号:
#include "adodb.h"
#include <rs232.h>
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>		
#include <userint.h>
#include "0511.h"
//数据库操作                             
static CAObjHandle objhandle;            
static ERRORINFO errinfo;                
static HRESULT adostatus;                
static VARIANT source;                   
static VARIANT activeconnecting;         
static char* recordstr;                  
static VARIANT aff;                      
static ADODBObj__Recordset recordset;    
char buffado[512],buff2ado[512];         
                                         








static int panelHandle;
char *buffer_receive85;
long prereadbytes;
int send_counter,qlength85;
int send_end_hits;
int temporarydata,i,j;
int command85[16]={0x68,0x0A,0x0A,0x68,0x71,0x10,0x05,4,1,0,0,0,0,0,0,0x16};
long adnum=237;
long badnum=15;
int main (int argc, char *argv[])
{
	if (InitCVIRTE (0, argv, 0) == 0)
		return -1;	/* out of memory */
	if ((panelHandle = LoadPanel (0, "0511.uir", PANEL)) < 0)
		return -1;
	DisplayPanel (panelHandle);
	RunUserInterface ();
	DiscardPanel (panelHandle);
	return 0;
}

int CVICALLBACK ok (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
   long dis;                          
   long ad1,ad2,ad3,ad4,ad5,ad6;      
  // int i=0,j,k,m;
	switch (event)
	{
		case EVENT_COMMIT:
		 OpenComConfig (1, "", 38400, 2, 8, 1, 512, 512);     
         SetCTSMode (1, LWRS_HWHANDSHAKE_OFF); //禁止硬件握手 
         SetComTime (1, 5.0);//设置通信超时时限               
         FlushInQ (1); //清空串口输入队列                     
         FlushOutQ (1);//清空串口输出队列  
		 
		 send_end_hits=adnum % badnum;
		 if(send_end_hits>0)
		  {
		   send_counter=adnum/badnum+1;
		  }
		else
		  {
		   send_end_hits=badnum;
		   send_counter=adnum/badnum;
		  } 
		for(i=0;i<send_counter;i++) 
		{
		  if(i==0)
		  {temporarydata=1;}
		  else
		  {
			  temporarydata=((i-1)*badnum)+1;
		  }
		  command85[9]=temporarydata%256;	  
		  command85[10]=temporarydata/256%256;
		  command85[11]=temporarydata/256%256; 
		  command85[12]=temporarydata/256/256/256;
		  if(adnum<badnum)
		  {
		   command85[13]=send_end_hits;
		  }
		  else if(i==badnum)
		  {
		   command85[13]=send_end_hits ;
		  }
		  else
		  {
		   command85[13]=badnum;
		  }
		  
		  command85[14]=(command85[4]+command85[5]+command85[6]+command85[7]+command85[8]+command85[9]+command85[10]+command85[11]+command85[12]+command85[13])%256; //计算校验和     	        
		 // prereadbytes=command85[13]*16+9+1;
		  for(j=0;j<16;j++)
		  {
		   ComWrtByte(1,command85[j]);
		  }
		  Delay(1);
		
		 qlength85=GetInQLen(1);
		 buffer_receive85=malloc( qlength85);  
		 ComRd(1,buffer_receive85,qlength85); 
	
		 for(j=8;j<qlength85-2;j++)
		 {
			 if(buffer_receive85[j]<0)
			 {
				 buffer_receive85[j]=buffer_receive85[j]+128;
			 }
		 }
	//	 保存	
	  ADODB_New_Connection (NULL, 1, LOCALE_NEUTRAL, 0, &objhandle);                                                                                                             
	                                                                                                                                                                             
	  adostatus = ADODB__ConnectionOpen (objhandle, NULL, "DSN=tckdb85", "", "", -1);                                                                                              
     /* if(adostatus>=0)                                                                                                                                                           
	  {                                                                                                                                                                          
	    MessagePopup ("提示", "成功!!");                                                                                                                                       
	  }                                                                                                                                                                          
	                                                                                                                                                                             
	  else                                                                                                                                                                       
	  {                                                                                                                                                                          
	    MessagePopup ("提示", "失败!!");                                                                                                                                       
	  }                                                                                                                                                                          
	//SQL命令方法(connection对象法) */                                                                                                                                           
	ADODB__ConnectionExecute (objhandle, NULL, "CREATE TABLE 原始损伤数据表(DISTANCE INT,AD1 INT,AD2 INT,AD3 INT,AD4 INT,AD5 INT,AD6 INT)", &aff, -1, &recordset);               
    for(j=0;j<command85[13];j++)
		
	{	
	 dis = buffer_receive85[9+j*16]+ buffer_receive85[10+j*16]*256+buffer_receive85[11+j*16]*65536+buffer_receive85[12+j*16]*16777216;                                                                                                                                                
	 ad1= buffer_receive85[13+j*16]+buffer_receive85[14+j*16]*256;                                                                                                                                                  
	 ad2= buffer_receive85[15+j*16]+buffer_receive85[16+j*16]*256;                                                                                                                 
     ad3= buffer_receive85[17+j*16]+buffer_receive85[18+j*16]*256;	                                                                                                             
	 ad4= buffer_receive85[19+j*16]+buffer_receive85[20+j*16]*256;	                                                                                                             
	 ad5= buffer_receive85[21+j*16]+buffer_receive85[22+j*16]*256;	                                                                                                             
	 ad6= buffer_receive85[23+j*16]+buffer_receive85[24+j*16]*256;	                                                                                                             
	}	                                                                                                             
		                                                                                                             
	  sprintf(buffado,"insert into 原始损伤数据表 VALUES(%d,%d,%d,%d,%d,%d,%d)",dis,ad1,ad2,ad3,ad4,ad5,ad6);                                                                   
	  ADODB__ConnectionExecute (objhandle, NULL, buffado, &aff, -1, &recordset);                                                                                                
	                                                                                                                                                                            
	                                                                                                                                 
	                                                                                                                                                                             
                                                                                                                                                                                 
//-----------------------------------------------------------------------------------------------------------------                                                                                                        
		}	 
		// ADODB__ConnectionClose (objhandle, NULL);  	
	   // free(buffer_receive85);
			break;
	}
	return 0;
}

int CVICALLBACK quit (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:
			QuitUserInterface (0);
			break;
	}
	return 0;
}

⌨️ 快捷键说明

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