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


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

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


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

示例1: main

int main() {

	Serial *ardu = new Serial("COM4");
	Gamepad *hid = new Gamepad(1);
	unsigned char l_dir, r_dir, l_pow, r_pow;
	unsigned char ardu_msg[5] = {0x05, RELEASE, 0, RELEASE, 0};

	while (1) {
		hid->Update();
		if (get_motor_params(*hid, &l_dir, &r_dir, &l_pow, &r_pow) < 0) {
			break;
		}

		ardu_msg[1] = l_dir;
		ardu_msg[2] = l_pow;
		ardu_msg[3] = r_dir;
		ardu_msg[4] = r_pow;

		ardu->WriteData(ardu_msg, 5);

		cout << l_dir << '\t' << (int)l_pow << '\t';
		cout << r_dir << '\t' << (int)r_pow << endl;

		hid->RefreshState();
	}
	return 0;
}
开发者ID:bcpearce,项目名称:arduino-xbox360-motor-control,代码行数:27,代码来源:main.cpp

示例2: main

int main(int argc, char* argv[])
{
	Serial * Arduino = new Serial("COM8");
	cout << "Communicating with COM7 enter data to be sent\n";
	char data[256] = "";
	int nchar = 256;
	char incomingData[256] = "";
	while (Arduino->IsConnected())
	{
		cin >> data;
		Arduino->WriteData(data, nchar);
		Arduino->ReadData(incomingData, nchar);
		cout << incomingData << endl;
	}
	return 0;
}
开发者ID:CYHan,项目名称:Algorithm,代码行数:16,代码来源:소스.cpp

示例3: Serial

int *LedAmountTest(char *Comm)
{
	Serial* SP = new Serial(Comm);

	if (SP->IsConnected())
		std::cout << "Connected with COM5" << std::endl;

	bool exit = false;
	//je kan hier op escape drukken om het programma af ste sluiten hier
	std::cout << "Waiting for Arduino. Press ESC to quit" << std::endl;
	char Rx_buffer[2] = "";

	while (Rx_buffer[0] != '0') //blijf hier hangen tot de arduino klaar is
	{
		Sleep(100);
		SP->ReadData(Rx_buffer, 2);
		if (GetAsyncKeyState(VK_ESCAPE))
		{
			exit = true;
		}
		if (exit == true)
		{
			std::cout << "Something went wrong with communication. Check baudrate settings and COM port" << std::endl;
		}
	}

	Rx_buffer[0] = '0';

	std::cout << "Got response from arduino sending amount of leds" << std::endl;

	//Stuur de hoeveelheid leds naar de arduino
	UINT8 Tx_buffer[600 * 3];

	ZeroMemory(Tx_buffer, 600 * 3);
	Tx_buffer[0] = 600 >> 8 & 0x00FF;
	Tx_buffer[1] = 600 & 0x00FF;

	SP->WriteData((char*)Tx_buffer, 2);


	std::cout << "Press up to add a LED and press down to remove one." << std::endl;
	std::cout << "When you are satisfied press SPACEBAR to confirm" << std::endl;
	std::cout << "Press ESC to quit" << std::endl;

	//onderstaande stukje code zal blijven draaien tot je op ESC drukt
	static int leds[4] = { 0 }, i = 0;
	int offset = 0;
	leds[0]++;
	while (i <4)
	{
		if (GetAsyncKeyState(VK_SPACE))						//Als escape is ingedrukt zet exit true
		{
			offset += leds[i];
			i++;
			Sleep(500);
		}
		if (GetAsyncKeyState(VK_UP))
		{
			leds[i]++;
			ZeroMemory(Tx_buffer, 600 * 3);
			for (int j = 0; j < leds[i]; j++)
			{
				for (int k = 0; k < 3; k++)
				{
					Tx_buffer[(j + offset) * 3 + k] = 0xff;
				}

			}

			SP->WriteData((char*)Tx_buffer, 1800);
			Sleep(50);
		}
		if (GetAsyncKeyState(VK_DOWN) && leds[i] > 1)
		{
			leds[i]--;
			ZeroMemory(Tx_buffer, 600 * 3);
			for (int j = 0; j < leds[i]; j++)
			{
				for (int k = 0; k < 3; k++)
				{
					Tx_buffer[(j + offset) * 3 + k] = 0xff;
				}

			}
			SP->WriteData((char*)Tx_buffer, 1800);
			Sleep(50);
		}

	}
	SP->~Serial();
	return leds;
}
开发者ID:jobbywl,项目名称:DirectXAmbi,代码行数:92,代码来源:Main.cpp

示例4: main


//.........这里部分代码省略.........

	char Rx_buffer[100] = "";	//Dit is de Rx_buffer deze moet een char zijn

	//je kan hier op escape drukken om het programma af ste sluiten hier
	std::cout << "Waiting for Arduino. Press ESC to quit" << std::endl;

	SP->ReadData(Rx_buffer, 2);
	while (Rx_buffer[0] != '0') //blijf hier hangen tot de arduino klaar is
	{
		Sleep(100);
		SP->ReadData(Rx_buffer, 2);
		if (GetAsyncKeyState(VK_ESCAPE))
		{
			exit = true;
		}
		if (exit == true)
		{
			std::cout << "Something went wrong with communication. Check baudrate settings and COM port" << std::endl;
			return 0;	//beeindig de software
		}
	}

	Rx_buffer[0] = '0';

	std::cout << "Got response from arduino sending amount of leds" << std::endl;

	//Stuur de hoeveelheid leds naar de arduino
	UINT8 Tx_buffer[600 * 3];

	ZeroMemory(Tx_buffer, 600 * 3);
	Tx_buffer[0] = Scherm.geefLeds() >> 8 & 0x00FF;
	Tx_buffer[1] = Scherm.geefLeds() & 0x00FF;

	SP->WriteData((char*)Tx_buffer, 2);

	Sleep(1000);	//Wacht 1 seconde op de arduino

	std::cout << "Press END to quit capturing" << std::endl;

	UINT8 *pointer;						//Pointer voor de led bitstream
	clock_t klok1;
	clock_t klok2 = 50;
	pointer = Scherm.GeefLedPointer();	//Koppel de led bitstream aan de pointer
	// maak een thread die nu nog niks doet
	std::thread uart(send_data,SP,Rx_buffer,Scherm,pointer);

	while (exit == false)
	{
		//std::cout << "                     " << "\r";
		//std::cout << "FPS: " << ((1 * CLOCKS_PER_SEC) / (clock() - klok2)) << "\r";
		klok2 = clock();

		if (GetAsyncKeyState(VK_END))						//Als escape is ingedrukt zet exit true
		{
			exit = true;
		}
		else if (GetAsyncKeyState(VK_F8))
		{
			JACK.stop();
			pBits = Cap.pBits;
			Scherm.set_data(pBits);
			cap_method = GDI_CAP;
			std::cout << "Changed capture method to GDI " << std::endl;
			Sleep(100);

		}
开发者ID:jobbywl,项目名称:DirectXAmbi,代码行数:67,代码来源:Main.cpp

示例5: main


//.........这里部分代码省略.........
//		cvReleaseImage(&pesos3);

		pesos3 = cvCreateImage(cvGetSize(Camera.frame), Camera.frame->depth, Camera.frame->nChannels);
		cvMerge(&(IplImage)pesos, &(IplImage)pesos, &(IplImage)pesos, NULL, pesos3);
		//cvAddWeighted(pesos3, 0.9, Camera.frame, 0.8, 80, Camera.frame);

		for (int i = 0; i < 7; i++)
		{
			if (Camera.players[i].x != -1)
			{
				cvCircle(Camera.frame, cvPoint((int)Camera.players[i].x, (int)Camera.players[i].y), radius, CV_RGB(debug_colors[i][0], debug_colors[i][1], debug_colors[i][2]), 2);
				cvLine(Camera.frame, cvPoint((int)Camera.players[i].x, (int)Camera.players[i].y), cvPoint((int)Camera.players[i].x + radius*cos(Camera.players[i].theta),
					(int)Camera.players[i].y + radius*sin(Camera.players[i].theta)), CV_RGB(debug_colors[i][0], debug_colors[i][1], debug_colors[i][2]), 2);
			}
		}



		cout << "nxd: " << xd << " nyd: " << yd << endl;
		cvCircle(Camera.frame, cvPoint(xd + 155, -yd + 116), 5, CV_RGB(0, 255, 0), -1);

		
		cvShowImage("Live", Camera.frame);



		//Escape Sequence
		char_pressed = cvWaitKey(1);
		if (char_pressed == 27) //esc
		{

			temp[0] = 0x80;
			temp[1] = 0x80;
			SP->WriteData(temp, 2);
			SP->sendApi(0, 0, 0, 0, 0);
			SP->sendApi(0, 0, 0, 0, 0);
			SP->sendApi(0, 0, 0, 0, 0);

			break;


		}
		if (char_pressed == 112) //p
		{
			if (paused)
				paused = false;
			else{
				paused = true;
				flag = 1.0;
				//thetad = alpha;
			}
		}
		if (char_pressed == 99) //c
		{
			whishPath.clear();
			followedPath.clear();
		}
		if (char_pressed == 105) //i
		{

			//e += 1;

		}
		if (char_pressed == 111) //o
		{
开发者ID:Hefestos,项目名称:cup2015,代码行数:66,代码来源:Main(teste-biel).cpp

示例6: _tmain


//.........这里部分代码省略.........
            SDL_FlushEvents(SDL_APP_TERMINATING, SDL_LASTEVENT); //Flush Old Events
#endif
		cout << "X Steering Wheel:" << joyinfo.dwXpos << endl;
		if(joyinfo.dwZpos != 32767)
			action = 0;
		if(action)
		{
			cout << "Z Throttle:" << 65536 << endl; //The original value of the inactivated throttle is 32767, should be modified to 65535 so that throttle is 0		
			cout << "R Break:" << 0.9*65536 << endl;
		}
		else
		{
			cout << "Z Throttle:" << joyinfo.dwZpos << endl; //If activated (moved), output real value.
			cout << "R Break:" << joyinfo.dwRpos << endl; //The same for breaks.
		}
		cout << "buttonNumber" << joyinfo.dwButtonNumber << endl;
		cout << "buttonStatus" << bitset<64>(joyinfo.dwButtons) << endl; //Output button status
		
		//Buttons:
		now_in_situ=bitset<64>(joyinfo.dwButtons)[0];
		now_any_direction=bitset<64>(joyinfo.dwButtons)[3];
		now_tradition=bitset<64>(joyinfo.dwButtons)[1];
		cout << "is_in_situ:" << is_in_situ << endl;
		cout << "is_any_direction:" << is_any_direction << endl;
		cout << "is_tradition:" << is_tradition << endl;
		
		//PostProcessing********************************************************
		if(now_in_situ== true && last_in_situ ==false)
		{
			is_in_situ =true;
			is_any_direction =false;
			is_tradition =false;

			SP->WriteData("b",1);
		}

		if(now_any_direction== true && last_any_direction ==false)
		{
			is_in_situ =false;
			is_any_direction =true;
			is_tradition =false;

			SP->WriteData("f",1);

		}

		if(now_tradition== true && last_tradition ==false)
		{
			is_in_situ =false;
			is_any_direction =false;
			is_tradition =true;
			SP->WriteData("f",1);

		}

		last_in_situ =now_in_situ;
		last_any_direction =now_any_direction;
		last_tradition =now_tradition;
		
		if(action)//Double-check that the inactivated throttle value is set to 0.
		{
			driveDutycycle = 0;
			breaking = 225;
		}
		else
		{
开发者ID:HaoguangYang,项目名称:AgileVehicle,代码行数:67,代码来源:main.cpp

示例7: main


//.........这里部分代码省略.........
    dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );

    //morphological closing (removes small holes from the foreground)
    dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
    erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );

    //Calculate the moments of the thresholded image
    Moments oMoments = moments(imgThresholded);

    double dM01 = oMoments.m01;
    double dM10 = oMoments.m10;
    double dArea = oMoments.m00;

    // if the area <= 10000, I consider that the there are no object in the image and it's because of the noise, the area is not zero
    if (dArea > 10000)
    {
        //calculate the position of the ball
        int posX = dM10 / dArea;
        int posY = dM01 / dArea;

    if (iLastX >= 0 && iLastY >= 0 && posX >= 0 && posY >= 0)
    {
    //Draw a red line from the previous point to the current point
       // line(imgLines, Point(posX, posY), Point(iLastX, iLastY), Scalar(0,0,255), 2);

        Point pt1(posX-10, posY-10);
        Point pt2(posX+10, posY+10);

        rectangle(imgLines, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
    }

        iLastX = posX;
        iLastY = posY;
    }

    Point pt3(100,100);
    Point pt4(520,380);

    rectangle(imgLines, pt3, pt4, cvScalar(0, 0, 255, 0), 1, 8, 0);

            if(iLastX-10 < 100)
                {
                //putText(image, "Your face is on the right side of me!", Point(faces[i].x, faces[i].y - 5), CV_FONT_HERSHEY_PLAIN, 1, Scalar(0,250,0), 1, 8, false );
                putText(imgLines, "The object is on the right side of me!", Point(70,90), CV_FONT_HERSHEY_PLAIN, 1, Scalar(0,250,0), 1, 8, false );

                outgoingData[0] = 'r';
                if(SP->WriteData(outgoingData, dataLength))

                Sleep(100);

                }

            if(iLastX+10 > 520)
                {
                putText(imgLines, "The object is on the left side of me!", Point(70,90), CV_FONT_HERSHEY_PLAIN, 1, Scalar(0,250,0), 1, 8, false );

                outgoingData[0] = 'l';
                if(SP->WriteData(outgoingData, dataLength))

                Sleep(100);

                }

            if(iLastY-10 > 380)
                {
                putText(imgLines, "The object is at the bottom!", Point(70,70), CV_FONT_HERSHEY_PLAIN, 1, Scalar(0,250,0), 1, 8, false );

                outgoingData[0] = 'b';
                if(SP->WriteData(outgoingData, dataLength))

                Sleep(100);

                }

            if(iLastY+10 < 100)
                {
                putText(imgLines, "The object is at the top!", Point(70,70), CV_FONT_HERSHEY_PLAIN, 1, Scalar(0,250,0), 1, 8, false );

                outgoingData[0] = 't';
                if(SP->WriteData(outgoingData, dataLength))

                Sleep(100);

                }

    imshow("Thresholded Image", imgThresholded); //show the thresholded image

    imgOriginal = imgOriginal + imgLines;
    imshow("Original", imgOriginal); //show the original image
    imgLines=cv::Scalar(0, 0, 0);

    if (cvWaitKey(33) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
            cout << "esc key is pressed by user" << endl;
            return -1;
       }
    }
	}
   return 0;
	}
开发者ID:niamleeson,项目名称:Colored-Object-Tracking-Robot-C-,代码行数:101,代码来源:main.cpp


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