USB 직렬 변환기를 사용하여 직렬 인터페이스와 통신하는 코드를 작성하려고합니다. 우분투 12.04 OS에서 코드를 실행하고 있습니다. 나는 장치를 부착하고이를 시스템에 의해 인식되는 것처럼 lsusb의 출력이 저를주기 때문에 그것은 같습니다파이썬 : 직렬 변환기에 USB 직렬 통신 실패
Bus 002 Device 003: ID 9710:7840 MosChip Semiconductor MCS7820/MCS7840 2/4 port serial adapter
과 dmesg를 명령 보고서 : 그러나
Tue Apr 18 15:22:07 2017] usb 2-2: new high-speed USB device number 3 using ehci_hcd
[Tue Apr 18 15:22:07 2017] usbcore: registered new interface driver usbserial
[Tue Apr 18 15:22:07 2017] USB Serial support registered for generic
[Tue Apr 18 15:22:07 2017] usbcore: registered new interface driver usbserial_generic
[Tue Apr 18 15:22:07 2017] usbserial: USB Serial Driver core
[Tue Apr 18 15:22:07 2017] USB Serial support registered for Moschip 7840/7820 USB Serial Driver*
[Tue Apr 18 15:22:07 2017] mos7840: 1.3.2:Moschip 7840/7820 USB Serial Driver
[Tue Apr 18 15:22:07 2017] mos7840 2-2:1.0: Moschip 7840/7820 USB Serial Driver converter detected
[Tue Apr 18 15:22:07 2017] usb 2-2: Moschip 7840/7820 USB Serial Driver converter now attached to ttyUSB0
[Tue Apr 18 15:22:07 2017] usb 2-2: Moschip 7840/7820 USB Serial Driver converter now attached to ttyUSB1
[Tue Apr 18 15:22:07 2017] usb 2-2: Moschip 7840/7820 USB Serial Driver converter now attached to ttyUSB2
[Tue Apr 18 15:22:07 2017] usb 2-2: Moschip 7840/7820 USB Serial Driver converter now attached to ttyUSB3
[Tue Apr 18 15:22:07 2017] usbcore: registered new interface driver mos7840
I 내 코드를 실행하려고하면 상대방으로부터 예상되는 응답을 얻지 못합니다. 내가 실행 해요 코드는 여기에 있습니다 :
class RTSSerial(object):
def __init__(self,serialID, baud):
self.serialID = serialID
self.baud = baud
try:
self.serDevice = serial.Serial(self.serialID,
baudrate = self.baud,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS)
self.serDevice.flushInput()
self.serDevice.flushOutput()
except Exception as e:
print 'Got the following exception: ', e
def read(self):
try:
inWaiting = self.serDevice.inWaiting()
except:
if os.path.exists(self.serialID):
self.serDevice = serial.Serial(self.serialID,self.baud)
inWaiting = 0
try:
rec = ''
if (inWaiting > 0):
rec = self.serDevice.read(inWaiting)
#Convert string message into list of integers
message = [ord(x) for x in rec]
except Exception as e:
message = []
print 'Got the following exception: ', e
return message
#Function to write to serial
#message should be a list. Then the function converts it into a string
def write(self, message):
try:
#Convert message into string
messageToSend = "".join(chr(x) for x in message)
errCode = self.serDevice.write(messageToSend)
except Exception as e:
errCode = 0
print 'Got the following exception: ', e
return errCode
ser = RTSSerial('/dev/ttyUSB0', 9600)
mess = [0x7e, 0xa, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x4d, 0x8a]
ser.write(mess)
time.sleep(1)
reply = ser.read()
내가 좋아하는 응답 기대 :
0x7E 0x04 0x00 CRC1 CRC2
을 대신 내가 얻을 : 여기 내려다하고 뭔가
0x7e 0xd 0xa 0x43 0x20 0x69 0x6e 0x74 0x65 0x72 0x70 0x3a 0x20 0x73 0x79 0x6e 0x74 0x61 0x78 0x20 0x65 0x72 0x72 0x6f 0x72 0x2e 0xd 0xa 0x2d 0x3e 0x20 0x3f 0x4d 0xd 0xa 0x43 0x20 0x69 0x6e 0x74 0x65 0x72 0x70 0x3a 0x20 0x74 0x6f 0x6b 0x65 0x6e 0x20 0x27 0x10 0x27 0x20 0x6e 0x6f 0x74 0x20 0x72 0x65 0x63 0x6f 0x67 0x6e 0x69 0x7a 0x65 0x64 0x2e 0xd 0xa 0x2d 0x3e 0x20
있습니까? 미리 감사드립니다! 대신 진수의 ASCII에서 그 결과를 볼 경우
직렬 포트를 디버그 할 무언가가 있습니까? 프로토콜 분석기처럼? 어쩌면 범위일까요? – DSLima90
불행히도 ... 지금 두 개의 컨버터 출력을 연결하여 한쪽면에 쓰고 다른 쪽면에 읽을 수 있는지 알아 보겠습니다. – toti08
좋아, 이것을 시도하고 그것은 효과가 ... 그래서 그것은 다른 컴퓨터에 뭔가 문제가있는 것 같아요 ... – toti08