Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to send numbers over the serial port as bytes, not strings.
What I mean is if I want to send a 120, that should be 1 byte, not a 2
followed by a 2 and a 0.How it possible?
Posted
Updated 27-Aug-14 1:43am
v2
Comments
[no name] 27-Aug-14 7:46am    
Maybe you should listen to what you have already been told and go read the documentation for the device you are trying to communicate with and find out the proper way to send data to it.
Member 10994712 27-Aug-14 7:50am    
I tried a code. But I didnt get the solution byte b = byte.Parse(textBox1.Text); serialPort1.Write(new byte[] {b }, 0, 1);

1 solution

If you use SerialPort class from System.IO.Ports: http://msdn.microsoft.com/de-de/library/ms143551%28v=vs.100%29.aspx[^]

C#
public void Write(
    byte[] buffer,
    int offset,
    int count
)



CSS
buffer
    Type: System.Byte[]
    The byte array that contains the data to write to the port.

offset
    Type: System.Int32
    The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.

count
    Type: System.Int32
    The number of bytes to write.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900