The Adams Command Server is an Adams View (or Adams Car) component that manages communication between Adams View and external software. Examples of external software include user-written applications created in Microsoft Visual Basic, Python, C, Java or similar. The server listens for either commands or queries from an external application and manages the command or query interaction with the Adams model. The server has a simple interface that is accessible from other programming languages that implement the TCP/IP communication protocol. The server also contains an interface for Microsoft Visual Basic that simplifies the communication protocol. 
  多体动力学仿真软件ADAMS可以通过Adams Command Server与外部程序进行TCP通信。首先需要打开ADAMS中的服务端,在Tool→Command Navigator中找到command_server,点击show会弹出一个图形界面的对话框。可以在对话框上点击Start Server开启服务器。如下图所示5002端口已经开启,可以通过TCP socket接收字符串指令:
 
 
  由于控制或查询指令通过TCP以字符串形式发送给command server,因此客户端程序可以采用Python、C++等语言编写,只要指令是合法有效的Adams View Commands(具体语法可以参考官方文档中的Adams View Command Language Help)。外部程序发送的字符串指令主要分为两种,一种是以cmd开头的控制指令,另一种是以query开头的查询指令:
  • Issuing Commands

  1. import socket
  2.  
  3. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4. client_socket.connect(("localhost", 5002))
  5.  
  6. # formulate valid Adams View command language that starts with the string "cmd"
  7. cmd = "cmd point create point_name = POINT__1 location = 10 , 15 , 10 relative_to = ground "
  8. client_socket.send(cmd)
  9.  
  10. # receives feedback from the server. The server responds with the string "cmd: 0" for successful command processing
  11. response = client_socket.recv(1024)
  12.  
  13. print response
    # Returns: cmd: 0 (on success) cmd: 1 (error detected in View command)

  cmd指令在相对于ground的(10, 15, 10)位置处创建了一个点,命名为POINT_1:

  发送指令后收到cmd:0,说明指令执行成功
 
 
  连续发送多条控制指令时必须通过新建的socket,下面代码创建了一个整型设计变量integer_numbers,然后又将其指改为16:
  1. import socket
  2. import time
  3.  
  4. cmds = ["cmd variable create variable_name=integer_numbers integer_value=12 range=10,20",
  5. "cmd variable set variable_name=integer_numbers integer_value=16"]
  6.  
  7. # Each command must be sent to the server over a new socket
  8. for cmd in cmds:
  9. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10. start_time = time.time()
  11. dt = time.time() - start_time
  12. while dt < 60: # wait for a new server connection:
  13. dt = time.time() - start_time
  14. try:
  15. client_socket.connect(("localhost", 5002))
  16. break
  17. except socket.error:
  18. pass
  19.  
  20. print "Connected to socket, sending cmd: %s" % cmd
  21. client_socket.send(cmd)
  22. data = client_socket.recv(1024)
  23. print "Response from cmd was: %s" % data

  • Issuing Queries

  下面代码查询了零件PART_2的位置信息:

  1. import socket
  2.  
  3. # create a socket & connect to the proper port/host
  4. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. client_socket.connect(("localhost", 5002))
  6.  
  7. # queries must always start with the string "query" followed by an Adams View expression
  8. the_query = "query part_2.location"
  9. client_socket.send(the_query)
  10.  
  11. # server replies with a description of the data
  12. query_description = client_socket.recv(1024) # Description of result: query: float : 3 : 12
  13.  
  14. # server waits for an "OK" command before sending the actual data
  15. client_socket.send("OK")
  16. query_data = client_socket.recv(1024) # accepts the actual server data
  17.  
  18. # parse query data based on type:
  19. description_list = query_description.split(':')
  20. data_type = description_list[1]
  21. data_length = int(description_list[2])
  22. data_bytes = int(description_list[3])
  23.  
  24. print "Query returned %i values of data type %s" % (data_length, data_type)
  25. print "Query data as a string is: %s" % query_data

  输出如下:

 
 
 
 
参考:
Adams/2017/help/adams_view/Exchanging Data in Adams / Adams Command Server
Command Language Help

ADAMS与外部程序通信(Adams Command Server)的更多相关文章

  1. Hadoop源码解析之 rpc通信 client到server通信

    rpc是Hadoop分布式底层通信的基础,无论是client和namenode,namenode和datanode,以及yarn新框架之间的通信模式等等都是采用的rpc方式. 下面我们来概要分析一下H ...

  2. JAVA ANDROID SOCKET通信检测(SERVER)连接是否断开

    Pre 解决思路 代码后记: 客户端app上的部分代码 调用: 服务器上: 客户端判断服务器是否还活着代码: PRE 在利用socket写通讯程序的时候,想检测服务器是否还活着. 从网上找了很多资料, ...

  3. C# 管道通信 (client —— server)Framework2.0版本也可用

    //管道服务类public class PipServer { [DllImport("kernel32.dll", SetLastError = true)] public st ...

  4. iSight集成Adams/View:Adams组件

    iSight本身支持特定版本的Adams/View,在Adams中添加isight的插件方法如下: 1.在iSight安装目录下搜索isight.bin文件,将其复制到Adams安装路径下的win32 ...

  5. adams/car 怎么进入template builder模块

    打开C:\Documents and Settings\Administrator文件夹下的acar.cfg文件,将 Desired user mode (standard/expert)ENVIRO ...

  6. TCP/UDP通信中server和client是如何知道对方IP地址的

    在TCP通信中 client是主动连接的一方,client对server的IP的地址提前已知的.如果是未知则是没办法通信的. server是在accpet返回的时候知道的,因为数据包中包含客户端的IP ...

  7. 用PHP的socket实现客户端到服务端的通信

    服务端 <?php error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); //本地IP $address = 'loca ...

  8. Socket编程之聊天程序 - 模拟Fins/ModBus协议通信过程

    设备控制软件编程涉及到的基本通信方式主要有TCP/IP与串口,用到的数据通信协议有Fins与ModBus. 更高级别的通信如.net中的Remoting与WCF在进行C/S架构软件开发时会采用. 本篇 ...

  9. Erlang下与其他程序和语言的通信机制(1)

    在Erlang运行时中,提供了几种机制来实现与其它程序或者语言的通信.一种为分布式Erlang,一种为端口,其中端口分为普通端口和链入式驱动端口,还有后面引入的NIFs. 分布式Erlang:一个Er ...

随机推荐

  1. Hype cycle(Gartner 成熟度曲线)

        Hype cycle The hype cycle is a branded graphical presentation developed and used by the American ...

  2. HipHop PHP & HHVM资料收集

    百度百科 HipHop PHP实战(详解web运行模式) 百度 PHP7和HHVM的性能之争

  3. 【转】各种 NoSQL 的比较

    转自 : http://linux.cn/article-2177-1.html 来源:Linux中国  原文:http://linux.cn/article-2177-1.html     即使关系 ...

  4. 【BZOJ】【3930】【CQOI2015】选数

    数论/莫比乌斯反演/快速mu前缀和 比较容易想到令f[x]表示gcd=x的方案数,令g[x]表示x|gcd的方案数. 那么有$ g(d)=\sum_{d|n} f(n)$,根据莫比乌斯反演,有$f(d ...

  5. XML和JSON优缺点

    <1>.XML的优点 A.格式统一,符合标准: B.容易与其他系统进行远程交互,数据共享比较方便.<2>.XML的缺点 A.XML文件庞大,文件格式复杂,传输占带宽: B.服务 ...

  6. 奇怪吸引子---Coullet

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  7. Ios之网络编程NSURLConnection

    通过NSURLConnection主要通过四个类进行网络访问:NSURL,NSURLRequest,NSMutableURLRequest,NSURLConnection 一.基本知识 (1)NSUR ...

  8. diy作品——视觉追踪小车介绍

    最近刚刚完毕了一个追踪功能的小车.大体功能例如以下:小车能通过网线给电脑传图(抱歉.临时没搞wifi驱动).并在电脑端通过鼠标选中待跟踪的目标,然后小车就開始追踪.由于追踪框有缩放功能.所以也能推断物 ...

  9. 如何实现Linux+Windows双系统启动

    设置你的计算机根据需要启动 Windows 10 或 Ubuntu 18.04. 尽管 Linux 是一个有着广泛的硬件和软件支持的操作系统,但事实上有时你仍需要使用 Windows,也许是因为有些不 ...

  10. JS 判断浏览器是否安装Flash 兼容IE、firefox

    /** * @Author: HTL * @Email: Huangyuan413026@163.com * @DateTime: 2016-06-02 11:37:05 * @Description ...