mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-06 15:05:13 +00:00
更新NMR驱动
This commit is contained in:
61
unilabos/devices/NMR/NMR.py
Normal file
61
unilabos/devices/NMR/NMR.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
import pandas as pd
|
||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
# define class ATR30007
|
||||||
|
# this class is used to control the ATR30007 Raman workstation
|
||||||
|
|
||||||
|
class NMR_400:
|
||||||
|
def __init__(self):
|
||||||
|
self.machine = None
|
||||||
|
|
||||||
|
def start_NMR(self, user: str = "admin", holder: int = 1,
|
||||||
|
name: str = "Samplename1", expno: int = 1,
|
||||||
|
solvent: str = "D2O", experiment: str = "PROTON16",
|
||||||
|
title: str = "test_1H", save_root: str = None,):
|
||||||
|
#打开仪器
|
||||||
|
content = f"""USER {user}
|
||||||
|
HOLDER {holder}
|
||||||
|
NAME {name}
|
||||||
|
EXPNO {expno}
|
||||||
|
SOLVENT {solvent}
|
||||||
|
EXPERIMENT {experiment}
|
||||||
|
TITLE {title}
|
||||||
|
END
|
||||||
|
"""
|
||||||
|
# 生成文件名(当前日期)
|
||||||
|
filename = datetime.now().strftime("%Y%m%d%H%M") + ".txt"
|
||||||
|
|
||||||
|
# 创建输出目录(如果不存在)
|
||||||
|
os.makedirs(save_root, exist_ok=True)
|
||||||
|
|
||||||
|
# 写入文件
|
||||||
|
filepath = os.path.join(save_root, filename)
|
||||||
|
with open(filepath, "w") as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
print(f'文件{filename}保存到{save_root}')
|
||||||
|
|
||||||
|
def NMR_cmd(self, command: str):
|
||||||
|
print(f"接收到命令: {command}")
|
||||||
|
# replace !=! to "
|
||||||
|
command = command.replace("!=!", "\"")
|
||||||
|
command = command.replace('\\', '\\\\')
|
||||||
|
command = command.replace("True", "true").replace("False", "false")
|
||||||
|
try:
|
||||||
|
cmd_dict = json.loads(command)
|
||||||
|
print(f"命令参数: {cmd_dict}")
|
||||||
|
# 解析命令参数
|
||||||
|
save_root = cmd_dict.get("save_root", r"D:\UniLab\results\250414")
|
||||||
|
# FIXME: use EIS for test. Add parameter for other tests
|
||||||
|
|
||||||
|
self.start_NMR(**cmd_dict) # , file_name=file_name, save_root=save_root
|
||||||
|
print(f"实验完成,数据已保存到 {save_root}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"命令执行失败: {e}")
|
||||||
|
raise f"error: {e}"
|
||||||
|
|
||||||
49
unilabos/devices/NMR/NMR_test.py
Normal file
49
unilabos/devices/NMR/NMR_test.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def generate_experiment_file( # 必填参数:输出路径
|
||||||
|
user: str = "admin", # 默认值参数
|
||||||
|
holder: int = 1, # 默认值参数
|
||||||
|
name: str = "Samplename1", # 默认值参数
|
||||||
|
expno: int = 1, # 默认值参数
|
||||||
|
solvent: str = "D2O", # 默认值参数
|
||||||
|
experiment: str = "PROTON16", # 默认值参数
|
||||||
|
title: str = "test_1H",
|
||||||
|
save_root: str = None, # 默认动态生成
|
||||||
|
):
|
||||||
|
|
||||||
|
# 生成文件内容
|
||||||
|
content = f"""USER {user}
|
||||||
|
HOLDER {holder}
|
||||||
|
NAME {name}
|
||||||
|
EXPNO {expno}
|
||||||
|
SOLVENT {solvent}
|
||||||
|
EXPERIMENT {experiment}
|
||||||
|
TITLE {title}
|
||||||
|
END
|
||||||
|
"""
|
||||||
|
# 生成文件名(当前日期)
|
||||||
|
filename = datetime.now().strftime("%Y%m%d%H%M") + ".txt"
|
||||||
|
|
||||||
|
# 创建输出目录(如果不存在)
|
||||||
|
os.makedirs(save_root, exist_ok=True)
|
||||||
|
|
||||||
|
# 写入文件
|
||||||
|
filepath = os.path.join(save_root, filename)
|
||||||
|
with open(filepath, "w") as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
return filepath
|
||||||
|
|
||||||
|
# 使用示例
|
||||||
|
|
||||||
|
generate_experiment_file(
|
||||||
|
user="chem_user",
|
||||||
|
holder=1,
|
||||||
|
name="MySample",
|
||||||
|
expno=2,
|
||||||
|
solvent="CDCl3",
|
||||||
|
experiment = "PROTON16",
|
||||||
|
save_root=r"D:\Uni-lab\NMR",
|
||||||
|
)
|
||||||
|
|
||||||
0
unilabos/devices/NMR/__init__.py
Normal file
0
unilabos/devices/NMR/__init__.py
Normal file
Reference in New Issue
Block a user