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

📄 opticswitch.cpp

📁 这是一个自动控制光开关的程序
💻 CPP
字号:
#include "OpticSwitch.h"


OpticSwitch::OpticSwitch(void){

}
OpticSwitch::~OpticSwitch(void){
}

void OpticSwitch::openSwitch(int number )
{
	CSerial *m_serial = new CSerial();
	m_serial->Open(1,9600);
	char buf[10000];
	for(int j = 0;j<10000;j++){
		buf[j] = ' ';
	}
	getValue(number,buf);


	for(int i = 0;i<10000;i=i+11){
		if(buf[i+1]==' '){
			break;
		}

		char sendBuf[11];
		
		memcpy(sendBuf,buf+i,11);
		sendBuf[11]='\0';
		printf(sendBuf);
	
		m_serial->SendData(sendBuf,11);
		Sleep(1000);
	}
	m_serial->Close();
	delete m_serial;
	return;
}
void OpticSwitch::setIniFile(LPCTSTR lpFileName)
{
	ini = lpFileName;
}
void OpticSwitch::getValue(int i_key,char* buf)
{
	    CString s_key;
	    s_key.Format("%d", i_key);	
	    GetPrivateProfileString("map", //节名
        s_key, //项名
        "No Text", //没找到此项时的返回值
        buf, //目标缓冲区地址
        10000, //目标缓冲区长度
        ini); //配置文件的准确路径

        return ;
	  
}

int main(){
	OpticSwitch *m_switch = new OpticSwitch();//创建实例
	m_switch->setIniFile("C:\\CSerial\\CConfig.ini");//设置配置文件
	m_switch->openSwitch(1);//打开光开关
	delete m_switch;
	return 0;
}

⌨️ 快捷键说明

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