| tnjgraham (26) | |
|
Hey, I am working on this project where when a user selects a particular com port via a config dialog, the software needs to retrieve the OS COM Port settings for the particaul port that was selected. For example, If I select COM Port 1 on the config dialog in project, the software needs to retrieve the OS current COM Port 1 settings(Baud Rate, Data bits,Parity, Stop bit, and Flow Control). Once OS settings are retrieved, I neeed to update my project dialog with the OS COM Port Settings. Once dialog settings are updated to OS COM Port settings, users will have an opportuntiy to change current port settings by clicking a button. Once user has changed settings for a port, the OS COM Port current settings needs to be updated to what user input. Any advice will be greatly helpful. I have never done any thing like this and am totally confused. Thanks In Advance | |
|
|
|
| guestgulkan (2915) | |
|
Use CreateFile function to get a handle to the com port. Then use GetCommState function to get com port current settings. Use SetCommState function to set com port parameters. See MSDN reference for the GetCommState function here: http://msdn.microsoft.com/en-gb/library/windows/desktop/aa363260%28v=vs.85%29.aspx See MSDN reference for the SetCommState function here: http://msdn.microsoft.com/en-gb/library/windows/desktop/aa363436%28v=vs.85%29.aspx | |
|
Last edited on
|
|
| tnjgraham (26) | |||
|
Guestgulkan, Thanks, I have been researching GetCommState and SetCommState. While researching I found the below code, I understand the code for the most part. However, I don't think it is doing what it says. It is suppose to be getting port settings and than changing settings to settings in program. When I view COM Port settings, my settings doesn't reflect what the code should have set it to. Can you please review code and give me input on what is going wrong.
I am programming on Windows XP. Also, I commented out SecureZeroMemory(&dcb, sizeof(DCB)); because I got an error stating that it wasn't declared. Any help will be greatly apprecitated!!!!!!!!!!!! | |||
|
|
|||
| EssGeEich (1007) | |
Tri to Initialize the dcb struct to 0:DCB dcb = {0};
| |
|
|
|
| tnjgraham (26) | |
|
EssGeEich, I tried that and it didn't work. It is stating that my current baud rate is 57600 but it is 4800 and it is stating that it changed it to 57600. My settings are not reflecting what the program is displaying. Do you have to have certain privillages on your computer for this to work like admin maybe. I am thinking I may not have rights to do this on my work computer. Do I need to include the SecureZeroMemory() method, I am not sure what it is doing though? Any help will be greatly apprecitated!!!!!!!!!!!! | |
|
|
|
| EssGeEich (1007) | |
| I don't think SecureZeroMemory will do anything. Try running your IDE/Program as Administrator anyways, it's no bad. | |
|
|
|
| tnjgraham (26) | |
|
Ok, found out that I am Admin on my computer. So thats not the reason why it isn't working. Is there another way to retrieve/set current system COM Port settings? Thanks In Advance | |
|
|
|
| guestgulkan (2915) | |
| I haven't had a PC with serial ports for 5 years now - so I will have to try it out on ather PC but won't be until monday unfortunately. | |
|
|
|
| tnjgraham (26) | |
|
Guestgulkan, By any chance were you able to retrieve/set current system COM Port settings? Thanks In Advance | |
|
|
|
| guestgulkan (2915) | |
|
Yes, I have done some tests. Ran the program - the Set and Get CommState says the port particulars have changed but the Control Panel -> system -> Ports display does not update to reflect this ( I think that might be just the way it is) EDIT: I'm sure the values in Control Panel -> System ->Ports are just default (on windows startup) settings. The value you get from GetCommState actually reflect the current port settings (from the ports itself). You can see what the actual port settings are by typing mode at a command prompt | |
|
Last edited on
|
|
| tnjgraham (26) | |
|
Guestgulkan, After doing some test with the Set and Get CommState method and getting port settings with the mode command, I totally agree with you. Thanks soooo much for giving me advice on this topic. | |
|
|
|