Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Going over some code and found I wasn't setting the Handshake, Parity or StopBits
in the file so I went in and found I was setting all the easy ones like Baudrate, Databits. I was the ones which require Name.Value ie:
C#
myComPort.Databit = 8;

fine,
C#
myComPort.Handshake = Handshake.None

I wasn't. Those values are enums aren't they?
So I tried
C#
myComPort.Handshake =Handshake.Enum.Parse(typeof(Handshake)(ITEMhandshake));

and no, it didn't work, there is a way to do this isn't there?

Glenn
The ini in Question is:
BOARDRATE = 2400
PARITY = None
DATABITS = 8
STOPBITS = One
HANDSHAKE = None

and I know BOARDRATE should be BAUDRATE.
Posted
Updated 24-Apr-12 2:40am
v2
Comments
Sergey Alexandrovich Kryukov 24-Apr-12 8:33am    
How is this related to "ini file"? And who would be working with INI files in .NET?
--SA
glennPattonWork3 24-Apr-12 8:36am    
Me, as I quote "use an ASCII text ini they are editable with Notepad, keep everything simple!" from the Boss, "but, XML ini" "do it as a flat text file"
"oh OK"
Richard MacCutchan 24-Apr-12 9:04am    
and no, it didn't work is not very descriptive. Use your debugger to find out what gets returned by the Parse() call.
glennPattonWork3 24-Apr-12 9:10am    
The problem seems to be Enum is throwing things
Richard MacCutchan 24-Apr-12 9:23am    
What are "things"? You really need to be much more specific about your results if you expect help here; we can't guess what is happening on your system, or see the screen to read any messages.

1 solution

You can do
C#
myComport.Handshake = (Handshake)Enum.Parse(typeof(Handshake), "None");


Replace "None" with the string that you read out of your ini file.
 
Share this answer
 
v2
Comments
glennPattonWork3 24-Apr-12 10:56am    
Thanks, that saved me a lot of head scratching, I hate typing on Laptops!

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