Re: Sending HEX Values via Ethernet from BeagleBone Black

108 views
Skip to first unread message
Message has been deleted

Dennis Lee Bieber

unread,
Mar 17, 2020, 7:44:17 PM3/17/20
to Beagleboard
On Tue, 17 Mar 2020 15:16:57 -0700 (PDT), in
gmane.comp.hardware.beagleboard.user Alex Rodriguez
<powertoutg-Re5JQ...@public.gmane.org> wrote:

>Hey guys,
>
>I would like to have my BeagleBone Black output certain hex values over
>Ethernet (either UDP or TCP) to another offline system. Is there a simple
>way to go about doing this? If so, are there any specific examples of this?
>Thanks!

First: Define what you mean by "hex values"...
Second: Study any textbook on network I/O (covering TCP/UDP) over
sockets. Related: What language do you intend to use?

Hexadecimal is a /display/ (text) encoding for binary data. If you
really mean "hex", then you just need to convert the binary data to a
string, and send the string.

>>> hxstr = "%8.8X" % 123987456
>>> hxstr
'0763E600'
>>> print(hxstr)
0763E600
>>>

{gets uglier for floating point -- one needs to use struct module to pack
the float into a bytestring, then unpack the bytestring as an integer}

If you mean arbitrary binary values, you need to pack them into a byte
array and send the byte array -- though this does introduce the next
factor...

... TCP is a stream protocol -- it ensures that you will receive the sent
data, but does not guarantee that you will receive the same number of
packets as sent. It can split packets into multiple receive calls, or join
multiple send packets into a single packet. It is up to YOU to define the
high-level protocol that allows you to know if you have received all of a
transmission (for example -- you send a count of how many bytes are to
follow... Many of the text protocols use a line that contains just a ".").

... UDP, on the other hand, does not split/combine packets -- what you
receive IS what was sent. However, it does not guarantee delivery! Any
individual packet can be lost/undelivered. It is up to YOU to define a
protocol that lets you detect lost packets (unless your application can
live with missed packets).


--
Dennis L Bieber

Message has been deleted

Robert Nelson

unread,
Mar 18, 2020, 3:24:24 PM3/18/20
to Beagle Board, Powertourg .
On Wed, Mar 18, 2020 at 2:20 PM Alex Rodriguez <power...@gmail.com> wrote:
>
> Hi,
>
> I intend to use C for this, unless there is an easier way to do it. For my application, UDP will work just fine as I'm not too concerned about packet loss. And yes, I understand that HEX is a representation of binary data. I simply wanted to know if this could be done from the BBB and if so, see if there is a similar solution out there for new users. Thanks

a quick google search found...

https://wiki.python.org/moin/TcpCommunication

Regards,

--
Robert Nelson
https://rcn-ee.com/

Dennis Lee Bieber

unread,
Mar 18, 2020, 9:25:26 PM3/18/20
to Beagleboard
On Wed, 18 Mar 2020 14:23:42 -0500, in gmane.comp.hardware.beagleboard.user
Robert Nelson <robertcnelson-Re5J...@public.gmane.org>
wrote:

>On Wed, Mar 18, 2020 at 2:20 PM Alex Rodriguez <powertoutg-Re5JQ...@public.gmane.org> wrote:
>>
>> Hi,
>>
>> I intend to use C for this, unless there is an easier way to do it. For my application, UDP will work just fine as I'm not too concerned about packet loss. And yes, I understand that HEX is a representation of binary data. I simply wanted to know if this could be done from the BBB and if so, see if there is a similar solution out there for new users. Thanks
>
>a quick google search found...
>
>https://wiki.python.org/moin/TcpCommunication

Forgive me, but -- that's a rather dated page for Python (it's Python
2.x, for one thing, and any new work should be done with Python 3.x). I'd
suggest the OP peruse the following...

The basic example at
https://docs.python.org/3/library/socketserver.html
is more up-to-date...

Also, Python has added a lot of standard library modules for network
access... cf:

https://docs.python.org/3/library/socketserver.html

along with

https://docs.python.org/3/howto/sockets.html#socket-howto


For creating binary packets to send/receive

https://docs.python.org/3.8/library/struct.html


And a caveat: In Python 3.x, "strings" are Unicode data, not "bytes" --
they may need to be encoded/decoded using a specified encoding into a byte
structure.




--
Dennis L Bieber

Robert Oostenrijk

unread,
Mar 19, 2020, 1:20:54 PM3/19/20
to BeagleBoard
Hi,

If you would like to do it in C (and you are running any Unix variant on your BBB) the book "UNIX Network Programming volume 1" might be something for you.
I'm not very experienced on the subject, but just putting it out there.

Good luck,
Robert
Reply all
Reply to author
Forward
0 new messages