Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving binary data via UDP #66

Open
bob-g4bby opened this issue Jun 6, 2021 · 0 comments
Open

Receiving binary data via UDP #66

bob-g4bby opened this issue Jun 6, 2021 · 0 comments

Comments

@bob-g4bby
Copy link

bob-g4bby commented Jun 6, 2021

Hi Attila,
How are you?
I'm revisiting Punyforth with the help of the glossary I wrote, if you remember. I'm successful in sending binary data from Punyforth to a PC - the data is read by a LabVIEW program just fine:-

\ UDP sender - array example

-UDP
marker: -UDP

1024 constant: arraysize

arraysize array: myarray		\ an array of 32 bit 'longs'

: !myarray					( -- ) \ initialise mybuffer with random data
	arraysize 0 do
		random i myarray !
	loop
;

"BOB-PC" 	constant: SERVER_IP
8005		constant: SERVER_PORT

: UDPsender
SERVER_PORT SERVER_IP UDP netcon-connect
begin
	!myarray										\ fill the array with random data
	dup 0 myarray arraysize 4 * netcon-send-buf	\ start address + byte count
	50 ms
	readchar-nowait 27 =							\ send it again until ESC pressed
until
netcon-dispose
;

UDPsender

What I can't seem to do is receive the same binary data from the PC with this code:-

 \ NETCON load beforehand

-UDP
marker: -UDP

"192.168.1.3" 	constant: HOST
1024 constant: datasize
8000 constant: PORT
datasize array: data

: UDPreceiver

PORT HOST netcon-udp-server
begin
	dup datasize 4 * 0 data netcon-read
	print: 'received bytes: ' . cr
	10 ms
	readchar-nowait 27 =
until
netcon-dispose
;

UDPreceiver

netcon-read never seems to return? Is that the right word to use with binary data or does it only accept ascii?

I can successfully read ascii data from the PC, using this:-

\ NETCON load beforehand

-UDP
marker: -UDP

"192.168.1.3" 	constant: HOST
128 constant: datasize
8000 constant: PORT
datasize buffer: data

: UDPreceiver

PORT HOST netcon-udp-server
begin
	dup datasize data netcon-readln
	print: 'received bytes: ' . cr
	data type cr
	10 ms
	readchar-nowait 27 =
until
netcon-dispose
;

UDPreceiver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant