Convert String to Char[]

Jul 24, 2011 at 11:09 PM

Hi. I'm trying to output a string out through the serial port. I made my own driver, here is the code:

 

public void write(string a)
{
    char[] ch = a.ToCharArray();
    while (is_transmit_empty() == 0) ;
    for (int i = 0; i < a.Length; i++)
    {
        Core.outb((ushort)PORT, (byte)ch[i]);
   }
}

and i used :

write("RETRO OS v0.4.2");

I used Virtual PC and outputs the serial to a text file, i opened it up, and it showed this:
Hex:
42 65 67 69 6e 0a f3 00 54 00 bf 00 67 00 a5 0087 00 f3 00 f3
Chars:
Beginó T ¿ g ¥ ‡ ó ó

and i also have it print Begin using chars, but strings don't work.

Developer
Jul 24, 2011 at 11:10 PM

Interesting.  

Coordinator
Jul 24, 2011 at 11:17 PM
> Hi. I'm trying to output a string out through the serial port. I made my
> own driver, here is the code:

DebugStub also uses the serial port. Are you sure you arent using the
same serial port that it does?
Jul 25, 2011 at 12:42 AM

I don't know, i use COM1. it works with putchar() with the same things, but not if its below line 25.

Coordinator
Jul 25, 2011 at 12:45 AM
> I don't know, i use COM1. it works with putchar() with the same things,
> but not if its below line 25.

Its very important to know. COM1 is normally used by the DebugStub.
Jul 25, 2011 at 12:56 AM
Well, I also implemented support for COM 2,3,and 4, will they work?

Sent from my iPod

On Jul 24, 2011, at 6:45 PM, "kudzu" <notifications@codeplex.com> wrote:

From: kudzu

> I don't know, i use COM1. it works with putchar() with the same things,
> but not if its below line 25.

Its very important to know. COM1 is normally used by the DebugStub.
Coordinator
Jul 25, 2011 at 1:00 AM
> Well, I also implemented support for COM 2,3,and 4, will they work?

It depends if you have more than one issue. But the first step certainly
is to use a different COM port.
Jul 25, 2011 at 1:50 AM
Edited Jul 25, 2011 at 1:52 AM

Same thing with COM2: Beginó T ¿ g ¥ ‡ ó ó  Virtual PC only supports 1 and 2, i think it is more than the serial thing, beacuse, like i said, it works with putchar() with the same method,
but not if its below line 25.

And  i just noticed, the T in RETRO is there, in the right position.

Coordinator
Jul 25, 2011 at 3:07 AM
> Same thing with COM2: Beginó T ¿ g ¥ ‡ ó ó Virtual PC only supports 1
> and 2, i think it is more than the serial thing, beacuse, like i said,
> it works with putchar() with the same method,
> but not if its below line 25.

Try getbytes instead of the casting.
Jul 25, 2011 at 3:14 AM
Edited Jul 25, 2011 at 3:20 AM

What is getbytes?

EDIT: Nevermind, i found it.

Jul 25, 2011 at 3:23 AM

When i try it i get an error about plugs, and system.threading.monitor.enter(System.Object)

Coordinator
Jul 25, 2011 at 3:23 AM
> What is getbytes?

Look at ASCIIEncoding
Coordinator
Jul 25, 2011 at 3:29 AM
> When i try it i get an error about plugs, and
> system.threading.monitor.enter(System.Object)

Yep, now I remember. See Breakpoints OS, it does some mungling from
strings to bytes for FAT.
Jul 25, 2011 at 3:44 AM

Thanks! It worked, using StringBuilder(). This ill also help me fix doing PutChar() over line 25.