Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with ASCII String and Serial Ports

Status
Not open for further replies.

danielkelly

IS-IT--Management
Aug 13, 2006
28
AU
I am trying to communicate with a serial device using Net Framework 2 and the Serial Port Class. I have a protocol definition written in VB which I am having problems converting to C#. The main problem I seem to be having is in the ASCII conversion.

The VB code is Chr$(255) //Hex Value 255
I thought the C# equivalent would be Convert.ToChar(255) however when I use a com port viewer, it is showing a different character to the VB Code.

Can anyone help me in how to achieve the above using the serial port class.

The eventual goal is to create a string of characters to output using the port.Write Method of the SP Class.

Thanks in advance
 
ASCII is only valid in the range of [0..127], so there's your problem.

You're probably sending an array of Byte to the comm port, right? If so, just create a byte value of 255 and add it to the array.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks, Im still a bit confused. Could you possibly put a small snippet of code so I can try and get my head around it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top