Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi

i write a program that sends data to software "real term" ...but i have some problem with this

1) when i send "A" it displays "0A" how can i control input buffer and display exactly "A" ?


2) for number 80 and after that it displays "3F" that is equal with character:"?"
because serial port's dataBit is just 5 to 8((2^8)-1=127) and 80 is "128"decimal i want send data in 2 parts ...
how can i do this?



i thank you for time friend
Posted

Without your code it is difficult to be precise, but...
I assume you are sending bytes to the port (otherwise you probably wouldn't get the first error), so try setting the byte value to the character you want to send:
C#
byte b = (byte) 'A';
Though either of these two will do the same thing:
C#
byte b = 0x41;

C#
byte b = 61;
Since 'A' is ASCII character 61 decimal, or 41 hex (See an ASCII Table[^] for details)

Secondly, if you are sending bytes, then provided you have set the port to 8 bits per character, you can send any value in the range 0 to 255 inclusive just by setting the byte value. If no need to send a larger value, then you need to look at the equipment you are sending to, as it will probably specify exactly how it is prepared to receive it.
 
Share this answer
 
In addition to Solution 1:
If you use SerialPort.Write(string) overload, make sure you set up appropriate SerialPort.Encoding before writing to port. This should probably be ASCII encoding, but you should check with device specs to see what encoding it expects.

If you setup SerialPort.Databits = 5; you don't need to worry about splitting bytes 5-bit values, you just give a byte[] to SerialPort class and it will split and send them the way you configure it.
This also applies to Parity and Stopbits.
 
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