/************************************************************************
TimeOut.c
-- Main module for read & write timeout setting example program.
Description:
1.Select "setting..." menu item to set com port option.
2.Select "Open" menu item to open com port.
After selected "Open" from menu, you can select
"Timeout Demo" to test timeout status.
Polling Write:
sio_write() will return immediately. The data will be
copied to driver,but do not really wrtie to com port. This
operation will maybe let sio_write() return 0, means that
not enough buffer to write. Be careful this polling operation
will 'eat' a large amount of system resource, including
memory, processor time.
Block Write:
sio_write() will block until the all data has be write to
com port (But maybe some data is still in com port output
buffer when sio_write() return). You can check the sio_write()
elapsed time. This operation is suitable to using another
thread to write data. Then you can call sio_AbortWrite()
to abort write operation in main thread when you want to
stop writing.
Block Write (Timeout):
This operation is the same as "Block Write". The difference
is that, sio_write() will block until the tiemout is arrived
or the all data has be write to com port. You can decrease
the timeout value to check the difference.
Polling Read:
sio_read() will return immediately. sio_read() just checks
input buffer, gets all buffer data (maybe less than or equal
to that sio_read() want to read), then returns. If no data in
buffer, sio_read() return 0. Be careful this polling operation
will 'eat' a large amount of system resource, including memory,
processor time.
Block Read:
sio_read() will block until the input buffer data length is
equal to that sio_read() want to read. This operation is
suitable to using another thread to read data. Then you can
call sio_AbortRead() to abort read operation in main thread
when you want to stop reading.
Block Read (Total Timeout):
This operation is the saem as "Block Read". The difference
is that, sio_read() will block until timeout is arrived or
the input buffer data length is equal to that sio_read()
want to read.You can decrease the timeout value to check
the difference.
In this example, you can connect to terminal. Then you can
try 2 cases from terminal:
send 10240 bytes,
or wait the timeout is arrived.
Check the sio_read() elapsed time.
Block Read (Interval Timeout):
sio_read() will wait the first byte arrived, then begin
interval timeout checking.sio_read will block until the
interval timeout is arrived or the input buffer data length
is equal to that sio_read() want to read.
In this example, you can connect to terminal. Then you can
try 2 cases from terminal:
send 1 or 2 byte,
send 10240 bytes,
Check the sio_read() elapsed time.
Block Read ( Total+Interval Timeout ):
sio_read() will block until the timeout is arrived or the
input buffer data length is equdal to that sio_read() want
to read.
In this example, you can connect to terminal. Then you can
try 3 cases from terminal :
send 1 or 2 byte,
send 10240 bytes,
send > 10240 bytes
Check the sio_read() elapsed time.
3.Select "Close" menu item to close com port.
This program demo:
How to set write timeout(sio_SetWriteTimeouts());
How to set read timeout(sio_SetReadTimeouts());
How to abort write process(sio_AbortWrite());
How to abort read process(sio_AbortRead());
Use function:
sio_open, sio_close, sio_ioctl,
sio_flowctrl, sio_DTR, sio_RTS,
sio_read, sio_write,
sio_SetWriteTimesout, sio_SetReadTimeouts,
sio_AbortWrite, sio_AbortRead;
History: Date Author Comment
3/1/98 Casper Wrote it.
*************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include "PComm.h"
#include "mxtool.h"
#include "resource.h"
#include "comm.h"
#define BUFLEN (10*1024)
HINSTANCE GhInst;
COMMDATA GCommData;
BOOL GbOpen;
HANDLE GhExit;
DWORD GDifTime;
DWORD GCount;
DWORD GCallCount;
char GszAppName[] = "TimeOut Setting Demo";
static char _GBuf[BUFLEN];
static HANDLE hWriteThread;
static HANDLE hReadThread;
static HWND GhWnd;
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK PortDlgProc(HWND hDlg,UINT iMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK AboutDlgProc(HWND hDlg,UINT iMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK WStatDlgProc(HWND hDlg,UINT iMsg,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK RStatDlgProc(HWND hDlg,UINT iMsg,WPARAM wParam,LPARAM lParam);
static void SwitchMenu(HWND hwnd);
static BOOL OpenPort(void);
static BOOL ClosePort(void);
static BOOL PortSet(void);
static void ShowStatus(void);
UINT WriteProc( LPVOID pParam );
UINT ReadProc( LPVOID pParam );
void DemoWriteTimeout(int port,UINT testitem);
void DemoReadTimeout(int port,UINT testitem);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
PSTR szCmdLine,int iCmdShow)
{
WNDCLASSEX wndclass;
HWND hwnd;
MSG msg;
GhInst = hInstance;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = MAKEINTRESOURCE(IDM_TIMEOUT);
wndclass.lpszClassName = GszAppName;
wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wndclass);
hwnd = CreateWindow(GszAppName,
GszAppName,
WS_OVERLAPPEDWINDOW ,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,NULL,
hInstance,
NULL);
GhWnd = hwnd;
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
{
switch(iMsg){
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDM_PORT_OPEN:
OpenPort();
return 0;
case IDM_PORT_CLOSE:
ClosePort();
return 0;
case IDM_PORT_SETTING:{
COMMDATA bakdata = GCommData;
if(DialogBox(GhInst,MAKEINTRESOURCE(IDD_OPEN),hwnd,PortDlgProc)==IDCANCEL)
return 0;
if(GbOpen)
if (!PortSet())
GCommData = bakdata;
return 0;
}
case IDM_WRITE_POLL:
case IDM_WRITE_BLOCK:
case IDM_WRITE_TIMEOUT:
DemoWriteTimeout(GCommData.Port,LOWORD(wParam));
return 0;
case IDM_READ_POLL:
case IDM_READ_BLOCK:
case IDM_READ_BLOCK_T:
case IDM_READ_BLOCK_I:
case IDM_READ_BLOCK_TI:
DemoReadTimeout(GCommData.Port,LOWORD(wParam));
return 0;
case IDM_HELP_ABOUT:
DialogBox(GhInst,MAKEINTRES
没有合适的资源?快使用搜索试试~ 我知道了~
pComm-Example.rar_Delphi PCOMM 串口_PCOMM免费_delphi pcomm_moxa exam
共96个文件
pas:20个
frm:13个
c:13个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 68 浏览量
2022-09-21
07:53:29
上传
评论
收藏 94KB RAR 举报
温馨提示
台湾MOXA公司的串口通讯卡的示例,包括 C + Delphi.
资源详情
资源评论
资源推荐
收起资源包目录
pComm-Example.rar (96个子文件)
pComm-Example
Delphi
Irqdemo
Irqproc.pas 2KB
Irqdemom.dfm 910B
Irqdemom.pas 8KB
Irqdemo.dpr 495B
Portstat
Pstatm.dfm 984B
Statdlg.pas 5KB
Portstat.dpr 590B
Pstatm.pas 6KB
Statdlg.dfm 3KB
Config.pas 3KB
Config.dfm 2KB
Readthd.pas 2KB
Exglobal.pas 3KB
Timeout
Tmoutm.dfm 2KB
Rstat.pas 973B
Wstat.pas 972B
Tmoutm.pas 11KB
Rstat.dfm 884B
Timeout.dpr 662B
Tothread.pas 2KB
Wstat.dfm 891B
About.dfm 530B
Mxtool.pas 2KB
Pcomm.pas 9KB
Ftrans
Ftransm.dfm 981B
Ftrans.dpr 740B
Dirdlg.pas 1KB
Fstat.pas 2KB
Dirdlg.dfm 842B
Fset.pas 1KB
Ftransm.pas 7KB
Fset.dfm 825B
Fstat.dfm 1KB
Ftproc.pas 5KB
Simple
Simplem.dfm 960B
Simple.dpr 502B
Simplem.pas 6KB
About.pas 1014B
C
Mxtool.h 131B
Irqdemo
Irqdemo.rc 583B
Irqdemo.c 13KB
Irqdemo.bc 1KB
Irqdemo.vc 941B
Resource.h 6KB
Portstat
Portstat.c 13KB
Statdlg.c 6KB
Portstat.vc 1KB
Portstat.bc 1KB
Portstat.rc 3KB
Pdlg.rc 3KB
Timeout
Timeout.rc 2KB
Timeout.vc 1KB
Timeout.c 16KB
Timeout.bc 1KB
Stat.c 2KB
Comm.c 6KB
Mxtool.c 2KB
Ftrans
Ftrans.bc 1KB
Ftrans.vc 1KB
Ftset.c 2KB
Ftrans.c 15KB
Ftproc.c 7KB
Fstatus.c 3KB
Ftrans.h 651B
Ftrans.rc 5KB
Comm.h 527B
Simple
Simple.bc 1KB
Simple.vc 926B
Simple.c 12KB
Simple.rc 461B
About.c 1KB
Vb
Irqdemo
Irqdemo.vbp 672B
Irqdemo.frm 10KB
Irqfunc.bas 1KB
Portstat
Portstat.vbp 641B
Statdlg.frm 11KB
Portstat.frm 8KB
Timeout
Timeout.frm 14KB
Wstat.frm 3KB
Rstat.frm 3KB
Timeproc.bas 2KB
Timeout.vbp 706B
Mxtool.bas 2KB
Config.frx 299B
Ftrans
Fset.frm 5KB
Ftrans.frm 9KB
Dir.frm 3KB
Ftproc.bas 8KB
Ftrans.vbp 777B
Ftstat.frm 4KB
Config.frm 7KB
Simple
Simple.vbp 638B
Simple.frm 9KB
About.frm 1KB
Global.bas 4KB
Pcomm.bas 9KB
共 96 条
- 1
JonSco
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0