Initial commit
This commit is contained in:
commit
b86fe6f3fc
9
IPTCMessage.py
Normal file
9
IPTCMessage.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class IPTCMessage(object):
|
||||
def __init__(self):
|
||||
print("Hello world!")
|
||||
|
||||
if __name__=='__main__':
|
||||
print("Testmode!")
|
28
README.md
Normal file
28
README.md
Normal file
@ -0,0 +1,28 @@
|
||||
tty2NewsML
|
||||
==========
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
* Python 3
|
||||
* PySerial
|
||||
* `yum install python-setuptools`
|
||||
* `easy_install pyserial`
|
||||
* or `pip install pyserial`
|
||||
|
||||
|
||||
Communication parameters:
|
||||
* 4800 baud
|
||||
* 8 data bits
|
||||
* no parity
|
||||
* 1 stop bit
|
||||
|
||||
Format: [IPTC 7901](http://www.iptc.org/site/News_Exchange_Formats/IPTC_7901/Specification/)
|
||||
|
||||
Priorities
|
||||
----------
|
||||
|
||||
* 5 - Normal
|
||||
* 4 - Dringend
|
||||
* 3 - Vorrang
|
||||
* 2 - Blitz/Eil
|
3
setbaud.sh
Executable file
3
setbaud.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
# 4800 kbps 8N1
|
||||
stty -F /dev/tty701 4800 cs8 -parenb -cstopb
|
51
tty2newsml.py
Executable file
51
tty2newsml.py
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import serial
|
||||
import IPTCMessage
|
||||
|
||||
class _main(object):
|
||||
def __init__(self, port='/dev/tty706'):
|
||||
self.openPort(port)
|
||||
while True:
|
||||
msg = self.waitForStart()
|
||||
msg += self.readUntilEOM()
|
||||
print("This is the message: %s" % repr(msg))
|
||||
|
||||
def openPort(self, port):
|
||||
self.port = serial.Serial(port, baudrate=4800, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None)
|
||||
print("%s opened with %i baud. Timeout is %s seconds." % (self.port.name, self.port.baudrate, self.port.timeout))
|
||||
|
||||
def waitForStart(self):
|
||||
print("Waiting for start indicator: ", end='', flush=True)
|
||||
while True:
|
||||
byte = self.port.read()
|
||||
print(".", end='', flush=True)
|
||||
if byte == b'\x01':
|
||||
print("Found.")
|
||||
return byte
|
||||
|
||||
def readUntilEOM(self):
|
||||
print("Reading data until EOM.", end='', flush=True)
|
||||
msg = b''
|
||||
ctr = 0
|
||||
while True:
|
||||
byte = self.port.read()
|
||||
ctr+=1
|
||||
if ctr % 10 is 0:
|
||||
print(".", end='', flush=True)
|
||||
if byte == b'\x01':
|
||||
print("PROBLEM: Got start indicator, but message not yet finished.")
|
||||
break
|
||||
msg += byte
|
||||
if byte == b'\x04':
|
||||
break
|
||||
print("Got %i bytes." % len(msg))
|
||||
return msg
|
||||
|
||||
def readLine(self):
|
||||
rcv = self.port.readline()
|
||||
print("Got: %s" % repr(rcv))
|
||||
|
||||
if __name__=='__main__':
|
||||
_main()
|
Reference in New Issue
Block a user