Using serial ports in vs on xp
-
Can anyone tell me how to output data and recieve from a com port on xp/nt in vs2005 managed C++ ? I have done Parallel i/o before but only on win 9x and never serial. Thx...
Hi, if you are using .Net 2 then System::IO::Ports::SerialPort should be the way to go. However, i found this new serial port class quite unreliable (in terms of switching RTS) and used therefore recently the one from windows.h. for example: HANDLE _ComPort = CreateFile( ptrComName,....); // create a port and use WriteFile(_ComPort, ptrTxFrame, pTxFrameLength,&ulBytesWritten, 0); ReadFile(_ComPort, ptrRxFrame, 256, &ulBytesWritten, NULL); to read and write, but with this approach you'll always have to pinpoint your buffers. pin_ptr ptrTxFrame = &pTxFrame[0]; best regards Tobias
-
Hi, if you are using .Net 2 then System::IO::Ports::SerialPort should be the way to go. However, i found this new serial port class quite unreliable (in terms of switching RTS) and used therefore recently the one from windows.h. for example: HANDLE _ComPort = CreateFile( ptrComName,....); // create a port and use WriteFile(_ComPort, ptrTxFrame, pTxFrameLength,&ulBytesWritten, 0); ReadFile(_ComPort, ptrRxFrame, 256, &ulBytesWritten, NULL); to read and write, but with this approach you'll always have to pinpoint your buffers. pin_ptr ptrTxFrame = &pTxFrame[0]; best regards Tobias
Thx Bee.. I think that was just what I needed. I wonder tho, about the reliability. I don't need rts or dts.. just to have them both stay high. I am wondering if switching is a problem. Can you elaborate a bit on that part? If I just set it high and forget it, will it stay? I am hoping the problem you are talking about is the api not seeing the change state. So if I set it then it will stay, not wanting to write a watchdog for it. Thx for the reply..
-
Thx Bee.. I think that was just what I needed. I wonder tho, about the reliability. I don't need rts or dts.. just to have them both stay high. I am wondering if switching is a problem. Can you elaborate a bit on that part? If I just set it high and forget it, will it stay? I am hoping the problem you are talking about is the api not seeing the change state. So if I set it then it will stay, not wanting to write a watchdog for it. Thx for the reply..
Right, maybe it did sound a little negative. The reason for my statement was that my application really depends on a very accurate switching time between Request to Send enabled/disabled. For some reason this switching time differs for each switch, 5-15 ms while using the .Net class. Thus I need a constant switching time, which must be less than 10 ms, i'll sometimes run into trouble. With the windows.h method I have never discovered this problem. It displays all the time a continuous 5 ms switch time on my oscilloscope. Probably there is a way to close out this problem but by the time I faced this problem, it was quite critical to go ahead with my project. Therefore I decided to go for the unmanaged option for the time being. However apart from this odd behaviour this new class is quite comfortable and very straight forward. I'll maybe give it another try after finishing my project. best regards Tobias
-
Right, maybe it did sound a little negative. The reason for my statement was that my application really depends on a very accurate switching time between Request to Send enabled/disabled. For some reason this switching time differs for each switch, 5-15 ms while using the .Net class. Thus I need a constant switching time, which must be less than 10 ms, i'll sometimes run into trouble. With the windows.h method I have never discovered this problem. It displays all the time a continuous 5 ms switch time on my oscilloscope. Probably there is a way to close out this problem but by the time I faced this problem, it was quite critical to go ahead with my project. Therefore I decided to go for the unmanaged option for the time being. However apart from this odd behaviour this new class is quite comfortable and very straight forward. I'll maybe give it another try after finishing my project. best regards Tobias
Hi I too have been looking for a way to access the comm ports using managed code. I'm pretty new to Visual C++ so I need a little more information regarding how to setup and access a com port connected to a USB-Serial adapter. My comm port shows up as COM7 in windows. I need baby steps for opening, configuring and sending and receiving data. I only need to send about 5 or 6 chars but can possibly receive 10 or up to 512 chars from the serial device I'm interfacing with. All the code I've come across on the web doesn't seem to work with Visual C++ 2005 expess Edition.:confused: