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

📄 sad8com.cpp

📁 RS232串口通讯,主要用来设置芯片中的数据.
💻 CPP
字号:
// sad8com.cpp: implementation of the sad8com class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SAD8PC.h"
#include "sad8com.h"

#ifdef _DEBUG
#undef THIS_FILE
static char     THIS_FILE[] = __FILE__;

#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSSAD8COM::CSSAD8COM()
{
   memset(commandbuf, 0, sizeof commandbuf);
   memset(answerbuf, 0, sizeof answerbuf);
   memset(sad8read_buf , 0 , sizeof ( sad8read_buf ));
   memset ( sad8_thermbuf , 0 ,sizeof ( sad8_thermbuf ));
}

CSSAD8COM::~CSSAD8COM()
{

}




void            CSSAD8COM::thermhex2str(byte innum, byte * buchang, int len)
{
   byte            ctemp = (innum & 0x7f) / 4;
   char            stemp[16];

   memset(buchang, 0, len);
   memset(stemp, 0, sizeof(stemp));

   if (innum & 0x80)
	  sprintf(stemp, "-%d", ctemp);
   else
	  sprintf(stemp, "%d", ctemp);

   ctemp = ((unsigned) len > strlen(stemp)) ? len : strlen(stemp);

   strncpy((char *) buchang, stemp, ctemp);

}

BOOL            CSSAD8COM::thermstr2hex(byte * buchang, int len,
										 byte * innum)
{

   BOOL            btemp = ('-' == *buchang) ? TRUE : FALSE;
   byte           *p = buchang;

   do
   {
   }
   while (isdigit(*p++));
   *innum = atoi((const char *) p) * 4;
   if (btemp)
	  *innum |= 0x80;

   return TRUE;

}

BOOL            CSSAD8COM::check_thermbackstring(char *stemp)
{
int             i = strlen(stemp);

   if (strlen(stemp) != 34)
   {
	  strcpy(errnostring, "接收长度错误");
	  return FALSE;
   }
   if ((*stemp != *(stemp + 33)) || (*stemp != '&'))
   {
	  strcpy(errnostring, "接收数据错误");
	  return FALSE;
   }
   return TRUE;
}

BOOL            CSSAD8COM::check_writebackstring(char *stemp)
{

   if (strlen(stemp) != 6)
   {
	  strcpy(errnostring, "接收长度错误");
	  return FALSE;
   }
   if ((*stemp != *(stemp + 5)) || (*stemp != '*'))
   {
	  strcpy(errnostring, "接收数据错误");
	  return FALSE;
   }
   return TRUE;
}

BOOL            CSSAD8COM::check_readbackstring(char *stemp)
{
   if (strlen(stemp) != 6)
   {
	  strcpy(errnostring, "接收长度错误");
	  return FALSE;
   }
   if ((*stemp != *(stemp + 5)) || (*stemp != '$'))
   {
	  strcpy(errnostring, "接收数据错误");
	  return FALSE;
   }
   return TRUE;
}

int             CSSAD8COM::iWrite_Sad8()
{

CComOperate     comOpt(comno);


int             iDec = 0;
BOOL            result;

extern char     configupdate_set[];

extern int      configlen;;

char           *p = configupdate_set;

   do
   {
	  memset(commandbuf, '\0', sizeof(commandbuf));
	  memset(answerbuf, '\0', sizeof(commandbuf));

	  memcpy(commandbuf, cSendbuf_WriteDemo, strlen(cSendbuf_WriteDemo));
	  hex2str((unsigned char *) &(*p), 1, (unsigned char *) (commandbuf + 1),
			  2);
	  hex2str((unsigned char *) &(sad8read_buf[*p]), 1,
			  (unsigned char *) (commandbuf + 3), 2);

	  result =
		 comOpt.com_ask_answer(comno, commandbuf, sizeof(commandbuf), answerbuf,
								 sizeof(answerbuf));

	  if (result == FALSE)
	  {

		 strcpy(errnostring, comOpt.errno2string());


		 return FALSE;
	  }
	  if (FALSE == check_writebackstring(answerbuf))
	 
		 return FALSE;
	 

   }
   while (++p - configupdate_set < configlen);
   return TRUE;
}

BOOL            CSSAD8COM::readtherm()
{

CComOperate     comOpt(comno);

BOOL            result = comOpt.com_ask_answer(comno, cSendbuf_ThermDemo,
												 strlen(cSendbuf_ThermDemo),
												 sad8_thermbuf,
												 sizeof(sad8_thermbuf));

   if (result == FALSE)

   {
	  strcpy(errnostring, comOpt.errno2string());

	  return FALSE;
   }

   if (FALSE == check_thermbackstring(sad8_thermbuf))
 
	  return FALSE;


   return TRUE;
}

BOOL            CSSAD8COM::iRead_Sad8()
{
CComOperate     comOpt(comno);


int             iDec = 0;
int             retry = 0;

extern char     configupdate_set[];

extern int      configlen;;
BOOL            result;

char           *p = configupdate_set;

   do
   {
	  memset(commandbuf, '\0', sizeof(commandbuf));
	  memset(answerbuf, '\0', sizeof(commandbuf));

	  memcpy(commandbuf, cSendbuf_ReadDemo, strlen(cSendbuf_ReadDemo));
	  hex2str((unsigned char *) &(*p), 1, (unsigned char *) (commandbuf + 1),
			  2);

	  result =
		 comOpt.com_ask_answer(comno, commandbuf, sizeof(commandbuf), answerbuf,
								 sizeof(answerbuf));

	  if (result == FALSE)
	  {

		 strcpy(errnostring, comOpt.errno2string());

		 return FALSE;
	  }

	  if (FALSE == check_readbackstring(answerbuf))
	  {

		 return FALSE;
	  } else
		 str2BCD((unsigned char *) answerbuf + 3, 2,
				 (unsigned char *) (sad8read_buf + (int) *p), 1);

   }
   while (++p - configupdate_set < configlen);

   return TRUE;

}

⌨️ 快捷键说明

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