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

import socket 

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 5002)) # formulate valid Adams View command language that starts with the string "cmd"
cmd = "cmd point create point_name = POINT__1 location = 10 , 15 , 10 relative_to = ground "
client_socket.send(cmd) # receives feedback from the server. The server responds with the string "cmd: 0" for successful command processing
response = client_socket.recv(1024) 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:
import socket
import time cmds = ["cmd variable create variable_name=integer_numbers integer_value=12 range=10,20",
"cmd variable set variable_name=integer_numbers integer_value=16"] # Each command must be sent to the server over a new socket
for cmd in cmds:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
start_time = time.time()
dt = time.time() - start_time
while dt < 60: # wait for a new server connection:
dt = time.time() - start_time
try:
client_socket.connect(("localhost", 5002))
break
except socket.error:
pass print "Connected to socket, sending cmd: %s" % cmd
client_socket.send(cmd)
data = client_socket.recv(1024)
print "Response from cmd was: %s" % data

  • Issuing Queries

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

import socket 

# create a socket & connect to the proper port/host
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 5002)) # queries must always start with the string "query" followed by an Adams View expression
the_query = "query part_2.location"
client_socket.send(the_query) # server replies with a description of the data
query_description = client_socket.recv(1024) # Description of result: query: float : 3 : 12 # server waits for an "OK" command before sending the actual data
client_socket.send("OK")
query_data = client_socket.recv(1024) # accepts the actual server data # parse query data based on type:
description_list = query_description.split(':')
data_type = description_list[1]
data_length = int(description_list[2])
data_bytes = int(description_list[3]) print "Query returned %i values of data type %s" % (data_length, data_type)
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. Pandas删除数据的几种情况

    开始之前,pandas中DataFrame删除对象可能存在几种情况 1.删除具体列 2.删除具体行 3.删除包含某些数值的行或者列 4.删除包含某些字符.文字的行或者列 本文就针对这四种情况探讨一下如 ...

  2. Ubuntu 查找文件的方法

    1. whereis+文件名 用于程序名的搜索,搜索结果只限于二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s),如果省略参数,则返回所有信息. 2. find / -name ...

  3. 短址服务 api

    1  is.gd 他这个api简单: http://is.gd/api.php?longurl= 后面加网址就可以返回短址 2 Google URL Shortener API api地址: http ...

  4. MySQL 查询优化简记

    今天尝试对一张MySQL表做查询优化, 500W数据 但是发现加了索引比不加索引使用全表扫描还慢, 上网查, 据说是因为需要回表, 因为没有用到 using index(覆盖索引), 而回表查询是随机 ...

  5. spring学习之@SessionAttributes

    一.@ModelAttribute 在默认情况下,ModelMap 中的属性作用域是 request 级别是,也就是说,当本次请求结束后,ModelMap 中的属性将销毁.如果希望在多个请求中共享 M ...

  6. vue项目实现列表页-详情页返回不刷新,再点其他菜单项返回刷新的需求

    问题背景:有时候一些列表会有一些跳转的需求,比如跳到详情页.或者是其他相关的页面(比如跳到用户列表去查看用户的相关信息)等,此时再返回列表页,列表页会刷新重置.目前需求就是需要改成如下情况: 问题1. ...

  7. 使用JDBC向Kudu表插入中文数据乱码(转载)

    参考:https://cloud.tencent.com/developer/article/1077763 问题描述 使用Impala JDBC向Kudu表中插入中文字符,插入的中文字符串乱码,中文 ...

  8. Android -- Interpolator

    Interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等. ...

  9. 转:EM算法总结

    https://applenob.github.io/em.html EM算法总结 在概率模型中,最常用的模型参数估计方法应该就是最大似然法. EM算法本质上也是最大似然,它是针对模型中存在隐变量的情 ...

  10. VS2010自带的性能分析工具分析.NET程序的性能

    这篇博文给大家分享的是,如何使用VS自带的性能分析工具来分析我们编写的.NET程序,一边找出程序性能的瓶颈,改善代码的质量.在实际开发中,性能真的很重要,往往决定一个产品的生死~良好的用户体验的基础之 ...