function WriteRaw(obj,message) if obj.RecordCommands fid = fopen('CommandLog.log','a'); fprintf(fid,'%s | %s | WRITE | %s',datetime('now','Format','yyyy-MM-dd HH:mm:ss.SSS'),pad(obj.DeviceName,10),message); fclose(fid); end % just writes the message straight to the session write(obj.Session,message); end
时间: 2024-02-14 08:35:57 浏览: 65
这是一个 MATLAB 中的函数,它用于向仪器发送原始的命令字符串。在这个函数中,输入参数 `obj` 是一个对象,`message` 是要发送的命令字符串。函数的实现是将命令字符串直接写入到仪器的会话中,以发送该命令。需要注意的是,函数还包含其他的功能,如记录命令日志等。
具体来说,函数的第一部分是一个条件语句,判断当前是否需要记录命令日志。如果 `obj.RecordCommands` 等于 true,则表示需要记录日志,函数会将命令字符串写入到文件 `"CommandLog.log"` 中。文件名和路径可以根据实际需要进行修改。文件写入完成后,函数会关闭文件。
第二部分是发送命令字符串。函数调用了 `write` 函数,将命令字符串写入仪器的会话中,以发送该命令。需要注意的是,这里的 `write` 函数是仪器连接接口提供的函数,不同的接口可能实现不同,具体实现可以根据实际情况进行查看。
相关问题
function res = ReadRaw(obj) %读取Session返回的数据 % start by reading one byte res = read(obj.Session,1); % read all the other bytes from the queue res = [res read(obj.Session)]; % if we are logging, write the response query to the log if obj.RecordCommands fid = fopen('CommandLog.log','a'); fprintf(fid,'%s | %s | READ | %s',datetime('now','Format','yyyy-MM-dd HH:mm:ss.SSS'),pad(obj.DeviceName,10),res); fclose(fid); end end
ReadRaw 方法的作用是从设备中读取数据,其实现过程如下:
1. 首先,使用 read 函数从设备中读取一个字节,并将其存储在变量 res 中。
2. 然后,使用 read 函数读取设备中剩余的所有字节,并将其与之前读取的字节合并成一个向量,存储在变量 res 中。
3. 如果对象 obj 的 RecordCommands 属性为真,则将读取到的响应记录到日志文件 CommandLog.log 中。
4. 最后,将读取到的响应返回给调用方。
需要注意的是,ReadRaw 方法是一个底层读取函数,它只是从设备中读取数据,并没有对其进行任何解析或处理。如果需要解析设备返回的数据,需要在调用 ReadRaw 方法之后对其进行相应的解析处理。
阅读全文
相关推荐










