本文介绍了串口通信使用Visual Studio 2008和C(用于Arduino的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数据发送到我的Arduino板使用Visual Studio和C.
我特别需要用C,因为我使用ARToolKit获得标记,并相应地发送数据。
I want to send data to my Arduino board using Visual Studio and C.I specifically need to use C since I am using ARToolKit to get markers and sending the data accordingly.
我试图在code
#include<stdio.h>
#include<stdlib.h>
void main()
{
system( "MODE COM9: BAUD=9600 PARITY=n DATA=8 STOP=1" ) ;
FILE port = fopen( "COM9:", "wb" ) ;
printf("hello");
fprintf( port, "s" ) ;
fclose( port ) ;
}
,但它不获取编译。
but it is not getting compiled.
我只需要发送数据。
推荐答案
我从您的文章,您需要发送邮件使用Visual Studio的不写一个程序,Flash或任何其他的东西,数据的理解。下面是我给你我的机器上做它的工作原理发送文本测试的例子。
I understood from your post that you need to send data using visual studio not to write a program to flash or any other stuff. Here is an example i made for you on my machine it works sending the text test.
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
char test[] = "Hello";
HANDLE hDevice = CreateFile(L"COM2",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0);
if (hDevice !=INVALID_HANDLE_VALUE)
{
printf("Port opened! \n");
DCB lpTest;
GetCommState(hDevice,&lpTest);
lpTest.BaudRate = CBR_9600;
lpTest.ByteSize = 8;
lpTest.Parity = NOPARITY;
lpTest.StopBits = ONESTOPBIT;
SetCommState(hDevice,&lpTest);
DWORD btsIO;
WriteFile(hDevice,test,strlen(test),&btsIO,NULL);
CloseHandle(hDevice);
}
_getch();
return 0;
}
这篇关于串口通信使用Visual Studio 2008和C(用于Arduino的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!