I’ve created a Windows c# console app to read the data from the listener and write the data to a MySQL data server (MariaDB) on Raspberry Pi 3 B+ with Raspbian Stretch. The listener is connected to PC with USB.
It works 100% on my PC.
I now want to run the app on the Raspberry Pi with Mono and read the data from Raspberry Pi USB. The app starting to run and open a serial port, but it don’t get data from the opened serial port. It seems that it didn’t recognized the USB port.
What must I do to connect the listener to Raspberry Pi? I didn’t find a solution on Google.
I used screen to connect devices on serial.
You can easly install with
sudo apt-get install screen
screen /dev/ttyS0 115200
you can change /dev/anyDeviceYouWant
I’m not sure how to use screen in my code and try to use “screen /dev/ttyS0” as port name but it give me IO errors.
If I connect the listener to the USB port, the Raspberry pi 3 B+ sees the port as “/dev/ttyACM0”. My code open the port - wait for 3 seconds and write the “lep” command to the port.
Thereafter nothing seems to happen because the port receives no data. Any suggestions?
I’ve now connected the listener directly on the Raspberry Pi 3 B+ header and not with USB anymore.
I’ve enable SPI on RPi configuration
I’ve tried it with serial console disabled and enabled.
I run my C# code with Mono. The software opens the /dev/ttyS0 port.
My problem is that it didn’t open the dwm> cursor when I give it the following code:
mySerialPort.Write("\r");
Thread.Sleep(100);
mySerialPort.Write("\r");
I’ve tried it with different delays from 50milliseconds to 3 seconds and without delays. I try it with combinations of /r, /r/r, /n, /r/n, etc.
In my windows console it work 100% with /r/r, but not on RPi.
Do I miss something? I see on the forum somebody else also ask a similar question, but nobody reply to him and I can’t get any answers in google.
I’ve plugged the listener onto my Rpi 3 headers. With screen /dev/ttyS0 115200 I’m able to receive the coordinates from the tags.(I don’t use the USB anymore)
At least I know my connection between the listener and Rpi is correct and my setup of the serial port on the Rpi is correct.
What C# code must I use to receive the coordinates from the listener? How do I use screen in my C# application?
This is my python code for switching a tag into what I call “logging mode”, over the USB connection. It seems to work pretty much all the time…
# this function has to handle 3 possibilities:
# 1: the beacon is already in logging mode, and is producing POS output lines
# 2: the beacon is in active mode (dwm> prompt), but not logging anything
# 3: the beacon is in normal mode
def put_beacon_in_logging_mode(self, port_name):
start = time.time()
have_signal = False
result = ''
while not have_signal:
result = self.port.read(1000)
have_signal = 'dwm>' in result or 'POS' in result
# we "get signal" by sending pairs of CR over the serial port
if not have_signal:
if round(time.time() - start) >= 5:
print 're-connecting'
self.port.close()
time.sleep(2)
self.connect_to_serial_port(port_name)
time.sleep(1)
start = time.time()
self.port.write(b'\r')
time.sleep(0.1)
self.port.write(b'\r')
print '..'
time.sleep(0.9)
print 'Got signal'
time.sleep(0.5)
# if we've already received a 'POS' in the latest results,
# we're already in logging mode
if 'POS' not in result:
self.port.write(b'lec\r')
time.sleep(2)
triggered = False
while not triggered:
line = self.port.readline()
if len(line) > 0:
line = line.strip()
if line.startswith('DIST'):
triggered = True
print 'Beacon already in logging mode'
if line.endswith('dwm>') and not triggered:
self.port.write(b'lec\r')
triggered = True
print 'Beacon switched to logging mode'