mglass
Posts: 6
Joined: Wed Jan 11, 2017 9:05 am

Serial Communications over USB with ArchLinuxARM

Wed Jan 11, 2017 9:11 am

Can anyone help me get started with Serial Communications over USB with ArchLinuxARM?

I have serial output streaming from a USB device at 9600 baud. How can I read this data into the Pi?

How do I setup the USB serial link and then how to I grab the serial data from the USB serial port?

User avatar
topguy
Posts: 6466
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Serial Communications over USB with ArchLinuxARM

Wed Jan 11, 2017 12:31 pm

Are you going to plug the USB device into the Raspberry Pi ?
If yes then you have to check if the device is recognized by the kernel as a USB2Serial converter and will give you a "/dev/ttyUSB0" device. ( alternativly "/dev/ttyACM0")

mglass
Posts: 6
Joined: Wed Jan 11, 2017 9:05 am

Re: Serial Communications over USB with ArchLinuxARM

Thu Jan 12, 2017 1:43 am

Yes - that's right. I'll plug the USB cable into the Pi, and presumably a USB port device will appear in /dev (eg /dev/ttyUSB0) as you say.

But how do I set the baud rate (eg 9600)?

Then, how do I open a file and store the data stream coming off the USB port?

Any help or clues ?

mglass
Posts: 6
Joined: Wed Jan 11, 2017 9:05 am

Re: Serial Communications over USB with ArchLinuxARM

Thu Jan 12, 2017 1:45 am

BTW I'm seeking bash/sh command lines, as I'm using ArchLinuxARM, as the operating system.

User avatar
topguy
Posts: 6466
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Serial Communications over USB with ArchLinuxARM

Thu Jan 12, 2017 12:21 pm

Set baudrate: ( but 9600 is already default baudrate in linux )

Code: Select all

stty -F /dev/ttyUSB0 9600
Dump serialport parameters:

Code: Select all

stty -a -F /dev/ttyUSB0
Test output if its text ( like a GPS )

Code: Select all

cat /dev/ttyUSB0
Test output if its binary:

Code: Select all

dd if=/dev/ttyUSB of=test.bin count=1024
od -t x1 test.bin

mglass
Posts: 6
Joined: Wed Jan 11, 2017 9:05 am

Re: Serial Communications over USB with ArchLinuxARM

Thu Jan 12, 2017 2:13 pm

Many thanks. That's just what I need.

I'll have a go and I expect I'll be able to take it from there.

Cheers,
Martin

Return to “Arch”