qq_26646737 2015-05-30 06:44 采纳率: 0%
浏览 3025

Python 代码转到Objective-C

请教高手以下代码是什么意思,怎么把它转换成Objective-C,
现在在做一个设备,无法和CL-200A这个光照计通讯,对串口方面的技术不太了解,请教各位。
设备使用以下方式通信
[STX]+"00541"+[ETX]+[BCC (="13")]+[DELIMITER] 
 Half-duplex communication
Parameter Details
Communication method Start/stop synchronization; Half duplex
Baud rate 9600bps (fixed)
Character length 7 bits
Parity Even
Stop bits 1 bit
Delimiter code CR+LF

以下是别人给的Python代码,安装了pyserial,能和设备通信,但是不知道如何使用Objective-C实现,或怎么调用Python的代码
#There are some initialize commands and response, any guys can update the port name for your used.
#Note: this need the python serial support

import serial
import time

portname = ‘/dev/cu.usbserial-A902WJ0N’
port = serial.Serial(port=portname,baudrate=9600,bytesize=7,parity=‘E’,stopbits=1,timeout=2)
print port

#init commands
#some commands is not any response, but I do not skip it, this code is just demo
command=[‘023030534312020200331330d0a’,’02393535312020300330320d0a’,’023030340313020200330360d0a3’,’0239393430323120200330340d0a’,’0239393430323120200330340d0a’]

for str in command:
hexer = str.decode(‘hex’)
port.write(hexer)
response = port.read(15)
time.sleep(0.1)
print response

#read datas from CL200A device
command_readdata = [‘0230303032313230300330320d0a’,’0230303033313230300330330d0a’]

for str in command_readdata:
hexer = str.decode(‘hex’)
port.write(hexer)
response = port.read(40)
time.sleep(0.1)
print response

port.close()

设备通信说明
• Commands from the PC to the CL-200A and command responses from the CL-200A are fixed- length strings (ASCII code).
• Half-duplex communication is used. Because of this, when sending a series of commands, it is necessary to receive the command response (including the delimiter code) from the instrument for each command and wait the specified length of time before sending the next command. However, certain commands do not provide a command response.
• For connecting the CL-200A with a PC, use the exclusive Communication Cable T-A15 (sold separately).

  • 写回答

4条回答 默认 最新

  • devmiao 2015-05-30 06:47
    关注

    应该是usb模拟的串口的双工通讯。具体要结合硬件设备才好编程。

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝