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).

查看全部
qq_26646737
qq_26646737
2015/05/30 06:44
  • objective-c
  • 点赞
  • 收藏
  • 回答
    私信

4个回复