Přihlašovací jméno: Heslo:
Registrace nového uživatele
Moderátor: toedder 
 Computers

Have computer questions, hints, or tips?

BBW's Tips on how to speed up page load the brainking site
Computers (BIG BAD WOLF, 2007-03-12 20:16:01)


Počet zpráv na stránce:

Co je nového o adware?
Seznam diskusních klubů
Není vám dovoleno psát zprávy do tohoto klubu. Minimální úroveň členství vyžadovaná pro psaní v tomto klubu je Brain střelec.
Mód: Každý může psát
Hledat v příspěvcích:  

6. července 2006, 09:04:34
Hrqls 
Subjekt: C# serial port sends only 3F above 7F ?
Změněno uživatelem Hrqls (6. července 2006, 09:06:16)
i hope anyone can help me

i am trying to send a string of characters (ascii codes 0 to 255) over the serial port using the SerialPort control in C# (vs 2005 pro)

the characters arrive nice and sweet ... up to 7F, the characters with ascii code 80 and higher (hex) are sent as 3F all the time (as soon as the 8th bit is used 3F will be sent)

does know anyone what could cause this problem, and maybe how it can be solved or done otherwise ?

i am using the code below :

string strMsg = "";
for (int intI = 0; intI <256; intI++)
{
strMsg += Convert.ToChar(intI);
}
comKAR.Write(strMsg);
</pre>

6. července 2006, 11:37:54
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
i am making the application for an ipaq (windows mobile 5.0)
i am using c# (i am more experienced in vb6, but i need c# for the ipaq)

i just found out that the 3F character is sent when a parity error occurs
so maybe thats the problem ?

i made a lot of application which used the serial port (all with vb6 though, and 1 with c#) and i never got a parity error (maybe i was just lucky ;))

can anyone explain to me when a parity error might occur and what might cause it ?

any ideas are welcome as it will offer me something more to test and check and continue from

thanks in advance ;)

6. července 2006, 18:49:29
toedder 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Hrqls: I'm not really sure, as I never worked directly with Serial Port. But parity errors normally occur if
a) there occured an error during sending and one bit was changed or
b) maybe the parity bit was corrupted by your program?
Maybe your connection is set to a bytelength of 7 bit and you overwrite the parity bit? Again: I don't really have a clue, but this was what came to my mind ;) Good luck in finding the solution :)

6. července 2006, 21:48:55
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Mr. Shumway: yes thats what i thought as well .. but it only occurs with characters with an ascii value of 128 (80) or higher .. and with all of them .. so it cant be an accidental loss of data

the databits are set to 8 in my program
i dont know how to check the databits of the serial port on the ipaq though .. it doesnt have a real serial port .. it uses a special cable to the normal connection on the ipaq (which normally ends in an usb connector :))

maybe the cable cant handle 8 databits ? but that would be weird as its serial data and not parallel so the data itself shouldnt matter

that leaves the driver (which is a default driver as i didnt have to install anything) or the serialport control in c# (or the functions i use to control the serialport) ?

6. července 2006, 23:48:28
hexkid 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Hrqls: Can you try converting those 8 bits you send/receive to 7 bits?
I googled a bit and found a Base64 Encoder/Decoder, but maybe the .NET framework already has something similar ???

7. července 2006, 07:44:27
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
hexkid: thanks

that would be nice .. but i think the receiving side has to receive decode the 7 bits back to 8 bits again and i have no control over the receiver side

will have a look though, it might be a solution :)

7. července 2006, 07:57:44
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Změněno uživatelem Hrqls (7. července 2006, 07:58:10)
Hrqls: i found something!!


By default, SerialPort uses ASCIIEncoding to
encode the characters. ASCIIEncoding encodes all
characters greater then 127 as (char)63 or '?'.
To support additional characters in that range,
set Encoding to UTF8Encoding, UTF32Encoding, or
UnicodeEncoding.


before i open the port i will try

comKAR.Encoding = Encoding.UTF8;

7. července 2006, 08:06:43
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Hrqls: i am on the right track .. it doesnt send 3F anymore .. but now what should be 80 sends C2 80
81 is now C2 81, ...., FF is now C3 BF

i will see what i can do now ... at least the parity error (which wasnt one imo ;)) is gone

7. července 2006, 08:58:07
Hrqls 
Subjekt: Re: C# serial port sends only 3F above 7F ?
Změněno uživatelem Hrqls (7. července 2006, 08:58:59)
Hrqls: the encoding classes wont help me .. i need to send 1 byte which has to hold characters from ascii value 0 to ascii value 255 .. the only encoding class which sends only 1 byte is the ascii encoding which sends the 63 (3F) when i try to send a character with ascii value of 128 or higher

but! (yeah! ;)) i can also send the string or character array as a byte array ... which then bypasses the encoding class (or simply doesnt need it)

this works! ;)

so for the loop to send all characters with ascii value from 0 to 255 i now use :

byte[] bytArray;
bytArray = new byte[256];
for (int intI = 0; intI <256; intI++)
{
bytArray[intI] = (byte)intI;
}
comKAR.Write(bytArray, 0, 256);



which works flawlessly

thanks for the help and ideas .. it set me on the right track and made it work :)

Datum a čas
Přátelé on-line
Oblíbené kluby
Společenstva
Tip dne
Copyright © 2002 - 2024 Filip Rachůnek, všechna práva vyhrazena.
Zpět na vrchol