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 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?