# 无法从串列埠送出CHR$(128~254)之字元码

Posted by lison on December 14, 1998 at 17:10:18:

缘起: vb6.0内有一通讯元件MSCOMM32.OCX(或vb6.0_16位元版MSCOMM16.OCX),使用上有
颇多之限制.

例如:
MSCOMM32.OCX :无法从串列埠送出CHR$(128~254)之字元码
MSCOMM16.OCX :无法从串列埠送出CHR$(&H0)及CHR$(&HFF)这两个字元码

所以想利用WIN32C API函式来完成一简易通讯程式却一直不得其门而入
若有先进于此方面有心得,盼能拨沉指导不胜感激.

说明: 在WINDOWS95里,串列埠与其它的通讯设备都被视为档案来处理,故以档案开/关
和读/写的函式来处理串列埠.
1.从呼叫CreatFile函式开始:CreatFile函式可将串列埠打开为读取或写入之用,
而且传回此打开的串列埠之控制标帜(handle),由于CreatFile函式是个通用型
函式,故内容颇为复杂.
底下为小弟所写之程式,但其传回值(hcomm)却使终传回-1,应该是参数的传输上出了问题

****从API检视员COPY下来之宣告 *******
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
**************************************

Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING& = 3
Public Const FILE_FLAG_OVERLAPPED = &H40000000

Function RDSEC$()
Dim hcomm As Long
hcomm = CreateFile("COM2", ByVal GENERIC_WRITE, 0&,0&, ByVal OPEN_EXISTING, ByVal FILE_FLAG_OVERLAPPED, 0&)
hcommerror& = GetLastError()
End Function

Follow Ups:

- Re: 无法从串列埠送出CHR$(128~254)之字元码 Andy 11:31:02 2/09/99 (0)
- Re: 无法从串列埠送出CHR$(128~254)之字元码 Roger 14:20:12 12/15/98 (0)
- Re: 无法从串列埠送出CHR$(128~254)之字元码 靓仔 18:47:30 12/14/98 (0)