2 qq 26646737 qq_26646737 于 2015.05.30 14:44 提问

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
devmiao   Ds   Rxr 2015.05.30 14:47

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

qq_26646737
qq_26646737 谢谢~
2 年多之前 回复
qq_26646737
qq_26646737   2015.05.30 15:09

我们搞了一个多礼拜,还是搞不定,老大说是半双工,半双工 Half-duplex communication怎么配置?

qq_26646737
qq_26646737   2015.05.30 15:10

别人用Python很容易就实现了,但是没有给我们深入的讲解原理。

oyljerry
oyljerry   Ds   Rxr 2015.05.30 23:00

基本就是串口开发,你需要知道oc的串口开发API,然后就是配置参数。

qq_26646737
qq_26646737 谢谢~
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片