TwinCAT3中的变量回调函数的时间戳读取方式

官网提供了例程,官网真是个宝库。基本ADS的操作都里面有例程了,但是可能会稍微分散一点,不过多看几遍,也就慢慢整理你所需要的东西出来了。

#include <Windows.h>
#include <conio.h>
#include <winbase.h>

#include <TcAdsDef.h>
#include <TcAdsAPI.h>

void myPAdsNotificationFuncEx(AmsAddr*	pAddr,
                              AdsNotificationHeader* pNotification,
                              unsigned long hUser
                              )
{
    SYSTEMTIME              SystemTime, LocalTime;
    FILETIME                FileTime;
    LARGE_INTEGER           LargeInteger;
    TIME_ZONE_INFORMATION   TimeZoneInformation;

    // Convert the timestamp into SYSTEMTIME
    LargeInteger.QuadPart = pNotification->nTimeStamp;
    FileTime.dwLowDateTime = (DWORD)LargeInteger.LowPart;
    FileTime.dwHighDateTime = (DWORD)LargeInteger.HighPart;
    FileTimeToSystemTime(&FileTime, &SystemTime);

    // Convert the time value Zeit to local time
    GetTimeZoneInformation(&TimeZoneInformation);
    SystemTimeToTzSpecificLocalTime(&TimeZoneInformation, &SystemTime, &LocalTime);

    // Print out the timestamp
    qDebug() << LocalTime.wHour << ":"
             << LocalTime.wMinute << ":"
             << LocalTime.wSecond << '.'
             << LocalTime.wMilliseconds;

    //这样子不行,貌似Qt不支持这种timeStamp
    //qDebug() << QDateTime::fromTime_t(pNotification->nTimeStamp);
}

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
三维场景变量通常是由three.js代码控制的,并且不会直接关联到TwinCAT3变量。不过,可以通过使用WebSocket协议在TwinCAT3和three.js之间建立连接,以便将变量值传递给three.js代码。以下是一个简单的示例: 1. 在TwinCAT3,创建一个PLC程序并添加一个变量。假设该变量是一个int类型,名称为“myVariable”。 2. 在TwinCAT3,创建一个WebSocket服务器。可以使用TwinCAT3自带的WebSocket库创建服务器。在服务器上启动后,可以使用任何WebSocket客户端连接到服务器。 3. 在three.js代码,创建一个WebSocket客户端并连接到TwinCAT3的WebSocket服务器。可以使用JavaScript的WebSocket API或任何WebSocket库来实现。 4. 在three.js代码,定义一个变量来存储TwinCAT3变量值。 5. 在three.js代码,使用WebSocket协议从TwinCAT3读取变量值,并将其存储在three.js变量。 6. 在three.js代码,使用three.js对象的属性来设置场景的物体的位置、旋转等属性,从而将变量值应用于场景的物体。 以下是一个简单的示例代码,演示了如何从TwinCAT3读取变量值并将其应用于three.js场景的一个立方体: TwinCAT3程序变量定义: VAR myVariable : INT; END_VAR three.js代码: // 创建WebSocket客户端并连接到TwinCAT3的WebSocket服务器 const ws = new WebSocket('ws://localhost:12345'); // 定义一个变量来存储TwinCAT3变量值 let myVariableValue = 0; // 从TwinCAT3读取变量值,并将其存储在three.js变量 ws.addEventListener('message', (event) => { myVariableValue = parseInt(event.data); }); // 创建场景和立方体 const scene = new THREE.Scene(); const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); // 设置场景的物体的位置,将其应用于TwinCAT3变量值 function animate() { requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; cube.position.y = myVariableValue / 100; renderer.render(scene, camera); } animate();

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值