关于DLL调用-USB转485中的串口参数如何设置-有偿!
本帖最后由 sddnothing 于 2011-2-12 11:26 编辑原程序中参数设置格式为:ret=sio_ioctl(2,B38400,P_NONE|BIT_8|STOP_1);
在进行DLL调用时,怎么进行参数设置?
目的:使用hexin USB转485或DT5011 USB转485 进行数据通信,能提供详细源程序或指导的可邮件联系商谈报酬。两种转接线我都有驱动光盘。chongzhoud@Hotmail.com
有这个介绍
Language Syntax
C/C++ int WINAPI sio_ioctl(int port, int baud, int mode)
Visual Basic Function sio_ioctl(ByVal port As Long, ByVal baud As Long, ByVal mode As Long) As Long
Delphi function sio_ioctl(port, baud, mode: Longint): Longin
Argument:
port = COM port number
baud = (bits/sec)
0 = 50 6 = 600 12 = 9600 18 = 460800
1 = 75 7 = 1200 13 = 19200 19 = 921600
2 = 110 8 = 1800 14 = 38400
3 = 134.5 9 = 2400 15 = 57600
4 = 150 10 = 4800 16 = 115200
5 = 300 11 = 7200 17 = 230400
Note: Some COM ports may not support higher speed. Please refer to the COM port's manual for more information.
mode = bit_cnt OR stop_bit OR parity
bit_cnt (bit 0, 1) = 0x00 = bit_5
0x01 = bit_6
0x02 = bit_7
0x03 = bit_8
stop_bit (bit 2) = 0x00 = stop_1
0x04 = stop_2
parity (bit 3,4 5) = 0x00 = none
0x08 = odd
0x18 = even
0x28 = mark
0x38 = space
Return:
SIO_OK OK
SIO_BADPORT Port is not opened in advance
SIO_BADPARM Bad parameter
SIO_WIN32FAIL Calling Win32 function failed
Call GetLastError to get the error code
Example:
Configure COM2 communication parameter:
Baud rate = 38400, Parity = NONE, Data bits = 8, Stop bits = 1
C/C++
ret = sio_ioctl ( 2, B38400, P_NONE | BIT_8 | STOP_1 );
if (ret != SIO_OK) {
/* Setting fail*/
} /* PComm_c.h
* PComm define file for Win32 on C/C++
* History:
* Date Author Comment
* 10/22/1996Victor wrote it.
* 03/28/1997Victor modified. add sio_term_irq function.
* add sio_linput function.
* 04/29/1997Victor modified. add sio_putb_x function.
* 05/21/1997Victor modified. add sio_view function.
* 06/13/1997Victor modified. add file transfer function.
* 06/30/1997Victor modified. add sio_TxLowWater function.
* 11/17/1997Victor add sio_AbortWrite, sio_SetWriteTimeouts
* 11/21/1997Victor add sio_SetReadTimeouts, sio_AbortRead
* sio_GetReadTimeouts, sio_GetWriteTimeouts
* 03/08/1998Casper support VB 5.0
*
* 04/27/1999Casper add sio_ActXon, sio_ActXoff, sio_break_ex
*/
/* BAUD rate setting */
#define B50 0x00
#define B75 0x01
#define B110 0x02
#define B134 0x03
#define B150 0x04
#define B300 0x05
#define B600 0x06
#define B1200 0x07
#define B1800 0x08
#define B2400 0x09
#define B4800 0x0A
#define B7200 0x0B
#define B9600 0x0C
#define B19200 0x0D
#define B38400 0x0E
#define B57600 0x0F
#define B115200 0x10
#define B230400 0x11
#define B460800 0x12
#define B921600 0x13
/* MODE setting */
#define BIT_5 0x00 /* Word length define */
#define BIT_6 0x01
#define BIT_7 0x02
#define BIT_8 0x03
#define STOP_1 0x00 /* Stop bits define */
#define STOP_2 0x04
#define P_EVEN 0x18 /* Parity define */
#define P_ODD 0x08
#define P_SPC 0x38
#define P_MRK 0x28
#define P_NONE 0x00
/* MODEM CONTROL setting */
#define C_DTR 0x01
#define C_RTS 0x02
/* MODEM LINE STATUS */
#define S_CTS 0x01
#define S_DSR 0x02
#define S_RI 0x04
#define S_CD 0x08
/* error code */
#define SIO_OK 0
#define SIO_BADPORT -1 /* no such port or port not opened */
#define SIO_OUTCONTROL -2 /* can't control the board */
#define SIO_NODATA -4 /* no data to read or no buffer to write */
#define SIO_OPENFAIL -5 /* no such port or port has be opened */
#define SIO_RTS_BY_HW -6 /* RTS can't set because H/W flowctrl */
#define SIO_BADPARM -7 /* bad parameter */
#define SIO_WIN32FAIL -8 /* call win32 function fail, please call */
/* GetLastError to get the error code */
#define SIO_BOARDNOTSUPPORT -9 /* Does not support this board */
#define SIO_FAIL -10 /* PComm function run result fail */
#define SIO_ABORTWRITE -11 /* write has blocked, and user abort write */
#define SIO_WRITETIMEOUT -12 /* write timeoue has happened */
/* file transfer error code */
#define SIOFT_OK 0
#define SIOFT_BADPORT -1 /* no such port or port not open */
#define SIOFT_TIMEOUT -2 /* protocol timeout */
#define SIOFT_ABORT -3 /* user key abort */
#define SIOFT_FUNC -4 /* func return abort */
#define SIOFT_FOPEN -5 /* can not open files */
#define SIOFT_CANABORT -6 /* Ymodem CAN signal abort */
#define SIOFT_PROTOCOL -7 /* Protocol checking error abort */
#define SIOFT_SKIP -8 /* Zmodem remote skip this send file */
#define SIOFT_LACKRBUF -9 /* Zmodem Recv-Buff size must >= 2K bytes */
#define SIOFT_WIN32FAIL -10 /* OS fail */
/* GetLastError to get the error code */
#define SIOFT_BOARDNOTSUPPORT -11 /* Does not support board */
#ifdef __cplusplus
extern "C" {
#endif
/* basic function phototype */
intWINAPI sio_ioctl(int port, int baud, int mode);
intWINAPI sio_getch(int port);
intWINAPI sio_read(int port, char *buf, int len);
intWINAPI sio_putch(int port, int term);
intWINAPI sio_write(int port, char *buf, int len);
intWINAPI sio_flush(int port, int func);
long WINAPI sio_iqueue(int port);
long WINAPI sio_oqueue(int port);
intWINAPI sio_lstatus(int port);
intWINAPI sio_lctrl(int port, int mode);
intWINAPI sio_cnt_irq(int port, VOID (CALLBACK *func)(int port), int count);
intWINAPI sio_modem_irq(int port, VOID (CALLBACK *func)(int port));
intWINAPI sio_break_irq(int port, VOID (CALLBACK *func 不知道是否符合你的实际情况:
把转换器插到电脑上,安装上驱动,此时,硬件管理器里面就会以串口的形式显示该转换器,你在编程时,按串口操作就够了,不需要在对dll进行调用。
我的PXI上也扩展了一个,就是这么做的。
设备管理器能找到端口,但labview的visa找不到。。。所以只要用这个麻烦的办法了。。。 sddnothing 发表于 2011-2-14 13:23 static/image/common/back.gif
设备管理器能找到端口,但labview的visa找不到。。。所以只要用这个麻烦的办法了。。。
labview的VISA中看不到串口要装上VISA就好了 我没说清楚。。。。有visa.但使用后找不到串口,
页:
[1]