llitcwl(中国龙)还是上次串口通讯的问题帮我写一个API吧,

nettang 2002-02-05 12:47:14
我的邮箱是:nettang@8848.net
QQ:1306644
...全文
89 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dgzdx 2002-02-06
  • 打赏
  • 举报
回复
关注!
nettang 2002-02-06
  • 打赏
  • 举报
回复
兄弟啊!
我怎么没有收到啊!
nettang@163.net
llitcwl 2002-02-05
  • 打赏
  • 举报
回复
算了,还是发一个以前网友用COMM 写的程序吧。
llitcwl 2002-02-05
  • 打赏
  • 举报
回复
一大堆的,不好说明:
//相关API
Function Boolean CloseHandle(ulong hObject ) Library "kernel32.dll"
FUNCTION boolean ReadFile(ulong fhand, ref string lpbuffer, ulong numbyte, ref ulong bytesread, ulong lpover) LIBRARY "kernel32.dll"
FUNCTION ulong CreateFileA(ref string fname, ulong f_access, ulong f_share, ulong f_sec, ulong f_create, ulong f_flag, ulong f_attrib) LIBRARY "kernel32.dll"
Function Boolean WriteFile(uLong handle,ref string lpbuffer,ulong numbytes, ref ulong bytesread, ulong lpOverLaped) Library "Kernel32.dll"
Function Boolean GetCommProperties(ulong hFile,ref COMMPROP lpCommProp ) Library "Kernel32.dll"
Function Boolean BuildCommDCBA(ref string lpDef,ref DCB lpDCB ) Library "Kernel32.dll"
Function Boolean SetCommState(ulong hCommDev,ref DCB lpdcb ) Library "Kernel32.dll"
Function Boolean GetCommState(ulong hCommDev,ref DCB lpdcb ) Library "Kernel32.dll"
Function ulong GetLastError() Library "Kernel32.dll"
Function Boolean SetCommTimeouts(ulong hCommDev, ref COMMTIMEOUTS lpctmo ) Library "Kernel32.dll"
Function Boolean PurgeComm(ulong hCommDev, ulong fdwAction ) Library "Kernel32.dll"
//相关结构(PB中要进行相关变化,其他见我前两天的C变量与PB对应表)
typedef struct _DCB {
DWORD DCBlength; // sizeof(DCB)
DWORD BaudRate; // current baud rate
DWORD fBinary: 1; // binary mode, no EOF check
DWORD fParity: 1; // enable parity checking
DWORD fOutxCtsFlow:1; // CTS output flow control
DWORD fOutxDsrFlow:1; // DSR output flow control
DWORD fDtrControl:2; // DTR flow control type
DWORD fDsrSensitivity:1; // DSR sensitivity
DWORD fTXContinueOnXoff:1; // XOFF continues Tx
DWORD fOutX: 1; // XON/XOFF out flow control
DWORD fInX: 1; // XON/XOFF in flow control
DWORD fErrorChar: 1; // enable error replacement
DWORD fNull: 1; // enable null stripping
DWORD fRtsControl:2; // RTS flow control
DWORD fAbortOnError:1; // abort on error
DWORD fDummy2:17; // reserved
WORD wReserved; // not currently used
WORD XonLim; // transmit XON threshold
WORD XoffLim; // transmit XOFF threshold
BYTE ByteSize; // number of bits/byte, 4-8
BYTE Parity; // 0-4=no,odd,even,mark,space
BYTE StopBits; // 0,1,2 = 1, 1.5, 2
char XonChar; // Tx and Rx XON character
char XoffChar; // Tx and Rx XOFF character
char ErrorChar; // error replacement character
char EofChar; // end of input character
char EvtChar; // received event character
WORD wReserved1; // reserved; do not use
} DCB;

//简单代码示例
//打开串口及初始化
dcb lst_dcb
ulong ll_hnd
//打开串口
ll_hnd = CreateFileA('com1',3221225472,0,0,3,128,0)
//设置串口
//初始化DCB
BuildCommDcbA ( '9600,N,8,1', lst_dcb )
setcommstate ( ll_hnd, lst_dcb )

//写串口
ulong lu_byte, lu_numbytes
string ls_buff
ulong ul_temp
setnull(ul_temp)
string ls_temp
ls_temp=char(27) + char(67) + char(ai_line+ads_1.dynamic rowcount( ))
writefile ( ll_hnd, ls_temp, len(ls_temp),lu_byte,ul_temp)
lionkings 2002-02-05
  • 打赏
  • 举报
回复
老兄﹐我也需要一個串口通信的程序﹐幫幫忙﹐有的話咱討論討論如何﹖
nettang 2002-02-05
  • 打赏
  • 举报
回复
dsadsd

401

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧