ASCII for numbers greater than 255

Thread Starter

kj4g09

Joined Dec 4, 2011
29
I am wondering how many binary bits used to represent number greater than 255, such as 256, is it represented by 100000000 or something like 0..0100000000(more than 9 bits, say 16 bits?);

I am using C# to send a number in the range of 0-4095 (12 bits) by serial port to 12-bit DAC. If the number (>255) send out is in the form of 16 bits then the extra 4 bits will shift out the first 4 bits in the register of DAC.
 

MrChips

Joined Oct 2, 2009
31,138
There are many different types of serial ports, UART, SPI, I2C, USB, ethernet, etc.
You really need to specify what kind of port you are using.

For character oriented interfaces, you can transmit two bytes in binary to give 16 bits.
 

John P

Joined Oct 14, 2008
2,027
ASCII is the coding used to represent characters in the computer. You could convert your numbers into ASCII digits and send the data that way, but from what's been said in this thread, it seems as if the title is seriously inaccurate.

If you send one byte for numbers < 256 and switch to two bytes for >= 256, is there any possibility that the receiving end will get confused about what's being sent? For instance, could the two bytes for a large number be interpreted as two successive numbers in the 0-255 range?

You do understand that a serial port sends 8-bit characters only, right? You can't send 8 bits and then 4. Is it possible that the DAC actually uses an SPI port, basically a shift register?
 

MrChips

Joined Oct 2, 2009
31,138
its RS-232.
I guess it will send 2 bytes through the serial port if the data is greater the 255.
Not quite. It depends on who or what is sending the data.
You still have to spell out clearly what you are doing.

I can only guess that you are opening a PC COM port using C#.
Then you are writing to the port. What statement are you using to write to the port?
Are you sending binary or ASCII?
ASCII can only send one byte at a time. You have to specifically deconstruct your data in order to send out two ASCII characters.

There are 10 types of people in the world, those who understand binary and those who don't.
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
yes I knew that it can only send 8 bits at a time. I was hoping if I send 256 through serial port, the actual signal send out could be 2 separated bytes like (00000001+00000000). But now I figured out it doesn't work in that way.

Sorry about the title if it confused you.
 

MrChips

Joined Oct 2, 2009
31,138
You cannot send one byte and later change and decide to send two bytes.
You have to make up your mind and always send two bytes.

Then the problem arises.
What if the receiver misses one byte and now every pair of byte is out of sync?
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
I created a Windows Form Application in C#. I want to enter integer numbers in textBox and then click the buttom to send out that number. Also the code will open the USB COMM port with an USB to Serial adapter connect to it. The transmit Data Pin of that adapter is connected to the SDI(serial data in) of Serial to Parallel Shift Register of the DAC.
the code for writing the port is:
SerialPort1.Write(textBox1.Text);

I tried to trigger the signal of the transmit data pin of the adapter using Oscilloscope.
When I sent 255 through the port, the output waveform looks like "A"+"B"+"B"(I am guessing A represents 2 and B represent 5, but its not in binary form);

What I want to do is to send a binary number out the port in the range of (0-4095);
 

tshuck

Joined Oct 18, 2012
3,534
I created a Windows Form Application in C#. I want to enter integer numbers in textBox and then click the buttom to send out that number. Also the code will open the USB COMM port with an USB to Serial adapter connect to it. The transmit Data Pin of that adapter is connected to the SDI(serial data in) of Serial to Parallel Shift Register of the DAC.
the code for writing the port is:
SerialPort1.Write(textBox1.Text);

I tried to trigger the signal of the transmit data pin of the adapter using Oscilloscope.
When I sent 255 through the port, the output waveform looks like "A"+"B"+"B"(I am guessing A represents 2 and B represent 5, but its not in binary form);

What I want to do is to send a binary number out the port in the range of (0-4095);
Then you'll need to convert the textBox text into an integer number... It hink the code would be Int32.Parse(textBoxt.Text);, though I could be mistaken.. it's something like that...

If you tell the port to send text, it will send the ASCII numbers corresponding to those characters...
 
Last edited:

John P

Joined Oct 14, 2008
2,027
... The transmit Data Pin of that adapter is connected to the SDI(serial data in) of Serial to Parallel Shift Register of the DAC...
Uh oh. I'm seeing confirmation that the DAC has SPI, not a serial port, which of course is typical. If it were a serial port, the input pin would most likely be RX. Is there also a clock input?

But prove me wrong. What is the part number and where can we look it up?
 

tshuck

Joined Oct 18, 2012
3,534
Uh oh. I'm seeing confirmation that the DAC has SPI, not a serial port, which of course is typical. If it were a serial port, the input pin would most likely be RX. Is there also a clock input?

But prove me wrong. What is the part number and where can we look it up?
SPI is serial... What you mean is a UART... I've never seen a DAC with a UART connection. You'll need to convert the UART data to SPI. a microcontroller can do this easily....
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
Sorry, I just realize I made a silly mistake.
The value out of the port is in the ASCII form, and the pin is active low which means 5(0101) is measured as (1010) plus a start&stop signals.

All I need to do is to figure out a way to write characters and punctuates to the port, so that the output binary signal can be seem as a integer number in the range of 0-4095.
 

John P

Joined Oct 14, 2008
2,027
Well, all right, but SPI is "clocked serial" as opposed to a "serial port". I suppose mentioning a UART removes any ambiguity. But that's what I meant--a DAC with a UART sounds unlikely, and the terminology sounds like SPI.
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
Then you'll need to convert the textBox text into an integer number... It hink the code would be Int32.Parse(textBoxt.Text);, though I could be mistaken.. it's something like that...

If you tell teh port to send text, it will send hte numbers corresponding to those characters...
Thanks for that code.
I will have a go.
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
Uh oh. I'm seeing confirmation that the DAC has SPI, not a serial port, which of course is typical. If it were a serial port, the input pin would most likely be RX. Is there also a clock input?

But prove me wrong. What is the part number and where can we look it up?
Yes, it has a clock input. Its DAC7614
 

tshuck

Joined Oct 18, 2012
3,534
Well, all right, but SPI is "clocked serial" as opposed to a "serial port". I suppose mentioning a UART removes any ambiguity. But that's what I meant--a DAC with a UART sounds unlikely, and the terminology sounds like SPI.
Yes, true, sorry.. I apparently misread the first time around, though it was a bit confusing making that distinction...;)
 

Thread Starter

kj4g09

Joined Dec 4, 2011
29
So this is a (almost) SPI interface.... you need to communicate with a clocked serial interface...
Yeah, I am going to use a microcontroller to setup and clock the DAC.
But I have to get the right SDI out of the PC COMM Port first.
 
Top