我从您的帖子中了解到,您需要使用 Visual Studio 发送数据,而不是编写 Flash 程序或任何其他东西。这是我在我的机器上为你制作的一个例子,它可以发送文本测试。
#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;
}