【问题标题】:getting started with Thorlabs APTThorlabs APT 入门
【发布时间】:2013-11-26 13:52:58
【问题描述】:

我希望其他人有编程 APT - DC 伺服控制器的经验。 我的客户想要一个自定义解决方案,因此使用 ActiveX 控件是不可行的。

我认为,一旦我弄清楚如何发送基本消息,我将能够很好地遵循 API,但我在入门时遇到了困难......而且文档似乎没有明确说明如何实际向控制器发送消息。

IE,我是否应该使用 FTDI 接口,使用 FT_Write/FT_Read 命令来操作设备?

我运行了以下代码,该代码贯穿了初始设置,但在我尝试使 LED 闪烁的最后一行失败。

//the following is per the user manual for thor device.    
ftHandle = FT_W32_CreateFile(SerialNumber.c_str(),
    GENERIC_READ|GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |  FT_OPEN_BY_SERIAL_NUMBER,
    0); // Open device by serial number
assert (ftHandle != INVALID_HANDLE_VALUE);
// Set baud rate to 115200.
const int uBaudRate=115200;
auto ftStatus =  FT_SetBaudRate(ftHandle, (ULONG)uBaudRate);
assert(ftStatus==FT_OK);

// 8 data bits, 1 stop bit, no parity
ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
assert(ftStatus==FT_OK);
// Pre purge dwell 50ms.
Sleep(50);
// Purge the device.
ftStatus = FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX);
assert(ftStatus==FT_OK);
// Post purge dwell 50ms.
Sleep(50); 
ftStatus = FT_ResetDevice(ftHandle);
assert(ftStatus==FT_OK);
// Set flow control to RTS/CTS.
ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_RTS_CTS, 0, 0);
// Set RTS.
ftStatus = FT_SetRts(ftHandle);
assert(ftStatus==FT_OK);

//lets flash the led, MGMSG_MOD_IDENTIFY
BYTE buf[6] ={0x23,0x2,0,0,0x21,0x1};
DWORD written=0;
/*******************/
ftStatus = FT_Write(ftHandle, buf, (DWORD)6, &written);//4= FT_IO_ERROR
assert(ftStatus==FT_OK);  //this is where I'm failing
/*******************/

作为参考,我正在编写一个 32 位应用程序 - 在 64 位笔记本电脑上工作。

【问题讨论】:

  • 咨询了技术人员,修改命令为:BYTE buf[6] ={0x23,0x02,0x00,0x00,0x50,0x01};但是,结果仍然失败。

标签: c++ api ftdi


【解决方案1】:

已通过使用 FT_OpenEx 而不是 FT_W32_CreateFile 修复。

【讨论】:

  • 我第一次尝试在不使用activeX的情况下使用VisualC++控制直流伺服控制器。我应该导入哪个库以及标题名称是什么?您的经验中的任何建议都会非常有帮助
猜你喜欢
  • 2015-09-17
  • 2020-07-04
  • 2020-03-17
  • 2021-02-14
  • 2012-11-15
  • 2010-09-21
  • 1970-01-01
  • 2017-05-15
  • 1970-01-01
相关资源
最近更新 更多