5
nitwhiz
6y

Is there any good linux application to send FUCKING RAW data to a serial port?

Port in question: /dev/ttyACM0
Baud (nice if configurable): 9600

I want to send specific binary data. I want to send 0b00110011 or something like that to it, not some character or a hex value.

Comments
  • 2
    @11000100111000 stty, minicom, screen are shit, tried all of them. I don't want to send data out of a file or something. I need to be able to enter data, press enter and get it transferred.
  • 1
    @11000100111000 yeah but my stdin doesn't interpret "101" as a 5, a number, it interprets it as "101", an ascii string.
  • 1
    Write your own in assembler...
  • 4
    1.Convert it to ascii.
    2.Send ascii
    3.Profit???
  • 2
    moserial is the one I use for hex input/output.
  • 1
    @Gregozor2121 please provide me the ascii symbols for 0xaa, 0x82, 0x10, 0xcd, 0x7a, 0xfa quickly so i can send it easily to my device.

    I got me an hex editor with binary capabilities, wrote a file and sent it. What a huge overhead for something so fucken simple.
  • 1
    Why not hexadecimal? It's easy to convert from base 2 to base 16. Or do you need values other than 8 bit length?

    For the serial part, install PySerial and write a short script.

    Here's an example (without any conversion from base 2, you can copy that from Stackoverflow ;-)):

    import serial

    TestString = b'ABC123'

    port = serial.Serial( 'ttyACM0', 9600 )

    port.timeout = 0.5

    port.write( TestString )

    port.flush()

    response = port.read( 10 )

    port.close()
  • 1
    @ddephor yeah of course i could write a program for that. But i don't want to write 3 programs in parallel.
  • 1
    @11000100111000 now where do i define my baud there?
  • 1
    nice gordon ramsey reference
  • 1
    @nitwhiz It's easy to complain about tools that are, in your words, “shitty” just because they don't convert what you type in your keyboard, whatever format it may be, to the correct value automagically.

    Those tools do what they're supposed to do: read data from stdin, send it to the serial port. What you need is something that reads whatever input you want to type in the format you want to type it and output the binary data to stdout, which then you can pipe to one of those tools.

    Let me add another tool not mentioned here before: socat. Here you go:

    while read -r i; do i="\\x$(printf '%2x' "$(( 2#$i ))")"; echo -ne "$i"; echo >&2; done | socat -u STDIN /dev/ttyACM0,b9600,rawer,crnl

    I haven't tested the socat part, but that Bash loop lets you enter bytes as binary digits and outputs them back as ASCII characters when you press Enter. You can consult socat's manpage for more information about what options to use in your particular case.
  • 1
    @nitwhiz Using base 2 directly is not a common use case. You will hardly find a popular tool that will do the conversion and all other stuff you need combined in one.

    Base 16/hexadecimal is much more common, and easy to convert, you're better off using hex IMO.

    Or just write the tool for yourself. I often rather write a small script to deal with some simple task, than search for hours for an existing solution, that usually doesn't do exactly what I need. These scripts are often one-shots, they look ugly and are not maintainable, but they do what I need. And as another benefit, it's a good developer training.
  • 1
    Quick python script maybe? That’s what I have used in the past
  • 0
    @ethernetzero @ddephor for me, it was completely normal that these tools should have such a function. Most mcu's let you transfer/receive less than a byte via serial, say 5 bit or so. So i thought someone else might have thought "geez to test my routine i need to calculate the hex number for this binary combination myself?"

    So I'm sorry i took "lat. computare" by it's meaning.
  • 0
    @nitwhiz I'd have written a bash function that does this for me
  • 0
    @nitwhiz xxd -r and printf "\x<hex value> are your friend
  • 1
    Usually, a serial ports treat data bytewise. Mostly 8 bits, no parity, 1 stop bit (8N1). This means that the port does NOT send the data as continuous bit stream, and that's why it's not useful to enter data in binary.

    Put 8 bits into a byte and then send it bytewise, that should work. You just need a little program that will convert '0' and '1' to bits, shift that into a variable, and transmit to the port once 8 bits are full. This is such an exotic use case that of course nobody has written a program to do that.
  • 1
    @Fast-Nop if i configure my mcu to actually use 5 bit i'd like to specify 5 bits because i'm able to ffs.
  • 1
    @nitwhiz the question is whether your mobo port also supports this. Even if it does, it's unlikely that the mobo manufacturer has tested this at all.
  • 1
    Try hterm, we use it all the time during development.
    Windows version works nice, Linux version needs some extra dependencies tho.
    The developer website seems dubious, but I assure you we've never had any problems with it.
  • 1
    dd? If you could mount the port's input as a file or mount point you could use dd.
  • 1
    @nitwhiz Many UARTs are configurable from 5-9 data bits, but today you will usually find 8 data bits. Some protocols still use 7 data bits. All other configurations are kept for backwards compatibility, because there were protocols using 5 or 6 data bits, and the UARTs mostly based on the classic 8250/16550 design already support them since forever. But 5/6 data bits are really rare today.
  • 0
    @ddephor I'm using 8 bit myself, but the possibility of < 8 bit let me think there must be an option to enter binary data in these tools.
Add Comment