当前位置: 首页>>代码示例>>C++>>正文


C++ Serial::Read方法代码示例

本文整理汇总了C++中Serial::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::Read方法的具体用法?C++ Serial::Read怎么用?C++ Serial::Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serial的用法示例。


在下文中一共展示了Serial::Read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: waitForSerialData

void RfidListener::waitForSerialData()
{
	Serial serial = Serial();
	while (serial.Init(_port) == 0)
		Sleep(200);

	serial.Write("auth");
	serial.Read();
	if (serial.DataRead.compare("0") == 0)
	{
		serial.Write("init");
		serial.Read();
		if (serial.DataRead.compare("ok") == 0)
			serial.Write("ok");
	}

	while (!_quit)	// Ends thread on end
	{
		serial.Write("check");
		serial.Read();
		if (serial.DataRead.compare("1") == 0)
		{
			serial.Write("get");
			serial.Read();

			list<Credential>::iterator it = _credentials.begin();
			for (int i = 0; i < _credentials.size(); i++)
			{
				advance(it, 0);
				if (serial.DataRead.compare(it->id) == 0)
				{
					ZeroMemory(_username, sizeof(_username));
					ZeroMemory(_password, sizeof(_password));

					wcscpy_s(_username, 1024, it->username);
					wcscpy_s(_password, 1024, it->password);
					_connected = TRUE;
					_pProvider->OnConnectStatusChanged();
					break;
				}
			}
			if (_connected)
				break;
		}
		Sleep(1000); // Wait so as no to flood the serial port
	}
}
开发者ID:TimKoruna,项目名称:RFID-Secure-For-Windows,代码行数:47,代码来源:RfidListener.cpp

示例2: main

int main(int argc, char* argv[])
{
	printf("[i] Start... \n");

	Serial serial;
#if defined(WIN32)
	serial.open(SERIAL_PORT_NAME, SERIAL_PORT_RATE, true);
#elif defined(LINUX)
	serial.open(SERIAL_PORT_NAME, SERIAL_PORT_RATE);
#endif

	if(!serial.connected())
	{
		printf("[!] Cant open port!\n");
		return -1;
	}

	char c = 'y';
	int res = 12;

	char buf[BUF_SIZE1];
	memset(buf, 0, BUF_SIZE1);

	while(true)
	{

		serial.write( &c, 1 );
#if 0
		if(res = serial.available()){
			if( res = serial.Read(buf, res) ){
				printf("%d %s\n", res, buf);
			}
		}
#else
		if(serial.waitInput(1000)==0)
			printf("[i] timeout!\n");
		else
		{
			if(res = serial.available())
			{
				res = serial.read(buf, res);
				printf("%d %s\n", res, buf);
			}
		}
#endif
	}
	serial.close();

	printf("[i] End.\n");
	return 0;
}
开发者ID:Aadi2110,项目名称:openrobovision,代码行数:51,代码来源:test_serial.cpp

示例3: loop

void loop()
{
	int len;
	if(serial.available())
	{
		len = serial.available();
	
		serial.Read(buffer, len, 0);

		printf("%s\n",buffer);
	}
	printf("This is setup\n");
	sleep(1);

}
开发者ID:codelectron,项目名称:Krixoid,代码行数:15,代码来源:SerialApp.cpp

示例4: main

int main()
{
    Serial s;
    if(s.Open("/dev/ttySAC1",19200))
    {
        cout<<"port open\n";
        byte packet[]= {0xAA,0xBB,0x03,0x01,0x01,0x03};
        for(int i=0; i<sizeof(packet); i++)
        {
            s.WriteByte((char)packet[i]);
        }

        byte packet_read[1];

        int attempt=100;
        bool flag=false;
        while(attempt--)
        {
            if(s.Read(packet_read,1)>0)
            {
                for(int i=0; i<sizeof(packet_read); i++)
                    printf("%x\n",packet_read[i]);
                flag=true;
            }

        }
        if(!flag)
            cout<<"nothing to read...\n";
        cout<<"closing port...\n";
        s.Close();
    }
    else
    {
        cout<<"port could not open\n";
    }
    return 0;
}
开发者ID:k29,项目名称:rfid,代码行数:37,代码来源:posix_read_write.cpp

示例5: main

int main()
{
	Log log("./data/temp_log.txt", 1024 * 1024);
	rrdWeather *rrdW = new rrdWeather();
	rrdBattery *rrdB = new rrdBattery();
	string port = "/dev/ttyAMA0";
	int iSpeed = 9600;
	char szReadBuffer[128];
	int iBytesRead = 0;
	bool bLoop = true;
	memset(&szReadBuffer[0], 0, 128*sizeof(char));

	LLAP llap;
	Serial serial;
	serial.Configure(port, iSpeed);
	serial.Open();

	int tem = fcntl(0, F_GETFL, 0);
  	fcntl (0, F_SETFL, (tem | O_NDELAY));

	cout << "creating database if not exist" << endl;
	rrdW->create();
	rrdB->create();
	cout << "Listening serial port " << port << endl;

	string tmp;
	int illapRet = 0;

	while(true == bLoop)
	{
		memset(&szReadBuffer[0], 0, 128*sizeof(char));
		iBytesRead = serial.Read(&szReadBuffer[0], 128, 2500, 12);
		if(0 < iBytesRead)
		{
			illapRet = llap.ParseMsg(szReadBuffer, iBytesRead);
			if(MSG_READY == illapRet || MSG_READY_PARTIAL == illapRet)
			{
				LLAP_MSG *pMsg = llap.GetLastMsg();
				string strTime = GetCurrentTime(false);
				//Write to rrd
				if(0 == strcasecmp("TMPA", pMsg->m_szCmd))
				{
					rrdW->update(atof(pMsg->m_szValue));
					//Copy file to /var/www/rpi_web
					CopyFile(rrdW->GetFile(1), "/var/www/rpi_web/01_daily.png");
					CopyFile(rrdW->GetFile(2), "/var/www/rpi_web/02_weekly.png");
					CopyFile(rrdW->GetFile(3), "/var/www/rpi_web/03_monthly.png");
					CopyFile(rrdW->GetFile(4), "/var/www/rpi_web/04_yearly.png");
				}
				if(0 == strcasecmp("BATT", pMsg->m_szCmd))
				{
					rrdB->update(atof(pMsg->m_szValue));
					//Copy file to /var/www/rpi_web
					CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png");
				}
				if(0 == strcasecmp("BATTLOW", pMsg->m_szCmd))
                                {
                                        rrdB->LowBattWarning();
                                        //Copy file to /var/www/rpi_web
                                        CopyFile(rrdB->GetFile(1), "/var/www/rpi_web/battery.png");
                                }

				//Write to screen and log
				tmp = strTime + "\t" + pMsg->m_szId + " " + pMsg->m_szCmd + " " + pMsg->m_szValue + "\t\t" + pMsg->m_szOriginal;
				cout << tmp << endl;
				log.Write(tmp);
			}
		}
		if('q' == getchar())
		{
			bLoop = false;
		}
	}
	serial.Close();
	cout << "Exiting program" << endl;
	fcntl(0, F_SETFL, tem);

	delete rrdW;
	delete rrdB;
	return 0;
}
开发者ID:markom80,项目名称:rpi_station,代码行数:81,代码来源:main.cpp

示例6: main

int main(int /*argc*/, char** /*argv*/)
{
	char panval[BUFFERSIZE];
	char tiltval[BUFFERSIZE];
	char distance[BUFFERSIZE];
	char* str = (char*)malloc(sizeof(char)*BUFFERSIZE);
	/*char* panval;
	panval = "ron01\r\n";
	char* tiltval;
	tiltval = "ron01\r\n";
	char* distance;
	distance = "ron01\r\n";*/
	
	char* camwait;
	camwait = "end00\r\n";
	char* startstr;
	startstr = "frame\r\n";

	
	
	cv::Mat mat;
	cv::Mat mat2;

	cv::Point target;

	Serial serial;

	long long start;
	long long elapsed;

	//char* str;
	//str = "ron01\r\n";

	if (!serial.InitSerial("COM3", 115200)) {
		return 0;
	}

	if (!pgrey.InitSingleCamera())
	{
		return 0;
	}
	FlyCapture2::Error error = pgrey.cam.StartCapture(OnImageGrabbed);
	if (error != PGRERROR_OK)  
	{
		cout << "start capture failed" << endl;
		return 0;
	}

	for (;;)
	{
		//start = milliseconds_now();
		if (status == 0) {
			if (serial.Read(&str)) {
				if (*str == *camwait) {
					//status = 1;
				}
				else if (str[0] == 'P') {
					strncpy(panval, str, sizeof(str));
					
				}
				else if (str[0] == 'T') {
					strncpy(tiltval, str, sizeof(str));
				}
				else if (str[0] == 'D') {
					strncpy(distance, str, sizeof(str));
				}
				else if (*str == *startstr) {
					status = 1;
					
				}
			}


			if (status == 1) {
				FlyCapture2::Error error;
				// Retrieve an image
				start = milliseconds_now();

				//pgrey.cam.tim

				error = pgrey.cam.RetrieveBuffer(&pgrey.rawImage);
				FlyCapture2::TimeStamp frametime = pgrey.rawImage.GetTimeStamp();
				cout << frametime.seconds << frametime.microSeconds << endl;
				//FlyCapture2::TimeStamp

				if (error != PGRERROR_OK)
				{
					pgrey.PrintError(error);
					return -1;
				}

				// Create a converted image
				Image convertedImage;

				// Convert the raw image
				error = pgrey.rawImage.Convert(PIXEL_FORMAT_MONO8, &convertedImage);
				if (error != PGRERROR_OK)
				{
					pgrey.PrintError(error);
					return -1;
//.........这里部分代码省略.........
开发者ID:rishflab,项目名称:lasershark2,代码行数:101,代码来源:main.cpp


注:本文中的Serial::Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。