想要一个VB 6 的串口控件,但不是MSComm,谢谢
解决方案 »
- 强烈要求封杀嗷嗷叫的老马,哈哈,支持我的,散分了
- 有关获取txt文档的问题
- supergrid 实现其在表格末尾,回车键加一行的事件,该如何编写?
- vsflexgrid控件一个很奇怪的问题
- 求助!急(关于数据表中数据统计的问题)
- 关于事务处理的问题?
- 请教:如何编程列出本机当前的网络连接
- 求救
- 请问如何计算vb的总代码行数?
- 谁能告诉我SHChangeNotify的详细用法(尽可能中文的),我给他100分(因为我的给分上限是40,所以这里无法一口气给100分,但我可以多提同样的问题,那样就凑得到一百分了)
- 为什么窗体里设了ICON属性,但图标显示不了?
- mscomm控件可以实现与usb端口连接的手机通讯吗
听说API也可以达到一样的目的,我帮你顶,等待高手
CreateFile就能打开串口
ReadFile、WriteFile读写数据
最后别忘了CloseHandle
MSDN上的一个例子:
Configuring a Communications Resource
The following example opens a handle to COM2 and fills in a DCB structure with the current configuration. The DCB structure is then modified and used to reconfigure the device.#include <windows.h>
#include <stdio.h>int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM2"; hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
); if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
} // Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm. fSuccess = GetCommState(hCom, &dcb); if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
} // Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit. dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit fSuccess = SetCommState(hCom, &dcb); if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
} printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
return (0);
}
串行通信相关函数说明:Communications Functions
The following functions are used with communications resources.Function Description
BuildCommDCB Fills a specified DCB structure with values specified in a device-control string.
BuildCommDCBAndTimeouts Translates a device-definition string into appropriate device-control block codes and places them into a device control block.
ClearCommBreak Restores character transmission for a specified communications device and places the transmission line in a nonbreak state.
ClearCommError Retrieves information about a communications error and reports the current status of a communications device.
CommConfigDialog Displays a driver-supplied configuration dialog box.
EscapeCommFunction Directs a specified communications device to perform an extended function.
GetCommConfig Retrieves the current configuration of a communications device.
GetCommMask Retrieves the value of the event mask for a specified communications device.
GetCommModemStatus Retrieves modem control-register values.
GetCommProperties Retrieves information about the communications properties for a specified communications device.
GetCommState Retrieves the current control settings for a specified communications device.
GetCommTimeouts Retrieves the time-out parameters for all read and write operations on a specified communications device.
GetDefaultCommConfig Retrieves the default configuration for the specified communications device.
PurgeComm Discards all characters from the output or input buffer of a specified communications resource.
SetCommBreak Suspends character transmission for a specified communications device and places the transmission line in a break state.
SetCommConfig Sets the current configuration of a communications device.
SetCommMask Specifies a set of events to be monitored for a communications device.
SetCommState Configures a communications device according to the specifications in a device-control block.
SetCommTimeouts Sets the time-out parameters for all read and write operations on a specified communications device.
SetDefaultCommConfig Sets the default configuration for a communications device.
SetupComm Initializes the communications parameters for a specified communications device.
TransmitCommChar Transmits a specified character ahead of any pending data in the output buffer of the specified communications device.
WaitCommEvent Waits for an event to occur for a specified communications device.