Industrial Communications

cancel
Showing results for 
Search instead for 
Did you mean: 

how you can send 3,4 byte under UDP protocol

Solved!
Go to solution

Hello, everyone

I want to use the UDP protocol to send a message from computer #1 to computer #2 with this format

 

First byte: Message ID                                                          

Second byte: number of message bytes n

Third byte: the message

 

How I can send that message by that format , could anyone help me?.

 

 

I try to do that by this way, is that way is a right way?....

 

Blockm D

 

 

Front B

 

In the message to be send (string indicator box) dose 1 represent message ID (M Id), - sign represent # of bytes and  is the first byte of message is the index 0 of array , second byte is index 1 , third byte is index 2 ,......etc

 

 

 

 

Best regard

Zhrani

 

 

0 Kudos
Message 1 of 11
(8,370 Views)

Hello Al-Zahrani,

 

Are you having issues trying to do it this way (errors, incorrect message, etc.)? I am also attaching a link to our UDP Communication in LabVIEW. Hope this helps a little bit! 

 

Mychal F

 

Applications Engineer
National Instruments
0 Kudos
Message 2 of 11
(8,359 Views)

Hello Mychal,

 

thank you for your reply , yeah I have issue to send the message by that format.

actually I have two computers and one microcontroller (PIC) which connected together  via ethernet switch.

 

in attachment you can find my VI's ,I tested these VI's in my two computers (until now without PIC circuit) ,

it was O.K

but until now I don't know if my technic is a right way to send a message by that format

(Message ID, # of bytes send and 2 or 3 or 4 Bytes the payload)

 

computer1.jpg

 

and at computer 2

 

Computer2.jpg

 

 

any suggestion or answer is helpful for me...

 

 

 

Thanks

alzhrani

 

 

Download All
0 Kudos
Message 3 of 11
(8,343 Views)

Al-Zahrani,

 

Can you please clarify the issue you are having? Are you receiving errors, warnings, time-outs, etc.? Thanks!

 

Mychal F

Applications Engineer
National Instruments
0 Kudos
Message 4 of 11
(8,327 Views)

Mychal F


In the microcontroller board (which contain PIC microcontroller from microchip ) I can only use UDP protocol ,

the program in PIC microcontroller receive a message in bytes format, because of that I should send the message as that format.

 

in computer to computer there is no problems of communication (try to test my VI's in previous reply in two computers)


Thank you again
Alzhrani

0 Kudos
Message 5 of 11
(8,323 Views)

Alzhrani,

 

What microcontroller are you using? 

 

Mychal F

Applications Engineer
National Instruments
0 Kudos
Message 6 of 11
(8,314 Views)

Hello Mychal

 

Thankyou for reply

 

 

I used PIC16F877 with ENC624J600

 

to communicate with computer

 

 

 

Best regard

Alzhrani

0 Kudos
Message 7 of 11
(8,302 Views)

Hi Al-Zahrani, 

 

It is too bad you don't have the device, it would make the testing easier. However, I think we still are a little unclear on your question. It sounds like you are trying to form instructions for your micro controller, such as the ones found in the Instruction set manual for your device, in which caseI think that what you might be interested in is logical shifts.

 

To put it another way, are you trying to send all three bytes at the same time, as part of the same command?

 

If not, what exactly are you trying to do and where did you get the criteria for three bytes?

 

 

 

Jesse Dennis
Engineer
INTP
0 Kudos
Message 8 of 11
(8,287 Views)

Hello Jess_D

 

Thankyou for reply

 

 

To put it another way, are you trying to send all three bytes at the same time, as part of the same command?


yeah , I wat to send all three bytes in one command

 

 

let's forget the microcontroller , if I want to send that three command to the second computer How I can do that ????
 

 

Thank you

 

Alzhrani

0 Kudos
Message 9 of 11
(8,278 Views)
Solution
Accepted by topic author Al-Zahrani

Cool, that is what I thought your were trying to do. 

 

You need to use logical shifts form the command. You will shift the first byte over 8 bits, the second byte over 4 bits and the payload over none. Then you can add them all into a single number and send this number over a single udp command. This give you a total message length of 3x4 = 12 bits.  

 

To illustrate, lets pretend that we have the following scenario: 

 

Message ID: 255 (1111 in binary) 

Number of bytes: 0000 (0000 in binary)

Message: 255 (1111 in binary)  

 

The below program shifts arranges them into one 12 bit message using shifts: 

 

example.png

You can then send this number over udp. Is this what you were trying to do? 

 

Could you tell me more about where you got this requirement? Was it from the manuals for the micro controller or a different source? I still don't understand why you need to send these commands in this fashion, which will help me answer your question much more effectively.  

Jesse Dennis
Engineer
INTP
0 Kudos
Message 10 of 11
(8,268 Views)