Skip to content

Commit 5fd3c21

Browse files
authored
Update README.md
1 parent d67c70c commit 5fd3c21

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,33 @@ class WbServerClient(builtins.object)
110110
```
111111
## 核心类实现
112112

113-
<img src="https://github.com/ansys-dev/PyWbUnit/blob/0.3.0/WbServerClient.png" alt="WbServerClient" style="zoom:40%;" />
113+
```python
114+
# -*- coding: utf-8 -*-
115+
from socket import *
116+
117+
class WbServerClient:
118+
119+
_suffix = '<EOF>'
120+
_coding = 'US-ASCII'
121+
_buffer = 1024
122+
123+
def __init__(self, aasKey: str):
124+
aasList = aasKey.split(':')
125+
self._address = (aasList[0], int(aasList[1]))
126+
127+
def execWbCommand(self, command: str) -> str:
128+
sockCommand = command + self._suffix
129+
with socket(AF_INET, SOCK_STREAM) as sock:
130+
sock.connect(self._address)
131+
sock.sendall(sockCommand.encode(self._coding))
132+
data = sock.recv(self._buffer).decode()
133+
return data
134+
135+
def queryWbVariable(self, variable) -> str:
136+
self.execWbCommand("__variable__=" + variable + ".__repr__()")
137+
retValue = self.execWbCommand("Query,__variable__")
138+
return retValue[13:]
139+
```
114140

115141
## 使用方法
116142
首先从PyWbUnit模块中导入CoWbUnitProcess类,详细文档说明可以通过help(CoWbUnitProcess)查看,以公众号文章:《[ANSYS中使用Python实现高效结构仿真](https://mp.weixin.qq.com/s?__biz=Mzg5MDMwNDIwMQ==&mid=2247484455&idx=1&sn=aac9501bb6fec23276353e4a27c10af9&chksm=cfdfe781f8a86e97bc5afb34678036318ce09d442d82cbeab195c8bdbaeb9e3e00606951469c&token=1162439082&lang=zh_CN#rd)》为例,演示如何使用PyWbUnit调用Workbench完成联合仿真的过程:

0 commit comments

Comments
 (0)