- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 C++ 和 Qt 通过 GPIB 与连接到 Windows PC 的 Yokogawa GS200 直流电源进行通信。
我从 Yokogawa ( https://y-link.yokogawa.com/YL008.po?V_ope_type=Show&Download_id=DL00002096&Language_id=EN ) 找到了一个可以完成任务的库;然而,当我尝试运行一个简单的代码时,它编译没有错误,但是没有输出或任何函数执行的迹象。我只会得到“按
我不确定到底出了什么问题,有人有什么想法吗?
代码和头文件如下:
主要内容:
#include "tmctl.h"
int main()
{
char adr[100];
int ret;
int id;
char buf[1000];
int length;
ret = TmcInitialize( TM_CTL_GPIB, "11", &id );
if( ret != 0 ) {
return TmcGetLastError( id );
}
ret = TmcSetTerm( id, 3, 1 );
if( ret != 0 ) {
return TmcGetLastError( id );
}
ret = TmcSetTimeout( id, 300 );
if( ret != 0 ) {
return TmcGetLastError( id );
}
ret = TmcSetRen( id, 1 );
if( ret != 0 ) {
return TmcGetLastError( id );
}
/* sending *RST */
ret = TmcSend( id, "*RST" );
if( ret != 0 ) {
return TmcGetLastError( id );
}
/* *sending IDN? & receiving query */
ret = TmcSend( id, "*IDN?" );
if( ret != 0 ) {
return TmcGetLastError( id );
}
ret = TmcReceive( id, buf, 1000, &length );
if( ret != 0 ) {
return TmcGetLastError( id );
}
}
标题:
/*STARTM------------------------------------------------------------------
+ Module Name : tmctl.h +
+ Abstract : Yokogawa T&M Remote Control functions. +
+ Revision History: +
+ Rev. Date. Notes. +
+ -------------------------------------------------------------- +
+ 2.0 20070309 USBTMC2 VXI11 supported. thread safe support +
+ 2.1 20080508 RS232C expand +
+ 2.2 20080704 Add TmcGetInitializeError. +
+ 2.3 20121121 coped 64 bits +
-ENDM-------------------------------------------------------------------*/
#ifndef _TMCTL_H
#define _TMCTL_H 1
#include <windows.h>
/* Control setting */
#define TM_NO_CONTROL 0
#define TM_CTL_GPIB 1
#define TM_CTL_RS232 2
#define TM_CTL_USB 3
#define TM_CTL_ETHER 4
#define TM_CTL_USBTMC 5
#define TM_CTL_ETHERUDP 6
#define TM_CTL_USBTMC2 7 // 2007/01/19 add
#define TM_CTL_VXI11 8 // 2007/01/19 add
#define TM_CTL_USB2 9
/* GPIB */
/* RS232 */
#define TM_RS_1200 '0'
#define TM_RS_2400 '1'
#define TM_RS_4800 '2'
#define TM_RS_9600 '3'
#define TM_RS_19200 '4'
#define TM_RS_38400 '5'
#define TM_RS_57600 '6'
#define TM_RS_115200 '7' // Ver2.1
#define TM_RS_8N1 '0'
#define TM_RS_7E '1'
#define TM_RS_7O '2'
#define TM_RS_8O '3' // Ver2.1 8bit,odd,onestopbit
#define TM_RS_7N5 '4' // Ver2.1 7bit,noparity,one5stopbit
#define TM_RS_8N2 '5'
#define TM_RS_NO '0'
#define TM_RS_XON '1'
#define TM_RS_HARD '2'
/* USB */
#define TM_USB_CHECK_OK 0
#define TM_USB_CHECK_NOTOPEN 1
#define TM_USB_CHECK_NODEVICE 2
#define TM_USB_READPIPE 0
#define TM_USB_WRITEPIPE 1
#define TM_USB_STATUSPIPE 2
/* Error Number */
#define TMCTL_NO_ERROR 0x00000000 /* No error */
#define TMCTL_TIMEOUT 0x00000001 /* Timeout */
#define TMCTL_NO_DEVICE 0x00000002 /* Device Not Found */
#define TMCTL_FAIL_OPEN 0x00000004 /* Open Port Error */
#define TMCTL_NOT_OPEN 0x00000008 /* Device Not Open */
#define TMCTL_DEVICE_ALREADY_OPEN 0x00000010 /* Device Already Open */
#define TMCTL_NOT_CONTROL 0x00000020 /* Controller Not Found */
#define TMCTL_ILLEGAL_PARAMETER 0x00000040 /* Parameter is illegal */
#define TMCTL_SEND_ERROR 0x00000100 /* Send Error */
#define TMCTL_RECV_ERROR 0x00000200 /* Receive Error */
#define TMCTL_NOT_BLOCK 0x00000400 /* Data is not Block Data */
#define TMCTL_SYSTEM_ERROR 0x00001000 /* System Error */
#define TMCTL_ILLEGAL_ID 0x00002000 /* Device ID is Illegal */
#define TMCTL_NOT_SUPPORTED 0x00004000 /* this feature not supportred */
#define TMCTL_INSUFFICIENT_BUFFER 0x00008000 /* unsufficient buffer size */
/* L2 Error Number */
#define TMCTL2_NO_ERROR (00000) /* No error */
#define TMCTL2_TIMEOUT (10001) /* Timeout */
#define TMCTL2_NO_DEVICE (10002) /* Device Not Found */
#define TMCTL2_FAIL_OPEN (10003) /* Open Port Error */
#define TMCTL2_NOT_OPEN (10004) /* Device Not Open */
#define TMCTL2_DEVICE_ALREADY_OPEN (10005) /* Device Already Open */
#define TMCTL2_NOT_CONTROL (10006) /* Controller Not Found */
#define TMCTL2_ILLEGAL_PARAMETER (10007) /* Parameter is illegal */
#define TMCTL2_SEND_ERROR (10008) /* Send Error */
#define TMCTL2_RECV_ERROR (10009) /* Receive Error */
#define TMCTL2_NOT_BLOCK (10010) /* Data is not Block Data */
#define TMCTL2_SYSTEM_ERROR (10011) /* System Error */
#define TMCTL2_ILLEGAL_ID (10012) /* Device ID is Illegal */
#define TMCTL2_NOT_SUPPORTED (10013) /* this feature not supportred */
#define TMCTL2_INSUFFICIENT_BUFFER (10014) /* unsufficient buffer size */
#define ADRMAXLEN (64)
typedef struct _Devicelist
{
char adr[ADRMAXLEN] ;
} DEVICELIST ;
typedef struct _DevicelistEx
{
char adr[ADRMAXLEN] ;
unsigned short vendorID ;
unsigned short productID ;
char dummy[188] ;
} DEVICELISTEX ;
typedef void(__stdcall *Hndlr)(int, UCHAR, ULONG, ULONG) ;
/* Functions */
#ifndef _TMCTL_DEFINES
#ifdef __cplusplus
extern "C" {
#endif
extern int __stdcall TmcInitialize( int wire, char* adr, int* id ) ;
extern int __stdcall TmcSetIFC( int id, int tm ) ;
extern int __stdcall TmcDeviceClear( int id ) ;
extern int __stdcall TmcDeviceTrigger( int id ) ;
extern int __stdcall TmcSend( int id, char* msg ) ;
extern int __stdcall TmcSendByLength( int id, char* msg, int len ) ;
extern int __stdcall TmcSendSetup( int id ) ;
extern int __stdcall TmcSendOnly( int id, char* msg, int len, int end ) ;
extern int __stdcall TmcReceive( int id, char* buff, int blen, int* rlen ) ;
extern int __stdcall TmcReceiveSetup( int id ) ;
extern int __stdcall TmcReceiveOnly( int id, char* buff, int blen, int* rlen ) ;
extern int __stdcall TmcReceiveBlockHeader( int id, int* len ) ;
extern int __stdcall TmcReceiveBlockData( int id, char* buff, int blen, int* rlen, int* end ) ;
extern int __stdcall TmcCheckEnd( int id ) ;
extern int __stdcall TmcSetCmd( int id, char* cmd ) ;
extern int __stdcall TmcSetRen( int id, int flag ) ;
extern int __stdcall TmcGetLastError( int id ) ;
extern int __stdcall TmcGetDetailLastError( int id ) ;
extern int __stdcall TmcCheckError( int id, int sts, char* msg, char* err ) ;
extern int __stdcall TmcSetTerm( int id, int eos, int eot ) ;
extern int __stdcall TmcSetEos( int id, unsigned char eos ) ;
extern int __stdcall TmcSetTimeout( int id, int tmo ) ;
extern int __stdcall TmcSetDma( int id, int flg ) ;
extern int __stdcall TmcGetStatusByte( int id, unsigned char* sts ) ;
extern int __stdcall TmcFinish( int id ) ;
extern int __stdcall TmcSearchDevices(int wire, DEVICELIST* list, int max, int* num,char* option) ;
extern int __stdcall TmcSearchDevicesEx(int wire, DEVICELISTEX* list, int max, int* num,char* option) ;
extern int __stdcall TmcWaitSRQ(int id, char* stsbyte, int tout) ;
extern int __stdcall TmcAbortWaitSRQ(int id) ;
extern int __stdcall TmcSetCallback(int id,Hndlr func, ULONG p1, ULONG p2) ;
extern int __stdcall TmcResetCallback(int id) ;
extern int __stdcall TmcSendTestData(int id, char* msg, int len ) ;
extern int __stdcall TmcReceiveTestData( int id, char* buff, int blen, int* rlen ) ;
extern int __stdcall TmcInitiateAbortBulkIn(int id, UCHAR tagNo) ;
extern int __stdcall TmcInitiateAbortBulkOut(int id, UCHAR tagNo) ;
extern int __stdcall TmcCheckAbortBulkInStatus(int id) ;
extern int __stdcall TmcCheckAbortBulkOutStatus(int id) ;
extern int __stdcall TmcEncodeSerialNumber(char* encode,size_t len,char* src) ;
extern int __stdcall TmcDecodeSerialNumber(char* decode,size_t len,char* src) ;
extern int __stdcall TmcGotoLocal( int id ) ;
extern int __stdcall TmcLocalLockout(int id) ;
extern int __stdcall TmcAbortPipe(int id,long pipeNo) ;
extern int __stdcall TmcResetPipe(int id,long pipeNo) ;
extern int __stdcall TmcWriteHeader(int id, int blen) ;
extern int __stdcall TmcReceiveWithoutWriteHeader(int id, char* buff, int blen, int* rlen, int* end ) ;
extern int __stdcall TmcGetTagNo(int id, UCHAR* tag) ;
extern int __stdcall TmcSendByLength2( int id, char* msg, int msgSize, int len, CHAR eof) ;
extern int __stdcall TmcDeviceChangeNotify(HWND hWnd, BOOL bStart) ;
extern int __stdcall TmcCheckUSB(int id) ;
extern int __stdcall TmcGetPipeNo(int id,int type,int* pipeNo) ;
extern int __stdcall TmcCheckGUID(void *lParam) ;
extern ULONG __stdcall TmcGetInitializeError() ;
// L2
extern int __stdcall xTmcSearchDevices(int wire, DEVICELIST* adrlist, int max, int *num,char* option) ;
extern int __stdcall xTmcSearchDevicesEx(int wire, DEVICELISTEX* adrlist, int max, int *num,char* option) ;
extern int __stdcall xTmcInitialize( int wire, char* adr, int* id ) ;
extern int __stdcall xTmcInitializeEx( int wire, char* adr, int* id, int timeout ) ;
extern int __stdcall xTmcFinish( int id ) ;
extern int __stdcall xTmcSend( int id, char* msg ) ;
extern int __stdcall xTmcSendByLength( int id, char* msg, int len ) ;
extern int __stdcall xTmcSendSetup( int id ) ;
extern int __stdcall xTmcSendOnly( int id, char* msg, int len, int end ) ;
extern int __stdcall xTmcReceive( int id, char* buff, int blen, int* rlen ) ;
extern int __stdcall xTmcReceiveSetup( int id ) ;
extern int __stdcall xTmcReceiveOnly( int id, char* buff, int blen, int* rlen ) ;
extern int __stdcall xTmcReceiveBlockHeader( int id, int* length ) ;
extern int __stdcall xTmcReceiveBlockData( int id, char* buff, int blen, int* rlen, int* end ) ;
extern int __stdcall xTmcCheckEnd( int id ) ;
extern int __stdcall xTmcDeviceClear( int id ) ;
extern int __stdcall xTmcSetRen( int id, int flag ) ;
extern int __stdcall xTmcGetLastError( int id ) ;
extern int __stdcall xTmcSetTerm( int id, int eos, int eot ) ;
extern int __stdcall xTmcSetTimeout( int id, int tmo ) ;
extern int __stdcall xTmcCreateSRQHandler( int id, UINT msgId, HWND hWnd) ;
extern int __stdcall xTmcDleateSRQHandler( int id ) ;
extern int __stdcall xTmcSetCallback(int id,Hndlr func, ULONG p1, ULONG p2) ;
extern int __stdcall xTmcResetCallback(int id) ;
extern int __stdcall xTmcSet( int id, char *msg) ;
extern int __stdcall xTmcSetBinary( int id, char* msg, char *buf, int size ) ;
extern int __stdcall xTmcGet( int id, char *msg, char* buf, int blen, int* rlen ) ;
extern int __stdcall xTmcGetBinary( int id, char *msg, char* buf, int blen, int* rlen ) ;
extern int __stdcall xTmcGetErrorQueue(int id) ;
extern int __stdcall xTmcSetNE( int id, char *msg) ;
extern int __stdcall xTmcSetBinaryNE( int id, char* msg, char *buf, int size ) ;
extern int __stdcall xTmcGetNE( int id, char *msg, char* buf, int blen, int* rlen ) ;
extern int __stdcall xTmcGetBinaryNE( int id, char *msg, char* buf, int blen, int* rlen ) ;
extern int __stdcall xTmcSetNES( int id, char *msg) ;
extern int __stdcall xTmcSetBinaryNES( int id, char* msg, char *buf, int size ) ;
extern int __stdcall xTmcLock( int id ) ;
extern int __stdcall xTmcUnlock( int id ) ;
#ifdef __cplusplus
}
#endif
#endif
#endif
除 .dll 文件外,函数和变量的描述可以在库文件夹中找到 here .
当然,我也使用 LIBS += "...\tmctl.dll"
将库链接到我的项目。
最佳答案
好的,所以代码可以正常工作。我不确定如何(它与我上面的代码完全相同)。
但唯一的区别是我尝试使用 VS 运行代码,为此我将 dll 文件添加到 (C\windows\system) 目录。在它在那里工作之后,我想在 Qt 中再试一次,结果竟然成功了!
尽管我怀疑系统目录中的 dll 文件是否有任何影响,因为我在将它包含在 Qt 中时引用了另一个位置。
如果有人有任何见解或理论,请随时分享。
关于c++ - 使用 Qt 通过 GPIB 编程电源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35481587/
我正在使用 Qt 语言学家翻译一个 ui 文件。我使用 lupdate 获取了它的 ts 文件,并翻译了这些单词和短语。现在我想将它添加到我的代码中,但我从它的教程中发现我似乎必须将 tr() 添加到
我想在 Qt Creator 中创建下面的简单控制台应用程序: #include int main(int argc, char* argv[]) { std::cout #include
我想将 libQtGui.so.4 libQtNetwork.so.4 和 libQtCore.so.4 包含在与我的应用程序所在的目录相同的目录中。我如何让 Qt 理解这一点? y 目的是拥有一个使
我有一个充满 QPushButtons 和 QLabels 以及各种其他有趣的 QWidget 的窗口,所有这些都使用各种 QLayout 对象动态布局...而我想做的是偶尔制作一些这些小部件变得不可
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
我想知道 Qt 是否将下面代码的“版本 1”之类的东西放在堆上?在版本 1 中,Qt 会将 dirStuff 放在堆栈上还是堆上?我问是因为我有一种感觉,Java 将所有数据结构放在堆上......不
这个问题是关于 Qt Installer Framework 2.0 版的。 在这一点上,使用 Qt 安装程序框架的人都知道,如果不进行自定义,您根本无法通过安装程序覆盖现有安装。这样做显然是为了解决
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
因为我在我的计算机上安装了 Qt 4.8.4 和 Qt 5.1,所以我遇到了问题。 当只有 Qt 4.8.4 存在时,一切都很好。 当我添加 Qt 5.1 时,这个工作正常,但 Qt 4.8.4 给了
我无法在我的 Ubuntu 12 中安装更多软件包。我尝试了 apt-get install -f ,以及许多其他类似的技巧,但在找到解决方案方面没有进展。 这是属于 Qt 的损坏包: 以下包具有未满
我正在尝试使用 Virtual Box 中的 Ubuntu 机器复制我们目前在物理 Ubuntu 服务器上运行的应用程序。它是一个 QT 应用程序,但在服务器上我们使用 NPM 的 pm2 运行它。安
问题: Qt Creator 是用 Qt Creator 构建的吗? 同样,Qt Designer 是用 Qt Designer 构建的吗? 顺便说一句,为什么有两个 Qt IDE?他们是竞争对手吗?
当我使用 QWidget设计用户界面时,我总是对它的大小属性有点困惑。有size policy , geometry和 hintSize . 我只知道size policy之间的关系和 hintSiz
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我想知道是否有一种很好的方法可以让用户像 LabView 一样创建节点图(有限制)。 像这样的东西: 我见过http://www.pyqtgraph.org/ ,这似乎有类似的东西,我确实打算使用 P
在 Qt 中是否有一种跨平台的方式来获得用户喜欢的固定宽度和比例字体? 例如,在 cocoa 中,有 NSFont *proportional = [NSFont userFontOfSize:12.
我想使用 Qt 和 C++ 制作这样的交互式图表:http://jsxgraph.uni-bayreuth.de/wiki/index.php/Cubic_spline_interpolation 关
我正在编写一个嵌入式设备屏幕的模拟(其中包含主 QWidget 顶部的自定义小部件),虽然屏幕的原始尺寸是 800x600,但我希望能够按比例放大和缩小它拖动窗口的角。如果不使用网格布局和担架(不会向
在下面的示例中,我是否必须从堆中删除对象?如果是的话,怎么办? #include #include #include #include #include int main(int argc,
来自 Web 开发背景,我现在进入 QT 应用程序开发。 使用 QFonts 我已经看到我显然只有两个选择,在 QT 中定义字体大小;按像素大小或点大小。 在制作网页布局时,我习惯于以相对方式定义所有
我是一名优秀的程序员,十分优秀!